This post aims to be a complete guide for nRF24L01 – 2.4GHz RF Transceiver module. I’ll explain what it does, show its specs and share an Arduino project example that you can take and apply to your own projects.
I have more complete guides for other popular sensors, check them below:
- Complete Guide for Ultrasonic Sensor HC-SR04
- Complete Guide for DHT11/DHT22 Humidity and Temperature Sensor
- Complete Guide for RF 433MHz Transmitter/Receiver Module
- Arduino with PIR Motion Sensor
Description
These RF modules are very popular among the Arduino tinkerers. The nRF24L01 is used on a wide variety of applications that require wireless control. They are transceivers which this means that each module can transmit and receive data.
These modules are very cheap and you can use them with any microcontroller (MCU).
Specifications nRF24L01 – 2.4GHz RF Transceiver
- Low cost single-chip 2.4GHz GFSK RF transceiver IC
- Range with Antenna: 250Kb rate (Open area) >1000 meter
- Power: Ultra low power consumption
- Input Voltage: 3.3V
- Pins: 5V tolerant
- Price: $2
Where to buy?
You can purchase these modules for just a few dollars. Click here to compare the nRF24L01 module on several stores and find the best price. They come in two versions with external antenna (more range) or built-in antenna (less range).
You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!
Arduino with nRF24L01
You need the following components to make this example:
Library download
Here’s the library you need for this project:
- Download the RadioHead library
- Unzip the RadioHead library
- Install the RadioHead library in your Arduino IDE
- Restart your Arduino IDE
The RadioHead library is great and it works with almost all RF modules in the market. You can read more about this project here.
Pinout
Client Circuit
Important: Input voltage is of 1.9V~3.6V, do not exceed this voltage, otherwise it will fry your module.
Follow the circuit above for your client. Then upload the code below which can be found in your Arduino IDE (after installing the RadioHead library).
Go to File > Examples > RadioHead > nrf24 > nrf24_client.
// nrf24_client
#include <SPI.h>
#include <RH_NRF24.h>
// Singleton instance of the radio driver
RH_NRF24 nrf24;
// RH_NRF24 nrf24(8, 7); // use this to be electrically compatible with Mirf
// RH_NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin
// RH_NRF24 nrf24(8, 7); // For RFM73 on Anarduino Mini
void setup()
{
Serial.begin(9600);
while (!Serial)
; // wait for serial port to connect. Needed for Leonardo only
if (!nrf24.init())
Serial.println("init failed");
// Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
if (!nrf24.setChannel(1))
Serial.println("setChannel failed");
if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
Serial.println("setRF failed");
}
void loop()
{
Serial.println("Sending to nrf24_server");
// Send a message to nrf24_server
uint8_t data[] = "Hello World!";
nrf24.send(data, sizeof(data));
nrf24.waitPacketSent();
// Now wait for a reply
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (nrf24.waitAvailableTimeout(500))
{
// Should be a reply message for us now
if (nrf24.recv(buf, &len))
{
Serial.print("got reply: ");
Serial.println((char*)buf);
}
else
{
Serial.println("recv failed");
}
}
else
{
Serial.println("No reply, is nrf24_server running?");
}
delay(400);
}
Server Circuit
Important: Input voltage is of 1.9V~3.6V, do not exceed this voltage, otherwise it will fry your module.
Follow the circuit above for your server. Then upload the code below which can be found in your Arduino IDE (after installing the RadioHead library).
Go to File > Examples > RadioHead > nrf24 > nrf24_server.
// nrf24_server
#include <SPI.h>
#include <RH_NRF24.h>
// Singleton instance of the radio driver
RH_NRF24 nrf24;
// RH_NRF24 nrf24(8, 7); // use this to be electrically compatible with Mirf
// RH_NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin
// RH_NRF24 nrf24(8, 7); // For RFM73 on Anarduino Mini
void setup()
{
Serial.begin(9600);
while (!Serial)
; // wait for serial port to connect. Needed for Leonardo only
if (!nrf24.init())
Serial.println("init failed");
// Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
if (!nrf24.setChannel(1))
Serial.println("setChannel failed");
if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
Serial.println("setRF failed");
}
void loop()
{
if (nrf24.available())
{
// Should be a message for us now
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (nrf24.recv(buf, &len))
{
// NRF24::printBuffer("request: ", buf, len);
Serial.print("got request: ");
Serial.println((char*)buf);
// Send a reply
uint8_t data[] = "And hello back to you";
nrf24.send(data, sizeof(data));
nrf24.waitPacketSent();
Serial.println("Sent a reply");
}
else
{
Serial.println("recv failed");
}
}
}
Demonstration
In this project the client is sending a message “Hello World!” to the server via RF and the server is sending back the following message “And hello back to you”. Those messages are being displayed in the serial monitor. Here’s what you should see in your serial terminal windows (see Figure below).
Note: On the left window, I’m establishing a serial communication with PuTTY.org. On the right window, I’m using the Arduino IDE Serial Monitor.
Conclusion
You need to have some realistic expectations when using this module. They work very well when the receiver and transmitter are quite close to each other. If you separate them too far you’ll loose the communication.
The communication range will vary. It depends on how much noise in your environment, if there’s any obstacles and if you’re using an external antenna.
I hope you found this guide useful.
Share this post with a friend that also likes electronics!
You can contact me by leaving a comment. If you like this post probably you might like my next ones, so please support me by subscribing my blog and my Facebook Page.
Thanks for reading,
-Rui Santos
Hello,
I’ve been following your posts from quite a few days. The nRF tutorial is really helpful. I have a query. Can we use this library for wireless sensor nodes. How to communicate with different clients with different device addresses?
Suppose we have 2 clients & 1 server. Then how to ask for data from a specific client at a time? Please help.
Hi Roy,
Thank you for trying my projects! Yes you can have multiple nodes and you can set different device addresses to allow multiple clients.
The library comes with an example that will help you use that concept.
Having the library installed in your Arduino IDE. Go to File > Examples > Radiohead > nrf24
And use these examples “nrf24_reliable_datagram_client” and “nrf24_reliable_datagram_server”.
If you look at the code you can set different addresses to each device
Hi Rui . please I want you to help me .I am designing an automatic menu ordering system In a restaurant using Arduino Uno ,2.4TFT touchscreen and NRF24l01+ can you help me with the code?
Hi.
We don’t write custom code or consulting.
Regards
Sara
Great job, as always! I hadn’t tried it yet, but I definitely will. I hope I’ll succeed.
Thank you Rui
Thank you Emil for your continuous support! Have a great day,
-Rui
when i insert code of nrf24_server into ardiuno uno, at serial monitor it shows init failed .
nrf24_client working fine, sending data but nothing is happening from server site , it shows only INIT FAILED.
I created server on both uno and mega 2560 but getting same response i.e init failed,
Please help me in these case, its urgent.
Thanks
Have you followed my exact schematics?
Are you using the proper nrf example for the Arduino IDE?
Check carefully the COM ports while uploading the Arduino code
Hello ,Rui I to am getting nothing on my uno server ,uno client seems fine and says “getting no response from server”. I have double checked everything ,any ideas. Such a good project I would like to get it running.Hope you reply, Steve
I had this same problem. I deleted Radiohead version 1.117 and installed 1.121. Now everything works fine.
see this page: http://www.airspayce.com/mikem/arduino/RadioHead/classRH__NRF24.html
you must swap 10>53, 13>52, 11>51, 12>50 on the arduino mega, and instantiate (line 7) using the following instead:
RH_NRF24 nrf24(8, 53); //mega
having said that, I can get the mega to act as client but not as server.
I had this same problem. I deleted Radiohead version 1.117 and installed 1.121. Now everything works fine.
Hello, this module is popular, common, is that transmits audio, which is the nRF24L01z has little information on his internet, you want to do some tutorial?
Hi,
I don’t know any tutorial on that subject… Sorry
Thanks for asking!
Hii rui,
I am using your above programs it works great…i also succeeded in sending continuous integer values between arduinos…Now i am thinking about sending interger values from 6 Transmitters to the base receiver….is it possible with this nrf24 library?if yes then how can it is possible plz …give me some ideas ..
Thank you….
Hi Sabale,
You can have multiple nodes and you can set different device addresses to allow multiple clients connected to one server.
The Radiohead library comes with an example that will help you do that.
Having the library installed in your Arduino IDE. Go to File > Examples > Radiohead > nrf24
And use these examples “nrf24_reliable_datagram_client” and “nrf24_reliable_datagram_server”.
If you look at the code you can set different addresses to each device
hello rui recently i am doing a project in which i am trying to use nrf24l01 as a transceiver for sending a data of sensors with aurdino uno to my serial monitor of laptop…. still i am not able to do it plzz can you help me..
Did you try the code example from this blog post?
we have tried this code….but we are not able to transfer sensors data(tiny gps)
from one aurdino to another aurdino serial port connected to computer through nrf. so please can you give us its complete code…..
I tried it with radio head library but server part not working .
What’s not working?
I tried your code with radio head library. Client sending to nrf24. But no reply. Is nrf24 server running? When i check in nrf24 server serial monitor is no problem. Got request : hello world! Sent a reply.can you help me…? Why client not reveive message from nrf24 server?
I have a problem… i do all things as it is but at transmitting side, I do not get any thing. just always show
Sending to nrf24_server
No reply, is nrf24_server running?
plzz help me
I tried your code with radio head library. Client sending to nrf24. But no reply. Is nrf24 server running? When i check in nrf24 server serial monitor is no problem. Got request : hello world! Sent a reply.can you help me…? Why client not reveive message from nrf24 server?
I encourage you to check if your nrf24 modules are well connected or defective..
I don’t have any other way of debugging your project with those specifications
If u r using radio head library check the following
*check the pin cs and cn connected to pin 7,8
*in the code add (7,8) in the bracket
*the Miso and mosi ,slave selct pins are different for different arduino boards check it .
*assure the vcc doesn’t exceed 3.3v
*link the neutral if any
I am a researcher in the field of Arduino and IOT
Thanks for reading!
Rui
Hi Sir Rui! You noted above that you established a serial communication with PuTTY.org on the client part of your project, I wanted to know if I can have that same communication with another arduino IDE? Hoping for your kind respond. Thank you!
I’m using PuTTY, because the Arduino IDE only supports a serial communication at a time.
With PuTTY you can have many serial ports open and see the serial data
hey i want to send integers from one module to another ,how to send them also i want to compare them on receiver i tried comparing string but it was not working..
What have you tried?
You can definitely send any type of data
HI! You’re post had been really helpful except on one part I can’t seem to understand. Where am I suppose to use the breadboard to connect the Arduino boards and rf together?
The breadboard is not exactly required, but it’s very helpful to put the nRF modules in a breadboard, so the connections are more secure and don’t disconnect by mistake.
Regards,
Rui
Thank you for making this tutorial. May I ask you how can i transmit data of sensor from server to client using the library you showed? Or is there anyway else?
There are many libraries created that should also work with the nRF24L01. You don’t need to use the one showed in this project, but during my tests it’s the most reliable and with more features.
Regards,
Rui
hi, good work
i have a doubt. i tried your nRF24L01 sketck.
i got “init failed” in both the transfer and datagram codes.
can you please help me as to what should i change.
Hi Kumuran.
I think that error means that the nRF24L01 is not properly connected, so it can’t initialize.
Regards,
Sara 🙂
I could reproduce your example quit good. I earlyer experienced errors when I looked for attiny85 examples and other lbraries. Sometimes good, sometimes bad. The radiohead library seems more stable. At least I know now that the components are working.
Is there any code that I can use with Pic microcontroller
Hi.
Unfortuantely, we don’t have any code with Pic microcontroller.
Regards,
Sara
Hey there!
I tried this project. I am using Arduino UNO as my client and Arduino MEGA as my server. Looks like the server is not working fine! The server prints “init failed” and nothing else.
Hi.
That probably means that the Arduino MEGA is not establishing a proper connection with the module.
The module communicates with the Arduino using the SPI pins.
SPI pins are different in Arduino UNO and Arduino MEGA.
ARDUINO UNO SPI PINS:
– MOSI: 11
– MISO: 12
– SCK: 13
– SS: 10
On the ARDUINO MEGA:
– MOSI:51
– MISO: 50
– SCK: 52
– SS: 53
So, please make sure that you wire the module to the correct SPI pins.
I hope this helps.
Regards,
Sara
where is the SS pin?
What is the maxim. distance betwen the 2 modules?
Hi Simon.
The maximum distance varies. But it can be 1000 meters in open field with ideal conditions (so, I wouldn’t expect getting such a long range).
Regards,
Sara
Hello,
Please do you have any guide for the nrf24 module with raspberry pi?
cheers.
Hi Pascal.
No.
We only have this tutorial with that module.
Regards,
Sara
Excelente post! Parabéns.
Hi,
Thank you very much, excuse mmoi I wanted to know how to do for a servomotor controlled by a potentiometer
Hi.
We don’t have that specific tutorial.
Regards,
Sara
This worked great for me after trying other examples on the net which were unsuccessful. Well done for a nice simple example which will form the basis for more complex projects.
Hi
I read your article and I did the same and it was all good.
but the problem I am deleing with is my transmitter cannot send three digit number is there reason for that?
any help will be apricated 🙂
Dear, I would like to start with measurements in my house…. especially temperature measurements. For this I would like to use the NRF24L10…. Can I find something in one of your books about this? or can you recommend me something reliable of reading for this? thanks Johan
Hi.
Unfortunately, we only have this tutorial about that module.
Regards,
Sara
I don’t know if this has been mentioned yet, but I had difficulty communicating with my nrf24 modules on some micros, and only some times. Adding a filter cap did not help, and the problem persisted whether connecting directly to the module at 3.3v or through the adaprer board powered by 5v. I was finally able to get reliable communication when using an external breadboard power supply (cheap, about $1.25 each) and powering the module and arduino from that, rather than trying to power the nrf24 from the Arduino board. When uploading/testing I only powered the module from the external supply and connected the ground lines together, but this has 100% solved my problems.
I am getting an error- init failed on server side. The client works fine and i receive the error No reply, is nrf24_server running?
Sending to nrf24_server
I am using both arduino unos.
How do i fix this?
Hi i would like to know if you got a fix for this init failed on the server side. I have being busy for weeks on this problem.
Hi Rui.
I know this is an old topic, But the project still stays current. I would to know if anyone has solved the issue if the of the nrf24_server that displays init failed, despite all the fiscal hardware is concerned. I had communication for a few times and then it all stoped. Hardware and power, caps on + and – , plenty nrf24l01’s and uploaded to different Uno’s
done it all, and nrf24l01 power adaptors. I was thinking that maybe there is a problem with the library.
please my receiver end keeps sending “init failed” to the serial monitor, what might be the cause of this ?
Hi.
Double-check the wiring.
Regards,
Sara
Some of Google Bard’s notes on setting nRFL2401 power level:
Include Necessary Library:
C++
#include <RF24.h>
Create an RF24 Object:
C++
RF24 radio(7, 8); // CE, CSN pins
Set Power Level:
C++
radio.setPALevel(RF24_PA_LEVEL); // Replace RF24_PA_LEVEL with desired level
Available power levels:
o RF24_PA_MIN: -18 dBm (lowest power)
o RF24_PA_LOW: -12 dBm
o RF24_PA_HIGH: -6 dBm
o RF24_PA_MAX: 0 dBm (highest power)
Example:
C++
radio.setPALevel(RF24_PA_MAX); // Set to maximum power
William
Hi ppl!
Provided 3.3Vdc(2) and GND(1), to those inputs pins on the nRF24L01 module,
should the 16Mhz xtal, starts to oscillate in case the module is OK?
Thanks !