Complete Guide for nRF24L01 – 2.4GHz RF Transceiver Module With Arduino

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.

nrf where to buy

I have more complete guides for other popular sensors, check them below:

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:

  • 2x Arduino (eBay)
  • 2x nRF24L01 – 2.4GHz RF Transceiver (eBay)
  • Breadboard (eBay)

Library download

Here’s the library you need for this project:

  1. Download the RadioHead library
  2. Unzip the RadioHead library
  3. Install the RadioHead library in your Arduino IDE
  4. 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

24L01Pinout-800
Top view of NRF24L01

Client Circuit

nrf24 radiohead with ArduinoImportant: 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);
}

View raw code

Server Circuit

nrf24 radiohead with Arduino 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");
    }
  }
}

View raw code

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

serial communication

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



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

63 thoughts on “Complete Guide for nRF24L01 – 2.4GHz RF Transceiver Module With Arduino”

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

    Reply
    • 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

      Reply
      • 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?

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

    Reply
  3. 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?

    Reply
  4. 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….

    Reply
    • 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

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

    Reply
  6. 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?

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

    Reply
  8. 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?

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

    Reply
  10. 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!

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

    Reply
  12. 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?

    Reply
    • 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

      Reply
  13. 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?

    Reply
    • 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

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

    Reply
    • Hi Kumuran.
      I think that error means that the nRF24L01 is not properly connected, so it can’t initialize.
      Regards,
      Sara 🙂

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

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

    Reply
    • 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

      Reply
    • 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

      Reply
  17. Hi,
    Thank you very much, excuse mmoi I wanted to know how to do for a servomotor controlled by a potentiometer

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

    Reply
  19. 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 🙂

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

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

    Reply
  22. 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?

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

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

    Reply
  25. 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 !

    Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.