Introduction: Arduino + NRF24L01: Simple Bidirectional Wireless Communication

Picture of Arduino + NRF24L01: Simple Bidirectional Wireless Communication

With this project I wanted to establish bidirectional communication between two circuits. To do so, I used the nRF24L01, which is ultra low power transciever that operates at about 2,4 GHz.

The circuits are very simple and will only do two thigs:

  1. turn on a green LED when the circuit is sending a message.
  2. turn on a red LED when a message has been received.

This can be used as base for a more complex project. For example, it could easily be expanded to send complex data streams.

Step 1: Required Hardware

Picture of Required Hardware

Per circuit, you will be needing following elements:

  • Arduino board, I will be using an Arduino Nano with the ATmega328 chip.
  • nRF24L01 transmitter.
  • 2 LEDs, one green and one red.
  • A button.
  • 3 Resistors (depends on your LEDs, but probably about 200-1000 Ohm).
  • (Optional, but very helpful) Breadboard.

Step 2: Connection

Picture of Connection

IMPORTANT: You can use the normal 5V digital pins for the input pins of the nRF24L01, but you must use the 3.3V pin as input power source. If you use 5V instead, you will probably burn the chip, since 5V is outside of its 1.9 to 3.6V supply range.

The Arduino nano to nRF24L01 pin connection is as follows (note that you may need to connect it differently if you use a different arduino board, refer to the RadioHead library):

  • VCC - 3.3V
  • GND - GND
  • CE - D8
  • CSN - D10
  • SCK - D13
  • MOSI - D11
  • MISO - D12
  • IRQ - Not connected

Further, I use D5 for the button, D4 for the red LED and D3 for the green one, each connected with a 220 Ohm resistor.

To power the arduino boards, you can connect them to a USB port or to a 9V battery (Battery negative to GND and positive to VIN).

Step 3: Code

Download the RadioHead Library and install it.

Upload this code to each of the arduino boards:

#include <SPI.h>

#include <RH_NRF24.h>

// Singleton instance of the radio driver RH_NRF24 nrf24;

int greenLed = 3; int redLed = 4; int button = 5;

void setup() { Serial.begin(9600); pinMode(greenLed, OUTPUT); pinMode(redLed, OUTPUT); pinMode(button, INPUT); 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 (digitalRead(button)) { //button is pressed, message should be sent, turn the green LED on digitalWrite(greenLed, HIGH);

// Send a message uint8_t data[] = "Aloha"; nrf24.send(data, sizeof(data)); nrf24.waitPacketSent(); digitalWrite(greenLed, LOW); } else { // Wait for a message uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN]; uint8_t len = sizeof(buf); while (nrf24.waitAvailableTimeout(200) && nrf24.recv(buf, &len)) { //something was received, turn the right LED on digitalWrite(redLed, HIGH); } digitalWrite(redLed, LOW); } }

Step 4: Result


siva.prasad.543792 (author)2017-10-26

Hello sir,

my name is siva I'm working on bidirectional communication using two arduino uno's and NRF24L01.

can you please send bidirectional code for "HELLO WORLD" in which one arduino send HELLO WORLD and another replys THANK YOU .

CliffordLeeBurton (author)2017-01-15

Hello, thank you for sharing your work. It was very helpful!
How do I read the message in receiver? Tried "Serial.println(buf)" in the while loop but it gives "call of overloaded println(uint8_t [28]) is ambiguous" ...I want to read and check (compare) the message on receiver.
Thank you again

You probably have to cast the variable first

Yes, that was what I did and it worked

how did you do that i am trying to make 3 leds on each end that activate with said buttons but everything i receive is 2271 i need at least 3 diffrint readings

NatanGoldschlag (author)2017-04-20

Will this code work with Arduino/Genuino Uno

I think so

elisklenina (author)2017-03-07

Hello, this code is very helpful for me in terms of task Send message and receive function that work for both objects. My project is that there are two cubes. Both has 4 buttons and 4 leds and 1 startButton. The task is: if startButton is not pushed send Sleep and set LEDs on, when startButton is pushed send StartGame and set LEDs off. The question: how to make rnf to differ messages Sleep and Start and make it do different things? (for sleep led on, for start led off)

I have a code for transmitter and receiver seperatly.I used const char instead of unit8_t and i have such commands as, radio.openingpipe and others. And it works, it does two things as it should. But now I need to make both arduinos to and transmitter and receiver.

DanielK82 (author)elisklenina2017-03-07

They already are transmitter and receiver

elisklenina (author)DanielK822017-03-07

Yes, but they do the same things at time. I need one to send a message another to get this message, and because of receiving that message it does the game. And that should from both sides. I don't understand what should I write in message recieving.

DanielK82 (author)elisklenina2017-03-07

You compile different codes for each of them.

One must contain the sending part (the block in `if (digitalRead(button))`) and the other the receiving part (the block in the `else`). The receiving part must also contain the game.

MinhT34 (author)2016-08-27

can you show me how to read your library?, i want to use another Microcontrollers, thanks

DanielK82 (author)MinhT342017-03-07

It is not my library, I just used it, you may ask at the libraries site

GurielV (author)2016-08-09

can you send me the Library Thanks :)

GurielV (author)GurielV2016-08-09

can't download it sorry

DanielK82 (author)GurielV2017-03-07

Here is a direct link:

Gyalu1 made it! (author)2016-05-14

Hi, thank you for this instructable.

I made it and learned a lot.

PeterP101 made it! (author)2016-04-04

Great :) thanks

ZipDriveRT (author)2016-03-29

how can we just have open terminal to send any strings? rather than just sending set var strings.

DanielK82 (author)ZipDriveRT2016-03-30

Use the read function ( and use the result instead of the `"aloha"` string. Then, above the line with `//something was received, turn the right LED on` write `Serial.println(buf)` to print the received data

Dav22 (author)2016-03-28

good tut.....thanx

About This Instructable



More by DanielK82:Arduino + nRF24L01: Simple bidirectional wireless communicationLED matrix - Game of life
Add instructable to: