NRF24L01 – Connection to Arduino

Many of you have probably heard about the remote control when everything is controlled at a great distance with a couple of simple taps. Pressed a button on the remote - and the light came on or your favorite robot clung to your feet.
nrf24l01-and-arduino-1

Many of you have probably heard about the remote control when everything is controlled at a great distance with a couple of simple taps. Pressed a button on the remote – and the light came on or your favorite robot clung to your feet. And the most interesting thing here is that kilometer wires are not needed to control the built-in system.

The remote control can be divided into many subspecies: control via Bluetooth, via Wi-Fi, via radio and many others. Most of these types of communication can be linked to Arduino and then create your projects on this basis.

MODULE OVERVIEW NRF24L01
In this article, we will discuss the radio module NRF24L01, which can exchange data with Arduino at a frequency of 2.4 GHz.

Examples of the layout of these modules you can now see in the picture below:

This module is a receiver and transmitter at the same time. It is quite small. To work with the module, it will be important to know the following characteristics:

  • Recommended power supply from 3.3 to 3.6 V;
  • The range of action is up to 100 meters in open areas and up to 30 meters in rooms;
  • Number of channels: 125;
  • speed: <2 Mb / s;
  • Maximum output power: +20 dBm.

So what else can the NRF24L01 besides wireless control? It has already been said that the module allows both to transfer data to the Arduino board and to receive it from it. This allows you to collect the device used for monitoring and data collection. For example, to collect information about climate and air condition in a house/apartment/room, etc., and send this data to your phone or other means of control.

To implement the project from this article, we need the following components:

  • Arduino Uno R3
  • NRF24L01 +
  • Small breadboard
  • Wires kit

CONNECTION TO ARDUINO
The main goal of this operation is to connect two microcontrollers with our radio module to achieve data exchange between them.

The module is connected via the SPI interface.

To connect, you will have to use 7 contacts on the board, two of which are responsible for the power supply:

NRF24L01 Arduino Uno
GND GND
VCC +3.3V
CE 9
CSN 10
MOSI 11
MISO 12
SCK 13

 

 An illustrative wiring diagram is shown in the figure below:

WORKING WITH A RADIO MODULE IN ARDUINO IDE
For writing code and testing the NRF24L01, we need two libraries. They need to be downloaded and moved to the Library section in the folder where you have the Arduino IDE installed.

These are the RF24 and SerialFlow libraries.

In this article, we will give a few simple sketches for working with the module. For example, the following program code serves to test the functionality and transfers the current timer value from one device to another.

#include
SerialFlow rd(9,10);
const unsigned long data_to = 100;
unsigned long tm, data_next;
void setup(void){
rd.setPacketFormat(2, 1);
rd.begin(0xF0F0F0F0E1LL,0xF0F0F0F0D2LL);
}
void loop(void){
tm = millis();
if( tm > data_next ){
data_next = tm + data_to;
rd.setPacketValue( tm );
rd.sendPacket();
}
}

By the way, 9 and 10 are the Arduino PINs to which the contacts of the CN and CSN radio modules are connected. Therefore, if you have other PINs, you should change them in the code in the very first line of SerialFlow rd.

The next sketch will allow you to output data from the radio module to the port monitor.

#include
SerialFlow rd(9, 10);
void setup(void){
Serial.begin(57600);
rd.setPacketFormat(2, 1);
rd.begin(0xF0F0F0F0D2LL,0xF0F0F0F0E1LL);
}
void loop(void){
unsigned int v;
if( rd.receivePacket() ){
v = rd.getPacketValue(0);
Serial.println(v);
}
}

If you are watching data through the port monitor, then do not forget to indicate in the lower right the same data transfer rate in it, as in our sketch (in this case, it is 57600 baud).

By the way, the simplest practical scheme for applying this radio module can be an IR remote control, where one device controls another.

Share on facebook
Facebook
Share on google
Google+
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on pinterest
Pinterest