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

Picture of 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

Picture of 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

Picture of 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

NickC245 (author)2017-10-04

I made the whole thing like mentioned above, but the receiver keeps telling me: 'No radio available'. I checked all the wires and I seriously don't know what to do anymore. Someone who can help me? Any ideas?

Felipe8 (author)NickC2452017-11-14

Hey, Nick.

Check out this page, there's an issue related to using Arduino Mega and the default pin 53.

http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo

ChiaraL2 (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?

RicardoG167 (author)ChiaraL22017-10-08

I'm facing the same problem too

NickC245 (author)ChiaraL22017-10-04

Did you found a solution? Unfortunately I'm facing the same problem

Akshay Jha (author)ChiaraL22016-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

ChelseaR31 (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!

NickC245 (author)ChelseaR312017-10-04

Did you solved the problem? I'm facing the same problem

botronics (author)2017-09-04

I made it using the module shown and the high power one too. Both from Banggood. Both worked first time. Recommend using the power board too.

vermasachin (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);}

}

botronics (author)vermasachin2017-09-04

Thank you for posting that code. I had the same error. Now it works perfectly.

MattA4 (author)2017-08-22

i want to be able to turn 3 switches, make them neg to pos and then switch it to pos to neg (double pole double throw), so 6 channel i think.

how would i do this?

StefanosG5 (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.

Lachlanv (author)StefanosG52017-04-03

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

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

abdualmlk_sb (author)2016-11-29

thanks man that was very helpful to me

Akshay Jha (author)abdualmlk_sb2016-11-30

welcome bro :-)

IshtiaqA6 (author)Akshay Jha2017-05-23

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

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

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...

tclayton (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!

robopro1234 (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

GabrielV89 (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

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.

AlbertG48 (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.

zihadmahmud (author)2017-03-17

How far is the range?

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

easy :)

Carlos JA made it! (author)2016-12-15

Heelp!!

vermasachin (author)Carlos JA2016-12-22

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

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

BharathRam (author)vermasachin2016-12-26

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

AbhishekS339 (author)2017-02-04

please guide for sending pwm signal through POT

stevenleeyongwah (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.

can u send the pin details for mega

shaun.husain (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.

vermasachin (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

shaun.husain (author)vermasachin2016-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".

AkashdeepC (author)2016-11-20

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

Akshay Jha (author)AkashdeepC2016-11-20

Thanks bro :-)

Akshay Jha (author)AkashdeepC2016-11-20

Thanks :-)

allana alain (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.

kartik-agrawal_97 (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

youcanmakeit (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.

Raitis (author)2016-08-03

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

jimkan (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

Akshay Jha (author)jimkan2015-10-18

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

JT3WH0 (author)Akshay Jha2016-04-27

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

JT3WH0 (author)JT3WH02016-04-29

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

BryanT46 (author)JT3WH02016-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

DarthSwagger (author)BryanT462016-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

About This Instructable

334,320views

314favorites

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: