Interface nRF24l01 Radio Tranciever Module With Arduino
Interface nRF24l01 Radio Tranciever Module With Arduino
Having two or more Arduinos able to communicate with each other wirelessly opens up a
world of possibilities, such as remotely monitoring sensor data, controlling robots, home
automation, and so on.
And when it comes to a low-cost but reliable 2-way RF solution, nothing beats Nordic
Semiconductor’s nRF24L01+ transceiver module.
The nRF24L01+ module is available for less than two dollars online, making it one of the
most affordable data communication options available.
Hardware Overview
Radio Frequency
The nRF24L01+ module is designed to operate in the 2.4 GHz worldwide ISM frequency
band and uses GFSK modulation for data transmission. The data transfer rate is configurable
and can be set to 250kbps, 1Mbps, or 2Mbps.
The 2.4 GHz band is one of the Industrial, Scientific, and Medical (ISM) bands reserved
internationally for unlicensed low power devices. Devices such as cordless phones, Bluetooth
devices, Near Field Communication (NFC) devices, and wireless computer networks (Wi-Fi)
use ISM frequencies.
Power
The module’s operating voltage ranges from 1.9 to 3.9V. Please keep in mind that powering
the module with 5V will most likely damage your nRF24L01+ module.
Despite the fact that the module operates at 1.9V to 3.6V, the logic pins are 5-volt tolerant, so
you do not need a logic level translator.
The output power of the module can be programmed to be 0 dBm, -6 dBm, -12 dBm, or -18
dBm. At 0 dBm, the module consumes only 12 mA during transmission, which is less than
the consumption of a single LED.
And the best part is that it consumes only 26 µA in standby mode and 900 nA in power down
mode. That’s why it’s the go-to wireless device for low-power applications.
SPI Interface
The nRF24L01+ communicates over a 4-pin SPI (Serial Peripheral Interface) with a
maximum data rate of 10Mbps.
All parameters, including frequency channel (125 selectable channels), output power (0 dBm,
-6 dBm, -12 dBm or -18 dBm), and data rate (250kbps, 1Mbps, or 2Mbps), can be configured
through the SPI interface.
The SPI bus uses the concept of a master and a slave. In most of our projects, the Arduino
serves as the master and the nRF24L01+ module serves as the slave.
Unlike the I2C bus, the SPI bus has a limited number of slaves. You can therefore use up to
two SPI slaves (two nRF24L01+ modules) on a single Arduino.
Technical Specifications
The first one uses an on-board antenna, which allows it to be more compact. A smaller
antenna, however, means a shorter transmission range. You will be able to communicate over
a distance of 100 meters using this module. Of course, that is outside in the open. Its range
gets a little weaker inside the house, especially because of the walls.
The second one has an SMA connector and a duck antenna, but that’s not the only difference.
It includes an RFX2401C range extender chip that combines PA, LNA, and transmit-receive
switching circuitry. This enables the module to achieve a significantly greater transmission
range of up to 1000 meters.
Except for this difference, both modules are drop-in compatible. If you build your project
with one, you can just unplug it and use the other without making any changes to the system.
PA stands for Power Amplifier. It merely amplifies the signal that is being transmitted by the
nRF24L01+ chip. LNA stands for Low-Noise Amplifier, and its function is to amplify an
extremely weak signal received from the antenna (usually below microvolts or -100 dBm) to
a more useful level (usually around 0.5 to 1 V).
nRF24L01+ PA/LNA Block Diagram
The receive path’s low-noise amplifier (LNA) and transmit path’s power amplifier (PA)
connect to the antenna via a duplexer, which isolates the two signals and prevents the
relatively powerful PA output from overloading the sensitive LNA input. Read this article on
digikey.com for more information.
The nRF24L01+ module transmits and receives data on a specific frequency known as
a channel. For two or more modules to communicate with each other, they must be on the
same channel. This channel can have any frequency in the 2.4 GHz ISM band, or more
precisely, any frequency between 2.400 and 2.525 GHz (2400 to 2525 MHz).
Each channel takes up less than 1 MHz of bandwidth. This gives us 125 possible channels
with a 1MHz spacing.
This means that the nRF24L01+ can operate on 125 different channels, allowing you to build
a network of 125 independently operating modems in one location.
At 250kbps and 1Mbps air data rates, each channel takes up less than 1 MHz of bandwidth,
so there is a 1 MHz gap between the two channels. However, for a 2 Mbps air data rate,
2MHz of bandwidth is required (greater than the resolution of the RF channel frequency
setting). So, in 2 Mbps mode, keep a 2MHz gap between the two channels to ensure non-
overlapping channels and reduce cross-talk.
The RF channel frequency of your selected channel is calculated using the following formula:
For example, if you choose channel 108 for data transmission, the RF channel frequency will
be 2508 MHz (2400 + 108).
The nRF24L01+ includes a feature known as Multiceiver. It stands for Multiple Transmitter
Single Receiver.
In a multiceiver network, each RF channel is logically divided into six parallel data channels
known as data pipes. In other words, the data pipe is one of six logical channels within a
single physical RF channel. Each data pipe has its own unique address, known as a data pipe
address. Only one data pipe can receive a packet at a time.
A multiceiver network is depicted below.
To understand a multiceiver network, imagine the primary receiver acting as a hub receiver,
collecting data from six different transmitter nodes at the same time. The hub receiver can
switch from listening to transmitting at any time.
The nRF24L01+ uses a packet structure known as Enhanced ShockBurst. It has five fields:
• Each sent packet is assigned a packet ID, which allows the receiver to determine
whether the message is new or has been retransmitted.
Let’s go over three scenarios to better understand how the two nRF24L01+ modules interact
with one another.
This is an example of a positive scenario. In this case, the transmitter starts the
communication by sending a data packet to the receiver. After transmitting the packet,
the transmitter waits approximately 130 µs for the acknowledgement (ACK) to arrive.
The receiver sends the ACK after successfully receiving the packet. Once the
transmitter receives the ACK, the transaction ends.
This is a negative scenario in which retransmission is required due to packet loss. The
transmitter waits for the ACK after transmitting the packet.
If the transmitter does not receive it within the auto-retransmit-delay (ARD) time, the
packet is retransmitted. When the receiver receives the retransmitted packet, it sends
the ACK, which ends the transaction.
• Transaction with a lost acknowledgment:
This is another negative scenario in which retransmission is required due to the loss of
the ACK. Because the transmitter did not receive the ACK, it believes the packet was
lost (even though the receiver received the packet on the first attempt).
The nRF24L01+ chip handles the entire packet handling process without the involvement of
the microcontroller.
VCC supplies power to the module. It can range from 1.9 to 3.9 volts. You can connect it to
your Arduino’s 3.3V output. Please keep in mind that connecting this to the 5V pin will most
likely damage your nRF24L01+ module.
CE (Chip Enable) is an active-high pin. When enabled, the nRF24L01 will either transmit or
receive, depending on the mode.
CSN (Chip Select Not) is an active-low pin that is typically held HIGH. When this pin goes
low, the nRF24L01 begins listening for data on its SPI port and processes it accordingly.
SCK (Serial Clock) accepts clock pulses from the SPI bus master.
MOSI (Master Out Slave In) is the SPI input for the nRF24L01.
IRQ is an interrupt pin that can notify the master when there is new data to process.
Let’s wire up the SPI pins. Note that each Arduino board has a unique set of SPI pins that
must be connected accordingly. For Arduino boards such as the UNO/Nano V3.0, these pins
are digital 13 (SCK), 12 (MISO), 11 (MOSI) and 10 (SS).
If you’re using a different Arduino board, check the official documentation for SPI pin
locations before proceeding.
The images below show how to connect the nRF24L01+ module to the Arduino.
Wiring nRF24L01+ Wireless Transceiver Module to Arduino UNO
Wiring nRF24L01+ PA LNA Wireless Module to Arduino UNO
Remember, you need to make two such circuits. One will act as a transmitter and the other as
a receiver. Both have the same wiring.
Library Installation
There are many libraries available for the nRF24L01+ module, but one of the most popular
is RF24. This library has been around for a long time. It’s simple to use for beginners while
still providing a lot for advanced users. We will use this library in our examples.
To install the library, navigate to Sketch > Include Library > Manage Libraries… Wait for
the Library Manager to download the library index and update the list of installed libraries.
Filter your search by entering ‘rf24‘. Look for the library by TmRh20. Click on that entry and
then choose Install.
Arduino Example Code – For Transmitter
The examples below demonstrate how to set up a simple one-way link between a transmitter
and a receiver. The transmitter simply sends a traditional ‘Hello World’ message to the
receiver, which displays it in the Serial Monitor window.
//Include Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
void setup()
{
radio.begin();
delay(1000);
}
Code Explanation
The sketch begins by including the necessary libraries. The SPI.h library handles SPI
communication, while the nRF24L01.h and RF24.h libraries control the module.
//Include Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
Next, we create an RF24 object. The constructor of this object accepts two pin numbers as
arguments, to which the CE and CSN signals are connected.
Next, we create a byte array to store the pipe address used by the two nRF24L01+ modules to
communicate.
The pipe address does not have to be “00001,” but it can be any 5-character string like
“node1.” Simply ensure that both the transmitter and receiver use the same address.
With a pipe address, you can choose a specific module on your network and communicate
with it. This is useful if your network contains multiple modules.
In the setup section, we use the begin() function to initialize the radio object, followed by
the openWritingPipe() function to set the transmitter address.
radio.begin();
In the loop section, we first create an array of characters and store the message “Hello world”
in it.
We use the write() function to send the message to the receiver. This function takes two
arguments: the message to be sent and the number of bytes it contains.
The write() function returns a bool value, which you can use to verify whether the data was
correctly received by the receiver. When the data reaches the receiver, it returns TRUE;
otherwise, it returns FALSE.
Also, it is important to note that the write() function stops the program until it receives an
acknowledgement or exhausts all retransmission attempts.
//Include Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
void setup()
{
while (!Serial);
Serial.begin(9600);
radio.begin();
void loop()
{
//Read the data if available in buffer
if (radio.available())
{
char text[32] = {0};
radio.read(&text, sizeof(text));
Serial.println(text);
}
}
Code Explanation
Except for a few changes, this code is very similar to the transmitter’s code.
At the beginning of the setup function, we initiate the serial communication. Then, using
the openReadingPipe() function, we set the same pipe address as the transmitter. This
enables the transmitter and receiver to communicate with one another.
The openReadingPipe() function’s first argument specifies which pipe to open for reading.
Because up to six pipes can be opened for reading at the same time, the possible range is 0-5.
In our case, pipe 0 was opened for reading. The second argument is the 40-bit address of the
pipe to open.
Following that, we configure the module as a receiver and begin receiving data. We use
the startListening() function to accomplish this.
The available() method is used in the loop section to check whether any data is available
to be read. This method returns TRUE if data is available, FALSE otherwise.
if (radio.available())
{
char text[32] = {0};
radio.read(&text, sizeof(text));
Serial.println(text);
}
When data is available, an array of 32 characters filled with zeros is created to store it. The
data is then read from the buffer and stored in our character array using the read(&text,
sizeof(text)) method.
Finally, the received message is printed on the serial monitor.
A circuit that generates a radio frequency (RF) signal is extremely sensitive to power supply
noise. Power supply noise, if not controlled, can significantly reduce the range you can
achieve.
Unless the power source is a standalone battery, there is a good chance that the power output
is noisy. To prevent this noise from entering the system, it is recommended that a 10 µf filter
capacitor be placed across the power supply line as close to the nRF24L01+ module as
possible.
The simplest way to reduce power supply noise is to use a low-cost adapter for the
nRF24L01+ module.
nRF24L01+ Adapter
This adapter has an 8-pin female connector where you can plug in your nRF24L01+ module.
It can accommodate both versions of the nRF24L01+ module, one with an integrated antenna
and one with an external antenna (PA/LNA).
It also has a 2-pin connector for power input and a 6-pin male connector for SPI and interrupt
connections.
Since the adapter has a built-in 3.3V voltage regulator and filter capacitors, you can safely
power it with a 5V power supply.
The external environment can also be a source of noise for RF circuits, especially if
neighbouring networks are set to the same channel.
Because Wi-Fi primarily uses lower frequency channels, it is recommended that you use the
highest 25 channels of your nRF24L01+ to avoid interference from these signals.
At 250Kbps, the nRF24L01+ has the highest receiver sensitivity of -94dBm. However, at
2MBps data rate, receiver sensitivity drops to -82dBm. That is, at 250kbps, the receiver is
approximately ten times more sensitive than at 2Mbps, allowing it to decode ten times
weaker signals.
As a result, lowering the data rate can significantly improve the range you can achieve. Plus,
a speed of 250kbps is sufficient for the majority of our projects.
Receiver sensitivity is the minimum power level at which the receiver can detect an RF
signal. The greater the absolute value of a negative number, the greater the receiver’s
sensitivity. A receiver sensitivity of −94dBm, for example, outperforms a receiver sensitivity
of −82dBm by 12dB.
Setting the maximum output power can also help to extend the range of communication. The
nRF24L01+ supports a variety of output power levels, including 0dBm, -6dBm, -12dBm, and
-18dBm. Choosing 0dBm output power sends stronger signals into the air but consumes more
power.