nRF24L01 Wireless Module with Arduino

Now we have a demo show how to use the Arduino controlling the nRF24L01 module , and you need two Arduino boards and two modules, one to transmit and the other receive. The connection of two part is the same but the different software.

The nRF24L01 module is worked at 3V voltage level , so the Arduino 5V pins may destroy it , so we need to add some resister to protect the module – using the 10K and the 15K resister to reduce the voltage is a usual method.

Connect the module pins to Arduino as below:
CS – D8 , CSN – D9 , SCK – D10 , MOSI – D11 , MISO – D12 , IRQ – D13
 

Download the code below into the TX Arduino  (transmit) — This code will drive the nRF24L01 module to send out data form 0×00 to 0xFF .
void setup()
{
  SPI_DIR = ( CE + SCK + CSN + MOSI);
  SPI_DIR &=~( IRQ + MISO);
  Serial.begin(9600);
  init_io();
  TX_Mode();
}
void loop()
{
  unsigned char status=0;
  unsigned char key=0;
  for(;;)
  {
    tx_buf[1]=key;
    key++;
    status=SPI_Read(STATUS);
    if(status&TX_DS)
    {
      SPI_RW_Reg(FLUSH_TX,0);
      Serial.println(tx_buf[1],HEX);
      SPI_Write_Buf(WR_TX_PLOAD,tx_buf,TX_PLOAD_WIDTH);
    }
    SPI_RW_Reg(WRITE_REG+STATUS,status);
    delay(1000);
  }
 
}

Download the code below into the RX Arduino (receive) – This code will drive the nFR24L01 module to receive the data that transmit form the TX module and print it to serial port.

void setup()
{
  SPI_DIR = ( CE + SCK + CSN + MOSI);
  SPI_DIR&=~ ( IRQ + MISO);
  Serial.begin(9600);
  init_io();
  RX_Mode();
}
void loop()
{
  unsigned char status=0;
  unsigned char key=0;
  for(;;)
  {
    tx_buf[1]=key;
    key++;
    status=SPI_Read(STATUS);
    if(status&TX_DS)
    {
      SPI_RW_Reg(FLUSH_TX,0);
      Serial.println(tx_buf[1],HEX);
      SPI_Write_Buf(WR_TX_PLOAD,tx_buf,TX_PLOAD_WIDTH);
    }
    SPI_RW_Reg(WRITE_REG+STATUS,status);// clear RX_DR or TX_DS or MAX_RT interrupt flag
    delay(1000);
  }
}

Now power on both Arduino , and connect the RX one to PC via USB. Open the IDE serial port monitor , change the baud rate to 9600 bps , and you can see the data that received.

If you want to change Arduino pin connecting to module , just modify the define on the NRF24L01.h .

All the project here(include API.h and NRF24L01.h)

  nRF24L01 Demo code for Arduino (unknown, 2,977 hits)

You can fine the cables , resisters and the nRF24L01 module that used in the demo on our webshop.

Responses to “nRF24L01 Wireless Module with Arduino

  1. In the figure above the arduino board is apparently connected directly to the nRF24L01 module. So, how do you adapt the 5V from arduino to the 3V in module ?
    Thanks!

    • The simplest way is to connect the arduino and the moudle with a 20K resistor in series , then you can use the 5V I/O of arduino to control the nRF24L01 directly. The best way , we use the iteaduino which the improved version of arduino, and it’s I/O voltage is 3.3V or 5V adjustable by a switcher , so we can choose using the 3.3V I/O level to control all the 3.3V module directly. Also , the arduino mini or arduino pro is 3.3V I/O level so they can be used with this module directly.

      • In the figure above the nRF24L01 module already has these resistors in its board ? My doubt is because apparently there is no resistor between the arduino and the module in the figure. Thanks !

        • I am sorry that there is not the resistors in the nRF24L01 , if you want to connect it to Arduino that you need to build the circuit yourself or use the Arduino pro/mini.
          Also , the best choice is using the iteaduino ; ) — because it’s compatible with both 3.3V and 5V I/O level.

  2. After looking at the datasheet I noticed that if you provide a maxium VCC of 3.3V the NRF module can handle 5V signales so just check that you 3.3V supply is MAX 3,3 and you don’t need any resistors.

  3. I’m interested in using this module to connect an Arduino to a PC without the USB cable. The 2.4GHz PC USB dongles I’ve seen are quite expensive.
    Would it be possible to use this module to make a wireless Arduino?

    • Hi,
      I think if you want to make a wireless Arduino, except the 2.4G module you also need other MCU which receive the data from PC and download it into Arduino via USB.
      Maybe a Bluetooth is a better idea than 2.4G because it can directly change the data into serial into Arduino.

  4. hello..
    I was planing on purchasing this, it is so in-expensive, and the hook-up seems so easy. But then I checked out the tutorials on this page: http://blog.diyembedded.com/, and they gave so much information that I am now seriously questioning whether the setup described here is really as simple as it appears to be. Can somebody re-assure me?
    -mike

  5. I built everything as described. Tested many times. Doesn’t work. Obviously I am doing something wrong. How do I debug?
    Thank you

  6. With a 20K resistor connecting in-series between the Arduino I/O pin and the nRF24L01 Wireless Module I/O pin to reduce the I/O voltage from 5V to 3.3V, it means that the current flows through the I/O pin should be (5-3.3)/20K = 0.085mA. From the Arduino Duemilanove homepage (http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove), the page says that “Each pin can provide or receive a maximum of 40 mA”. I wonder whether the Arduino board is really delivering such small amount of current (~0.085mA) in its I/O pin. Could anyone confirm this ?

  7. I’d like to see an Arduino shield with this module and a 3.3 volt regulator.
    Kind of like the SDcard shield. Just a suggestion.

  8. it’s nice work but not work for me i add a 10 kilo for down 5 volt to 2 or higer but Arduino not work with it
    any way thank you

    • 20k ohm is a too larger value, please try a 100 ohm register. And if just for a try, you can connect the module directly to Arduino pin, it will not destroy the module immediately.

  9. Connecting 3V RF devices to the Arduino is quite common.
    Normal practice is to reduce the supply voltage from 5V to 3V using forward biased diodes. Each diode drops approx 0.5V, some drop a bit less so you need to make a test circuit with your own diodes and confirm the voltage using a meter.
    For the data input the normal practice is to use a voltage divider using 2 resistors.
    10k and 15k are the most commonly used values, sometimes 10k and 12k
    e.g. 10+25=25k
    15/25 * 5v= 3V
    For data in to the Arduino, (I’ve not tested this), but technically “HIGH” is at least 0.6 x Vcc. So if Vcc is 5V, then HIGH = 0.6 x 5V = 3V. So if this module outputs at least 3V the Arduino should be able to read the input.
    If this doesn’t work the only option is to use a transistor to drive the input pin on the Arduino.
    BTW. I’ve just ordered 3 of these for testing, so if I remember I’ll update this blog when I have it working from 5V

  10. I have added the resistors in series, confirmed my connections many times and I cannot send a simple character. Has anyone confirmed that the code they supplied works?

    • @ Elroy : ) It’s sure that the code can work, why not try using the Iteaduino and put the operation value to 3.3V and you don’t need the resistor which may bring you the issue once they not be connected well.

  11. The datasheet states that this chip has a maximum of 3.6V on VDD, but also that its input pins can be driven to 5.25V
    Sparkfun do sell this chip and state that is has 5V tolerant inputs.
    I am pretty sure that as long as the VDD is driven by 3.3V no harm will be done if you use direct connections on the Arduino family.

  12. I’m a bit confused as to what this code does exactly. It looks like the RX and TX code are identical except that the RX code is in RX mode and the TX code is in TX mode. On the RX code, you’re transmitting the counter data and waiting for a register status which shows that the transmission has been received? Shouldn’t the RX code wait until data is received and then read the data and then do something with the data that has been read? To put it simply: nowhere in the code is either device actually reading any data.

  13. John, you are right. The loop() routine in the RX version the code just prints out the value of the local variable key which has been invcremented and stored in tx_buf[1]. When you run this code, you see a series of hex value counting from 0 -> FF — but these are not received characters, the program is simply printing out the value of this local variable to the serial output! The proof is that it even “works” when there is no transmitting Arduino powered on! As you say, the RX code is not actually reading any received data anywhere… I suspect this the wrong version of “loop()” for the RX code, and that somehow the TX version of “loop()” found its way in there.

  14. is there any modification version about the Receive program? that Receive program activity is useless, it’s not reading information that Receive from Transmit program, there’s just print “key” variabel that counter. please give us a solution. thanks.

    • I realized now that this article was posted in 2010, before the iBoard …
      I found the library suitable for the iBoard: https://github.com/andykarpov/iBoardRF24

      I managed to get it working even on gBoard changing the following line initialization (referring to the example GettingStarted included in the library):
      Original for iBoard: iBoardRF24 radio (3,8,5,6,7,2);
      Modified for gBoard: iBoardRF24 radio (8,9,11,12,13,2);

    • @sincar

      You should change the code because the code use the pin is not the same as IBoard, Gboard and RBoard, you need to read the datasheet of Iboard and Gboard, them modify the code with right pin cofigulation.  Of you can download the library which in the DOWNLOAD lable of product page.

    • Hi, You can not use it directly in your AT90USB162, you need to change some code because of the different register setting of different MCU

  15. Sorry for speaking bad english i’m french. Im a newbie. I have a question about modify pins connect into the NRF24L01.h file. I have an Arduino Nano and i dont have more than 12 digital port on my arduino. You said that i can change the pin for connect to the module. I take a look into the file but i can find IRQ definition line. Please h

  16. Hi, I´m working with nRF24L01 + arduino Uno. This is my first project that I´m using Arduino and RF
    1. I´d like of communicate two arduino using nRF24L01 for temperature measure
    2. Someone could help me with a basic implementation for me make a test. When I could leave a arduino in the PC and put the other near the enginer i possible??
    I already have two arduino and two nRF24L01 and two sensor, just need i put the nRF24L01 in ckt for make a test.
    Thanks a lot
    Best Regards

  17. There is problem with examples you included in this blog entry. In Arduino 1.0.4 there is header file called pins_arduino.h. In that file there are definitions for MISO, MOSI and CLK as pins. But in nrf24l01.h there are also definition of MISO, MOSI and CLK!!! There is double definition with same names so compiler output lot of errors. I renamed MISO, MOSI and CLK in nrf24l01.h as MISO_n24, MOSI_n24 and CLK_n24, and I also renamed all MISO, MOSI and CLK in nRF24l01_RX.ino and nRF24l01_TX.ino.

  18. I get the sample code from cytron and my project is about the same with this one, but I’m using pic16f877a. I have follow the sample connection provided by cytron, but it does’t work at all. Is it I have miss out something??

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>