Weâve used Infrared and Bluetooth to talk to an Arduino. But what if you want two Arduinos to gossip behind your back? Whether youâre building a weather station or a drone, Arduino-to-Arduino communication is basically black magic. Enter the NRF24L01+. This absurdly cheap radio transceiver uses the 2.4GHz band to blast data packets through the air. Now your microcontrollers can plot against you together.
The NRF24L01 module is small but powerful, allowing two microcontrollers to form a local network.
For this lesson, you will need two sets of hardware (a transmitter setup and a receiver setup).
The NRF24L01 is a transceiver, meaning it can both transmit (send) and receive (listen for) data. Unlike Bluetooth, which is designed to connect to your phone, NRF24L01 modules are designed to talk to other NRF24L01 modules using a protocol called SPI.
SPI (Serial Peripheral Interface) requires several pins to operate:
Warning: The NRF24L01 strictly requires 3.3V for power! Connecting its VCC pin to 5V will instantly fry the module.
However, its data pins are 5V tolerant, so you can connect them directly to your 5V Arduino Uno.
Wire both the Transmitter Arduino and Receiver Arduino identically:
To make things easy, we will use the fantastic RF24 library created by TMRh20. Go to your Arduino IDE Library Manager and install RF24.
This code sends a simple âHello Worldâ message every second.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001"; // Communication pipe address
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN); // Use minimum power for testing
radio.stopListening(); // Set as transmitter
}
void loop() {
const char text[] = "Hello from Transmitter!";
radio.write(&text, sizeof(text));
delay(1000);
}
Upload this code to your second Arduino. Open the Serial Monitor at 9600 baud.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001"; // Must match the transmitter!
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening(); // Set as receiver
}
void loop() {
if (radio.available()) {
char text[32] = ""; // Create a buffer
radio.read(&text, sizeof(text));
Serial.println(text);
}
}
The NRF24L01 is notorious for drawing sudden spikes of power during transmission. The Arduinoâs 3.3V pin is quite weak. If your modules are dropping connections or refusing to work, the solution is almost always to solder a small capacitor (like a 10uF electrolytic capacitor) directly across the VCC and GND pins of the NRF24L01 module.
In our next lesson, weâll learn how to measure gravity and orientation to build a Digital Smart Level!