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

Build 25 cool Arduino projects with our course even with no prior experience DOWNLOAD »

Build 25 cool Arduino projects with our course even with no prior experience DOWNLOAD »

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

Download our Free eBooks and Resources

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 program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »

Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »


Enjoyed this project? Stay updated by subscribing our weekly newsletter!

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

    • 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

  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

  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?

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

    • 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

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

  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?

  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

  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?

  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

  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!

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

  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?

    • 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

  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?

    • 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

  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.

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

  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.

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.