We will going to demonstrate here how to use Nordic nRF24L01 2.4 Wireless Radio using Arduino with Joystick Controller. This 2.4Ghz Radio module are base on Nordic Semiconductor nRF24L01+ Chip,
The Nordic nRF24L01+ integrates a complete 2.4GHz Radio Frequency Transceiver, Radio Frequency Synthesizer, and Baseband Logic including the Enhance ShockBurst hardware protocol accelerating a high speed SPI interface for the application controller and low -power short-range transceiver and it has a built in on-board antenna other model it has SMA integrated antenna with a range up to 1100 Meter.
Features:
- 2 ore more Arduino’s be able to communicate wirelessly over a distance.
- Controlling a nearby buildings
- Controlling Autonomous vehicles of all kinds
- Excellent for a remote sensors for temperature, pressure, distance, switching, alarm and more.
- Controlling and monitoring a robot a range up to 2000 feet distance
We will going to transmits a communication between to Arduinos over NRF24L01 using Joystick
Note: Problem accure when operation because of electrical noise on 3.3v supply, specially when using Arduino Mega and Nano we need to add bypass capacitor across ground and vcc on the module. please see the schematics below.
Pin Out Connection to the Arduino by Library
Signal | RF Module | Arduino pin for / RF24 | Arduino pin for Mirf | MEGA2560 pin / RF24 | Arduino UNO Pin for RH_NRF24 RadioHead | MEGA2560 Pin for RH_NRF24 RadioHead |
GND | 1 | GND * | GND | GND * | GND * | GND * |
VCC | 2 | 3.3V * | 3.3V | 3.3V * | 3.3V * | 3.3V * |
CE | 3 | Pin 9 | Pin 8 | Pin 9 | Pin 8 | Pin 8 |
CSN | 4 | Pin 10 | Pin 7 | Pin 53 | Pin 10 | Pin 53 |
SCK | 5 | Pin 13 | Pin 13 | Pin 52 | Pin 13 | Pin 52 |
MOSI | 6 | Pin 11 | Pin 11 | Pin 51 | Pin 11 | Pin 51 |
MISO | 7 | Pin 12 | Pin 12 | Pin 50 | Pin 12 | Pin 50 |
IRQ | 8 | Pin 2 * | per library | N/C | N/C |
Get the Code Libraries from ManiacBug NRF24L01 Libraries import to your Arduino Libraries
nRF24L01 TX – Transmitter Sketch.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
/* Example: nRF24L01 */ 1 - GND 2 - VCC 3.3V /* WARNING SHOULD BE 3.3v Not 5V */ 3 - CE - Arduino pin 9 4 - CSN - Arduino pin 10 5 - SCK - Arduino pin 13 6 - MOSI - Arduino pin 11 7 - MISO - Arduino pin 12 8 - UNUSED /* You can used an Analog Joystick or 2 10K potentiometers */ GND - Arduino GND VCC - Arduino +5V X Pot - Arduino A0 Y Pot - Arduino A1 /*----- Import all required Libraries -----*/ #include <SPI.h> #include <nRF24L01.h> #include <RF24.h> /*----- Declare all constant pin to be used ----*/ #define CE_PIN 9 #define CSN_PIN 10 #define JOYSTICK_X A0 #define JOYSTICK_Y A1 const uint64_t pipe = 0xE8E8F0F0E1LL; // This is the transmit pipe to communicate the two module /*-----Object Declaration ----*/ RF24 radio(CE_PIN, CSN_PIN); // Activate the Radio /*-----Declaration of Variables -----*/ int joystick[2]; // Two element array holding the Joystick readings void setup() { Serial.begin(9600); /* Opening the Serial Communication */ radio.begin(); radio.openWritingPipe(pipe); }//--(end setup )--- void loop() /* Runs Continuously */ { joystick[0] = analogRead(JOYSTICK_X); /* Reading Analog X joystick[1] = analogRead(JOYSTICK_Y); /* Reading Analog Y radio.write( joystick, sizeof(joystick) ); }//--(end main loop )--- |
nRF24L01 RX – Receiver Sketch.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
/* Testing nRF24L01 Receive Joystick values to NRF24l01 Module 1 - GND 2 - VCC 3.3V /* WARNING SHOULD BE 3.3v Not 5V */ 3 - CE - Arduino pin 9 4 - CSN - Arduino pin 10 5 - SCK - Arduino pin 13 6 - MOSI - Arduino pin 11 7 - MISO - Arduino pin 12 8 - UNUSED /*----- Import all required Libraries -----*/ #include <SPI.h> #include <nRF24L01.h> #include <RF24.h> /*----- Declare all constant pin to be used ----*/ #define CE_PIN 9 #define CSN_PIN 10 const uint64_t pipe = 0xE8E8F0F0E1LL; // This is the transmit pipe to communicate the two module /*-----Object Declaration ----*/ RF24 radio(CE_PIN, CSN_PIN); // Activate the Radio /*-----Declaration of Variables -----*/ int joystick[2]; // Two element array holding the Joystick readings void setup() { Serial.begin(9600); /* Opening the Serial Communication */ delay(1000); Serial.println("Nrf24L01 Receiver Starting"); radio.begin(); radio.openReadingPipe(1,pipe); radio.startListening();; }//--(end setup )--- void loop() { if ( radio.available() ) { // Reading the data payload until the RX received everything bool done = false; while (!done) { // Fetching the data payload done = radio.read( joystick, sizeof(joystick) ); Serial.print("X = "); Serial.print(joystick[0]); Serial.print(" Y = "); Serial.println(joystick[1]); } } else { Serial.println("No radio available"); } } |
Note: you need to check the voltage 3.3v power supply, it will distract the operation due to power regulation issues, the average current may be less 15ma.
Arduino: 1.6.9 (Windows 7), Board: “Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)”
J:\nRF24\rx\rx.ino: In function ‘void loop()’:
rx:43: error: void value not ignored as it ought to be
done = radio.read( joystick, sizeof(joystick) );
^
Multiple libraries were found for “nRF24L01.h”
Used: C:\Users\dholu\Documents\Arduino\libraries\RF24
Not used: C:\Program Files\Arduino\libraries\RF24-master
Not used: C:\Program Files\Arduino\libraries\RF24-master
Not used: C:\Program Files\Arduino\libraries\RF24-master
Not used: C:\Program Files\Arduino\libraries\RF24-master
exit status 1
void value not ignored as it ought to be
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
Please help me how can i fixed this problem?