Components and supplies
Jumper wires (generic)
Arduino UNO
Resistor 1k ohm
Tactile Switch, Top Actuated
RF24L01 with Antenna
Rotary potentiometer (generic)
Analog joystick (Generic)
Apps and platforms
Arduino IDE
Project description
Code
Controller Receive
arduino
1 2// Controller RECEIVE 3 4#include <nRF24L01.h> 5#include <RF24.h> 6#include <RF24_config.h> // include these libraries 7#include <SPI.h> 8 9RF24 radio(9, 10); // CE, CSN pins 10const uint64_t pipe = 0xE8E8F0F0E1LL; // create 64 bit pipe, 11 12int data[10] = { "001", "002", "003", "004", "005" }; // create 5 piece data array, in 3 digit formats 13 14 15void setup() { 16 17 Serial.begin(9600); // begin serial, 9600 baud 18 19 radio.begin(); // start radio 20 radio.setPALevel(RF24_PA_MAX); // set power level to max 21 radio.openReadingPipe(1, pipe); // open READING pipe 22 radio.setDataRate(RF24_250KBPS); // Set data rate to 250 KBPS 23 radio.enableDynamicPayloads(); // enable dynamic payloads helps 24 radio.StartListening(); // START listening, . 25 26 27 } 28 29 30 31void loop() { 32 33 radio.read(&data, sizeof(data)); // read all the data, the size of the data 34 35 Serial.print("J1x: "); 36 Serial.print( data[0]); // Print the values, these will read 0 if the radio is not connected. 37 Serial.print("\ "); 38 39 Serial.print ("J1y: "); 40 Serial.println(data[1]); 41 Serial.print("\ "); 42 43 Serial.print ("Jpush1: "); 44 Serial.print(data[2]); 45 Serial.print("\ "); 46 47 Serial.print ("B1: "); 48 Serial.print(data[3]); 49 Serial.print("\ "); 50 51 Serial.print ("Pot1: "); 52 Serial.print(data[4]); 53 Serial.print("\ "); 54 55 56 delay(10); 57 58 } 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
Controller Receive
arduino
1 2// Controller RECEIVE 3 4#include <nRF24L01.h> 5#include <RF24.h> 6#include 7 <RF24_config.h> // include these libraries 8#include <SPI.h> 9 10RF24 radio(9, 11 10); // CE, CSN pins 12const uint64_t pipe = 0xE8E8F0F0E1LL; 13 // create 64 bit pipe, 14 15int data[10] = { "001", "002", "003", "004", 16 "005" }; // create 5 piece data array, in 3 digit formats 17 18 19void setup() 20 { 21 22 Serial.begin(9600); // begin serial, 9600 baud 23 24 radio.begin(); 25 // start radio 26 radio.setPALevel(RF24_PA_MAX); // set 27 power level to max 28 radio.openReadingPipe(1, pipe); // open READING pipe 29 30 radio.setDataRate(RF24_250KBPS); // Set data rate to 250 KBPS 31 radio.enableDynamicPayloads(); 32 // enable dynamic payloads helps 33 radio.StartListening(); // 34 START listening, . 35 36 37 } 38 39 40 41void loop() { 42 43 44 radio.read(&data, sizeof(data)); // read all the data, the size of the data 45 46 47 Serial.print("J1x: "); 48 Serial.print( data[0]); // Print the 49 values, these will read 0 if the radio is not connected. 50 Serial.print("\ "); 51 52 53 Serial.print ("J1y: "); 54 Serial.println(data[1]); 55 Serial.print("\ "); 56 57 58 Serial.print ("Jpush1: "); 59 Serial.print(data[2]); 60 Serial.print("\ "); 61 62 63 Serial.print ("B1: "); 64 Serial.print(data[3]); 65 Serial.print("\ "); 66 67 68 Serial.print ("Pot1: "); 69 Serial.print(data[4]); 70 Serial.print("\ "); 71 72 73 74 delay(10); 75 76 } 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
Controller - Send
arduino
1 2// Controller send 3 4#include <nRF24L01.h> 5#include <RF24.h> 6#include <RF24_config.h> // include these libraries 7#include <SPI.h> 8 9RF24 radio(9, 10); // CE, CSN pins 10const uint64_t pipe = 0xE8E8F0F0E1LL; // create 64 bit pipe, 11 12int data[10] = { "001", "002", "003", "004", "005" }; // create 5 piece data array, in 3 digit formats 13 14const int J1xPin = A2; 15const int J1yPin = A1; // set joystick pins, these are all analog pins. 16const int Jpush1 = A3; 17 18const int B1Pin = 3; // set button pin, digital 19 20const int Pot1Pin = A0; // set potentiometer pin 21 22 23 24void setup() { 25 26 Serial.begin(9600); // begin serial, 9600 baud 27 28 radio.begin(); // start radio 29 radio.setPALevel(RF24_PA_MAX); // set power level to max 30 radio.openWritingPipe(pipe); // open the WRITING pipe, this is the sender. 31 radio.setDataRate(RF24_250KBPS); // Set data rate to 250 KBPS 32 radio.enableDynamicPayloads(); // enable dynamic payloads helps 33 radio.stopListening(); // STOP listening, so you can send data. 34 35 pinMode(Jpush1, INPUT); 36 pinMode(B1Pin, INPUT_PULLUP); // set the buttons and potentiometer as inputs. 37 pinMode(Pot1Pin, INPUT); 38 39 40 } 41 42 43 44void loop() { 45 46 data[0] = map(analogRead(J1xPin), 0, 1023, 100, 200); 47 data[1] = map(analogRead(J1yPin), 0, 1023, 200, 100); // define data, startiung with 0. I have also mapped them as data 48 data[2] = map(analogRead(Jpush1), 1023, 0, 0, 1); 49 50 data[3] = digitalRead(B1Pin); // read the button pin as data 51 52 data[4] = analogRead(Pot1Pin); // read the potentiometer as data 53 54 55 radio.write(&data, sizeof(data)); // write all the data, the size of the data 56 57 Serial.print("J1x: "); 58 Serial.print( data[0]); // Print the values, these will read 0 if the radio is not connected. 59 Serial.print("\ "); 60 61 Serial.print ("J1y: "); 62 Serial.println(data[1]); 63 Serial.print("\ "); 64 65 Serial.print ("Jpush1: "); 66 Serial.print(data[2]); 67 Serial.print("\ "); 68 69 Serial.print ("B1: "); 70 Serial.print(data[3]); 71 Serial.print("\ "); 72 73 Serial.print ("Pot1: "); 74 Serial.print(data[4]); 75 Serial.print("\ "); 76 77 78 delay(10); // 10 second delay 79 80 } 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
Downloadable files
Receiver
Receiver
Controller Breadboard
Controller Breadboard
RF24 Pinout
RF24 Pinout
RF24 Pinout
RF24 Pinout
Receiver
Receiver
Controller Breadboard
Controller Breadboard
Comments
Only logged in users can leave comments