Introduction: Wireless Remote Using 2.4 Ghz NRF24L01 : Simple Tutorial Using of NRF24L01 & Arduino

Hello Everyone this is my second instructable . After lots of surfing on GOOGLE when I wont able to find a easy and a simple tutorial for NRF24L01 transceiver then I decided to publish an instructable on this. This is a simple short and easy tutorial for NRF24L01 Radio 2.4GHz Transmitter Receiver. In this tutorial I am going to control led using a pair of NRF24L01 transceiver.

Step 1: Small Introduction About NRF 24L01 Transceiver

The nRF24L01 is a highly integrated, ultra low power (ULP) 2Mbps RF transceiver IC for the 2.4GHz ISM (Industrial, Scientific and Medical) band. With peak RX/TX currents lower than 14mA, a sub μA power down mode, advanced power management, and a 1.9 to 3.6V supply range, the nRF24L01 provides a true ULP solution enabling months to years of battery lifetime when running on coin cells or AA/AAA batteries .

Step 2: Material Require

  1. 2 PCS NRF24L01+2.4 GHz Wireless Transceiver module
  2. 2 Arduino any (I have used one arduino R3 & nano)
  3. Male to. femal jumpers
  4. LED
  5. Any Switch
  6. 10K resistor

Step 3: Connections

  • Connect the following pins to your Arduino:as shown in figure
  • Pin 9 - CE
  • Pin 10 - CS(N)
  • Pin 11 - MOSI
  • Pin 12 - MISO
  • Pin 13 - SCK
  • 3.3v - VCC
  • GND - GND
  • On the Receiver Pin 3 - LED
  • On the Transmitter Pin 7 - Button
  • same connection for receiver and transmitter and you can use any arduino board

Step 4: Coding Arduino

For coding arduino first we need some library files so follow the steps given below :

1. Download the ZIP file (library file zip folder from attachments ).

3. Unpack the ZIP file.

4. Go to arduino library folder

5. And paste both the folders named " nFR24L01" and "RF24" into it.

Now, program the Arduino receiver and transmitter

Code for Receiver

<p>#include <SPI.h><br>#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int LED1 = 3;</p><p>void setup(void){
 Serial.begin(9600);
 radio.begin();
 radio.openReadingPipe(1,pipe);
 radio.startListening();
 pinMode(LED1, OUTPUT);}</p><p>void loop(void){
 if (radio.available()){
   bool done = false;    
   while (!done){
     done = radio.read(msg, 1);      
     Serial.println(msg[0]);
     if (msg[0] == 111){delay(10);digitalWrite(LED1, HIGH);}
     else {digitalWrite(LED1, LOW);}
     delay(10);}}
 else{Serial.println("No radio available");}}</p>

Code for Transmitter

<p>#include  <SPI.h><br>#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7;</p><p>void setup(void){
 Serial.begin(9600);
 radio.begin();
 radio.openWritingPipe(pipe);}</p><p>void loop(void){
 if (digitalRead(SW1) == HIGH){
 msg[0] = 111;
 radio.write(msg, 1);}}</p>

Step 5: Testing

This is a last step after completing the circuit and coding part we can easily test it by switching "ON" and "OFF". .

When switch is "ON" on transmitter side connected to pin 7 of arduino then led glows on receivers side connected to pin 3 of arduino .Video Shows the output of this project.

THANKS HOPE THIS WILL HELP YOU

Comments

author
ChelseaR31 made it!(author)2017-06-07

Hi there, I followed the instructions using an Arduino Pro Mini and an Arduino Uno, but the LED will not light and I only get "No Radio Available" in the serial monitor. Any ideas as to why it is not working? Thanks!

author
StefanosG5 made it!(author)2017-02-14

an Open Question:

Has anyone measured the actual delay in time with an oscilloscope or logic analyser for the transmission of a byte from RX1 of the first arduino to the TX2 of the second arduino using this module? More precisely what is the "latency" between the first bit of a test byte measured from the moment that "enters" in RX1 and "exits" from TX2. I am making this question because most transceiver modules going around have latencies of the order of 30ms. Which is ok for many applications, but too long for other, which make cable comm. the only choise.

Please answer only if you have actually measured the delay, not on estimation.

author
Lachlanv made it!(author)2017-04-03

Round-trip delay 1832 microseconds, for two normal modules at 20cm apart.

author
stevenleeyongwah made it!(author)2017-05-26

It got some delay, the LED just light up after i pressed it for awhile

author
abdualmlk_sb made it!(author)2016-11-29

thanks man that was very helpful to me

author
Akshay+Jha made it!(author)2016-11-30

welcome bro :-)

author
IshtiaqA6 made it!(author)2017-05-23

sir can we do duplex communication with this if yes ,,,,,,,,what should be changes in code

author
anand.krishnan.37 made it!(author)2017-01-27

does the same pinout works for mega if not please let me know and whether i have to change the code according to it

author
raman_raja made it!(author)2017-05-11

The pin connections depend on the Arduino board as well as the RF library used. A table can be found here:

https://arduino-info.wikispaces.com/Nrf24L01-2.4GH...

nRF24 pin connections.JPG
author
tclayton made it!(author)2017-05-23

This is the exact base code and tutorial i was looking for, i can modify my wired projects to this tutorial , i had never tried any wireless communication. Thankyou!

author
robopro1234 made it!(author)2017-05-08

if i want to send / receive signal to /from pc to this nrf24l01 and arduuino, how can i do that? please help

author
GabrielV89 made it!(author)2017-04-25

Hello:

the MOSI signal coming from Arduino to NRF is 5V, doesn't damage the NRF which is 3V3, or is it 5V tolerant?

thanks

author
Vladivarius made it!(author)2017-04-04

Hey guys, I followed the tutorial and it works :)
However, I changed the code to send zero's when the led should be off, otherwise it will flicker or not turn on at all.

Also I made another program to send messages(strings) to transmitter and print them on LCD!

Sorry for ugly code, it was made on the go.

Image uploaded from iOS.mp4RFtutorial.rarLCD_print_RF.rar
author
AlbertG48 made it!(author)2017-03-29

I cannot make these modules work, at all. I bought 10 of them, two I burned accidentally by plugging them in the 5v line. The other do send and receive data, but not the one I send from one to another.

I'm using two Arduino UNO, and I have tried very much every example. Even powering them we two very stable, 700mA 3.3v power supplies, as every other blog I have read say that powering them with the Arduino's 3.3v line will not work. Obviously, since you are showing that it works, I no longer believe them. :)

Anyhow, I'm pretty much giving up on those modules. I'm very familiar with SPI, I2C, USART, etc. and I have project using all different types of sensors, IO explander, SRAM, EEPROM, without much difficulty. This nRF24L01+ is proving impossible...unless I got a very bad batch of those modules.

author
zihadmahmud made it!(author)2017-03-17

How far is the range?

author
JimmyL42 made it!(author)2017-03-10

easy :)

20170310_105812.jpg
author
Carlos+JA made it!(author)2016-12-15

Heelp!!

error.jpg
author
vermasachin made it!(author)2016-12-22

were you able to resolve this???, I am getting the same error too !!!

author
Shyamsingla11 made it!(author)2017-02-16

Hey! i also got his error and this error was removed when i upgrade my arduino ide now i have 1.8.2 version of arduino ide

author
BharathRam made it!(author)2016-12-26

replace it by radio.read(msg, 1);
it means you are trying to get value from void function

author
AbhishekS339 made it!(author)2017-02-04

please guide for sending pwm signal through POT

author
stevenleeyongwah made it!(author)2017-01-08

Thank you so much! Finally got it working with arduino uno as transmitter and arduino mega as receiver. Just make sure u connect the NRF24L01 to arduino mega with correct pin.

author
anand.krishnan.37 made it!(author)2017-01-27

can u send the pin details for mega

author
vermasachin made it!(author)2016-12-27

finally, able to run the code successfully now.

made few changes to the rcvr code to fix the radio.read error and also in my case the led was not turning off after I release the button, so I added line to turn it off

#include <SPI.h>

#include "nRF24L01.h"

#include "RF24.h"

int msg[1];

RF24 radio(9,10);

const uint64_t pipe = 0xE8E8F0F0E1LL;

int LED1 = 3;

void setup(void){

Serial.begin(9600);

radio.begin();

radio.openReadingPipe(1,pipe);

radio.startListening();

pinMode(LED1, OUTPUT);}

void loop(void){

if (radio.available()){

bool done = false;

while (radio.available()){

radio.read(msg, 1);

Serial.println(msg[0]);

if (msg[0] == 111){delay(10);digitalWrite(LED1, HIGH);}

else {digitalWrite(LED1, LOW);}

delay(10);

msg[0] == 9;}}

else; {Serial.println("No radio available");

digitalWrite(LED1, LOW);}

}

author
shaun.husain made it!(author)2016-11-27

Nice job I also am using these modules for a controller with a model here http://www.thingiverse.com/thing:1864536 I made a preliminary PCB for hooking up between the nrf module and arduino nano but am thinking I will modify it to just have the atmega 328p chip right on my PCB instead of stacking the modules.

author
vermasachin made it!(author)2016-11-22

Hello Akshay - thanks for sharing this. unfortunately I am not able to make it work on my circuit. Dont know if it something I am doing wrong or if my circuit board are bad. Can you suggest any trouble shooting tips to see what is wrong with my circuit?

Also curious to know what does the syntax </p> <p> means and what is its significance....I am very new to Arduino so pardon me aksing very basic question

author
shaun.husain made it!(author)2016-11-27

For troubleshooting use a voltmeter and check that wires are connected where you expect, also check the voltage on the 3.3V is going to the wireless module without a problem. Also can be useful to use Serial.begin(9600); in your setup and Seral.println("signs of life"); Serial.println(someImportantVar); in your loop function to see that things are working on the arduino side. The <p> is HTML syntax and is accidental (probably copy paste problem or issue with instructable formatting, would check the zip for code).

Beyond the voltmeter I just bought and assembled a really cheap oscilloscope ($20-30) and even with this cheapo oscilloscope I can see some digital signals on various pins communicating to the rf module.

Also read up here for more details https://arduino-info.wikispaces.com/Nrf24L01-2.4GH...

In particular be sure to include a capacitor across the 3.3V and ground (with negative side towards ground), 100uF with any Voltage above 3.3V will be fine. The rf module will otherwise draw too much power occasionally causing it to "brown out".

author
AkashdeepC made it!(author)2016-11-20

awesome man nicely donne.....good jog..

author
Akshay+Jha made it!(author)2016-11-20

Thanks bro :-)

author
Akshay+Jha made it!(author)2016-11-20

Thanks :-)

author
allana+alain made it!(author)2016-09-25

Hi. Can someone please help me how to combine the receiver codes with a lcd library? its for our project. please. thanks.

author
kartik-agrawal_97 made it!(author)2016-09-16

i couldn,t make it yrr led glows when the transmitter swith is on but it has no relation with the switch acutally led glow when the transmitter is on althow swith is off and led is off when transmitter is off please help me in this

author
youcanmakeit made it!(author)2016-09-04

Hello when I am trying this I only get "255" in the serial monitor of the receiver before and after truing on the transmitter.

author
ChiaraL2 made it!(author)2016-08-21

Even if I follow each step exactly, I get "No Radio Available"... I'm using an Arduino Uno as transmiter e an Arduino Mega as Receiver in order to switch on and off a led by a switch button. I've controlled again and again connections and it seems to be everything right. Which could be the problem?

author
Akshay+Jha made it!(author)2016-08-21

Can you use any other board like arduino mini instead of using arduino mega this might be a problem and please double check the connections

author
Raitis made it!(author)2016-08-03

Thank you, this helped me understand the syntax of the code for nRF!

author
jimkan made it!(author)2015-09-14

Jha,

Got an error on this line

done = radio.read(msg, 1);

couldn't figure out this compiler error "void value not ignored as it ought to be"

Thx

author
Akshay+Jha made it!(author)2015-10-18

@ jimkhan Sorry for late reply I think you should try with new version of arduino ide .

author
JT3WH0 made it!(author)2016-04-27

I get the same error, installed latest arduino, still the same error

author
JT3WH0 made it!(author)2016-04-29

Fixed, I deleted the rf24 library I had an installed the one linked from arduino, then it compiled

author
BryanT46 made it!(author)2016-05-02

Just to let you know, the newer library function "radio.read" is now a void, and not a boolean function. View the function here: https://github.com/TMRh20/RF24/blob/master/RF24.h#L201

author
DarthSwagger made it!(author)2016-08-03

I know this is a bit late to the original question, but I just stumbled across this and in case people are still wondering (like I was). Here's a bit to save you the headache.

As BryanT46 mentioned, the radio.read is a void not a boolean. This means you need to change the "done = radio.read(msg, 1);" to "radio.read(msg,1);" and completely get rid of the while loop (keep everything inside it though). The "bool done = false" can be deleted as well.

Replace:

delay(10);

digitalWrite(LED1, HIGH);

with:

digitalWrite(LED1, HIGH);

delay(10);

digitalWrite(LED1, LOW);

I had to change it to that way because after receiving the "111" and releasing the button, the program quickly reverts to "no radio available". So i have it just turn it on and off and then it's constantly checking for the new input. So if you hold it down it'll stay lit. The turn off could also easily be in the radio availability else section.

Finally, change the "if (radio.available())" to "if (radio.available() == true)". It was giving me funky feedback when the if wasn't defined correctly.

-DarthSwagger

author
mbehera1 made it!(author)2016-05-27

getting error on receiver part.......

**void value not ignored as it ought to be**

Capture.PNG
author
procesor made it!(author)2016-06-01

Did you fix that ? If you do, tell me how because i have the same problem.

author
DarthSwagger made it!(author)2016-08-03

I know this is a bit late to the original question, but I just stumbled across this and in case people are still wondering (like I was). Here's a bit to save you the headache.

As BryanT46 mentioned, the radio.read is a void not a boolean. This means you need to change the "done = radio.read(msg, 1);" to "radio.read(msg,1);" and completely get rid of the while loop (keep everything inside it though). The "bool done = false" can be deleted as well.

Replace:

delay(10);

digitalWrite(LED1, HIGH);

with:

digitalWrite(LED1, HIGH);

delay(10);

digitalWrite(LED1, LOW);

I had to change it to that way because after receiving the "111" and releasing the button, the program quickly reverts to "no radio available". So i have it just turn it on and off and then it's constantly checking for the new input. So if you hold it down it'll stay lit. The turn off could also easily be in the radio availability else section.

Finally, change the "if (radio.available())" to "if (radio.available() == true)". It was giving me funky feedback when the if wasn't defined correctly.

-DarthSwagger

author
joe1111 made it!(author)2016-07-27

I am trying to use one transmitter to cycle through communications with receiver arduinos. I am trying to open pipe1 to receiver1, transmit data, receive a value from the receiver, and close that pipe. Open pipe2, transmit, receive, close pipe two. repeat through all receivers. I'm not sure how I set the transmitter to change writing pipes or how to use ACK to automatically check for the returned value rather than switching between transmitting and receiving. Appreciate any help.

author
JohnL451 made it!(author)2016-07-23

Cannot verify either tx or rx sketch: get error message stray "#" in program.

author
Ali+Burak%C3%96 made it!(author)2016-07-22

made it.

thanks

author
AchieverSanjay made it!(author)2016-06-06

Dear Akshay,

Kindly provide a code to control 4 outputs (non-toggle) using nRF24L01 module.

Thanks in Advance.

author
bhadresh+parmar made it!(author)2016-05-25

Thanks mr.jha.I made it and is working.tried adding more switches and led.does not work.pls guide to get the result.
Regards

About This Instructable

306,478views

301favorites

Bio: Hello I am Tech Creator Akshay I love electronics and get in touch for more projects
More by Akshay Jha:Add Voice to Your Arduino Projects Without Using Any Module(BLINK WITH VOICE)How to Interface Oled and Arduino (Part -1)DIY Helping hand for soldering and elec.(SIMPLE & CHEAP)
Add instructable to: