NRF 24 L
NRF 24 L
2.
1. Now Playing
Wordle Game Answer Today -Reveal the Answer
2.
Top 10 Strategies for Identifying Key Points in TOEFL iBT
Reading Texts
4:32
3.
Top 10 Techniques for Enhancing Vocabulary with Flashcards at
B1 Level
4:00
4.
How To Change Windshield Wipers: A Comprehensive Guide
2:35
5.
Spirited In Sentences Example Of Spirited In Sentences How To
Use Spirited In Sentences
2:30
6.
Top 10 English Idioms for Computer Programmer
5:54
7.
Vague In Sentences - Examples Of Vague In Sentences
2:30
8.
How To Get Admission Into Michigan State University
3:13
9.
Top 10 English Verbs for Discussing Cultural Exchange Programs
and International Studies
4:47
10.
Top 10 Ways to Practice Vocabulary with a Language Partner
4:39
11.
Play Video
Wordle Game Answer Today -Reveal the Answer
In this tutorial we will learn how to make wireless
communication between two Arduino boards using
the nRF24L01 transceiver modules. The nRF24L01 module is very
popular choice for wireless communication when using Arduino.
I have already used this module for numerous Arduino projects and
you can check out some of them here:
Overview
For explaining the wireless communication we will make two
examples, the first one will be sending a simple “Hello World”
message from one Arduino to another, and in the second example
we will have a bi-directional communication between the Arduino
boards, where using the Joystick at the first Arduino we will control
the servo motor at the second Arduino, and vice versa, using the
push button at the second Arduino we will control the LED at the
first Arduino.
How It Works
The module can use 125 different channels which gives a possibility
to have a network of 125 independently working modems in one
place. Each channel can have up to 6 addresses, or each unit
can communicate with up to 6 other units at the same time.
Module variations
There are several variations of the NRF24L01 modules. The most
popular is the one with on-board antenna. This makes the module
to be more compact, but on the other hand, lowers the transmission
range to a distance of about 100 meters.
The second variation, instead of on-board antenna, it has a SMA
connector and which we can attach a duck antenna for better
transmission range.
Uno 13 12 11 10
Nano 13 12 11 10
Mega 52 50 51 53
NRF24L01 Transceiver
Module……… Amazon / Banggood / Aliexpress
Arduino Board
……………………………… Amazon / Banggood / Aliexpress
Breadboard and Jump Wires
………… Amazon / Banggood / Aliexpress
Disclosure: These are affiliate links. As an Amazon Associate I earn
from qualifying purchases.
First we need to download and install the RF24 library which makes
the programming less difficult. We can also install this library
directly from the Arduino IDE Library Manager. Just search for “rf24”
and find and install the one by “TMRh20, Avamander”.
Here are the two codes for the wireless communication and below
is the description of them.
Transmitter Code
/*
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
void loop() {
radio.write(&text, sizeof(text));
delay(1000);
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}
void loop() {
if (radio.available()) {
radio.read(&text, sizeof(text));
Serial.println(text);
So we need to include the basic SPI and the newly installed RF24
libraries and create an RF24 object. The two arguments here are the
CSN and CE pins.
// at the Transmitter
void loop() {
delay(1000);
On the other side, at the receiver, in the loop section using the
radio.available() function we check whether there is data to be
received. If that’s true, first we create an array of 32 elements, called
“text”, in which we will save the incoming data.
void loop() {
if (radio.available()) {
radio.read(&text, sizeof(text));
Serial.println(text);
Another common issue is that the 3.3V pin of the Arduino boards,
cannot always supply enough power to the NRF24L01 module. So,
powering the module with an external power source is also a good
idea.
You can get the components needed for this example from the links
below:
NRF24L01 Transceiver
Module………… Amazon / Banggood / AliExpress
Arduino
Board…………………………………. Amazon / Banggood / AliE
xpress
Joystick Module
………………………………. Amazon / Banggood / AliExpress
Servo Motor
……………………………………. Amazon / Banggood / AliExpr
ess
Pushbutton
…………………………………….. Amazon / Banggood / AliExpr
ess
LED
………………………………………………… Amazon / Banggood /
AliExpress
Disclosure: These are affiliate links. As an Amazon Associate I earn
from qualifying purchases.
See Also
How To Build an Arduino Wireless Network with Multiple
NRF24L01 Modules
Transmitter Code
/*
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define led 12
boolean buttonState = 0;
void setup() {
pinMode(12, OUTPUT);
radio.begin();
radio.openWritingPipe(addresses[1]); // 00002
radio.setPALevel(RF24_PA_MIN);
void loop() {
delay(5);
radio.stopListening();
radio.write(&angleValue, sizeof(angleValue));
delay(5);
radio.startListening();
while (!radio.available());
radio.read(&buttonState, sizeof(buttonState));
if (buttonState == HIGH) {
digitalWrite(led, HIGH);
else {
digitalWrite(led, LOW);
/*
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
#define button 4
Servo myServo;
boolean buttonState = 0;
void setup() {
pinMode(button, INPUT);
myServo.attach(5);
radio.begin();
radio.openWritingPipe(addresses[0]); // 00001
void loop() {
delay(5);
radio.startListening();
if ( radio.available()) {
while (radio.available()) {
int angleV = 0;
radio.read(&angleV, sizeof(angleV));
myServo.write(angleV);
delay(5);
radio.stopListening();
buttonState = digitalRead(button);
radio.write(&buttonState, sizeof(buttonState));
radio.openWritingPipe(addresses[1]); // 00001
radio.openWritingPipe(addresses[0]); // 00002
radio.stopListening();
radio.startListening();
if ( radio.available()) {
while (radio.available()) {
int angleV = 0;
radio.read(&angleV, sizeof(angleV));
myServo.write(angleV);
Transmitter Code
/*
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
struct Data_Package {
byte a = 0;
byte b = 125;
byte c = 255;
int d = 1024;
float e = 3.141592;
String f = "Test";
};
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop() {
radio.write(&data, sizeof(Data_Package));
delay(500);
struct Data_Package {
byte a = 0;
byte b = 125;
byte c = 255;
int d = 1024;
float e = 3.141592;
String f = "Test";
};
Data_Package data; // Create a variable with the above structureCode language: Arduino
(arduino)
We should keep in mind that the maximum size of this struct data
can be 32 bytes. Here we can see I included three variables type
byte, one integer variable (4 bytes), one float variable (4 bytes) and
one String containing four characters (4 bytes). That’s total of 15
bytes.
Receiver Code
/*
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
struct Data_Package {
byte a = 0;
byte b = 125;
byte c = 255;
int d = 1024;
float e = 3.141592;
String f = "Test";
};
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
void loop() {
if (radio.available()) {
radio.read(&data, sizeof(Data_Package)); // Read the whole data and store it into the 'data'
structure
}
Serial.print("a: ");
Serial.print(data.a);
Serial.print(" b: ");
Serial.print(data.b);
Serial.print(" c: ");
Serial.print(data.c);
Serial.print(" d: ");
Serial.print(data.d);
Serial.print(" e: ");
Serial.print(data.e);
Serial.print(" f: ");
Serial.println(data.f);
Here I will list all of my projects in which I have used these modules.