In this tutorial to learn sending and receiving random data from NRF24L01 Wireless Transceiver using Arduino nano. we will learn how to make Radio Frequency wireless communication using the nRF24L01+PA transceiver module is designed to operate in 2.4 GHz worldwide ISM frequency band and uses GFSK modulation for data transmission. The data transfer rate can be one of 250kbps, 1Mbps and 2Mbps. The NRF24L01 module is a low-cost ultra-low power, bi-directional transceiver module. The module can achieve data rates as high as 2Mbits! and uses a high-speed SPI interface in order to communicate with the Arduino and IOT.
Components required
Transmitter:
Arduino Nano - 1 no
LCD1602 with I²C - 1no
nRF24L01+PA- 1no
3.3V breakup module -1no
Receiver:
Arduino Nano - 1 no
LCD1602 with I²C - 1no
nRF24L01+PA- 1no
3.3V breakup module -1no
Circuit diagram
The diagram shows the detail connections of NRF24L01module with Arduino.
Connect VCC of NRF24L01 module to Arduino Nano’s 3V3 pin
Connect GND of NRF24L01 module to Arduino Nano’s GND pin
Connect CE of NRF24L01 module to Arduino Nano’s Digital Pin 7
Connect CSN of NRF24L01 module to Arduino Nano’s Digital Pin 8
Connect SCK of NRF24L01 module to Arduino Nano’s Digital Pin 13
Connect MOS of NRF24L01 module to Arduino Nano’s Digital Pin 11
Connect MISO of NRF24L01 module to Arduino Nano’s Digital 12
NRF24L01 Wireless RF Module
Refer blog for more detail: https://www.dofbot.com/post/nrf24l01-wireless-temperature-monitor-with-bluetooth
Transmitter Circuit:
The transmitter circuit side consists of an Arduino Nano, nRF24L01+PA module and 1602 LCD with I2C module. Arduino generate random data and sends it to the nRF24L01 Transmitter. Then the nRF transmitter circuit transmits the data into the air.
Receiver Circuit:
The receiver circuit side consists of an Arduino Nano, nRF24L01+PA module and 1602 LCD with I2C module. The nRF module receives the random data from the transmitter and sends it to LCD display through Arduino.
Installing Library
NRF24L01: you need to Download and install the RF library.
LiquidCrystal_I2C.h : you need to Download and install the LiquidCrystal_I2C library.
Follow the next steps to install those libraries.
In your Arduino IDE, to install the libraries go to Sketch > Include Library > Add .ZIP library… and select the library you’ve just downloaded.
After installing the required libraries, copy the following code to your Arduino IDE.
Arduino Code
Transmitter Code
#include "nRF24L01.h" //NRF24L01 library created by TMRh20 https://github.com/TMRh20/RF24
#include "RF24.h"
#include "SPI.h"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x3F for a 16 chars and 2 line display
int SentMessage[1] = {000}; // Used to store value before being sent through the NRF24L01
RF24 radio(7, 8); // NRF24L01 used SPI pins + Pin 9 and 10 on the NANO
const byte address[6] = "00001";
void setup(void) {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Initializing");
lcd.setCursor(0, 1);
lcd.print("Transmitter");
delay(2000);
radio.begin(); // Start the NRF24L01
// Max power
radio.setPALevel( RF24_PA_MAX ) ;
// Min speed (for better range I presume)
radio.setDataRate( RF24_250KBPS ) ;
// 8 bits CRC
radio.setCRCLength( RF24_CRC_8 ) ;
// increase the delay between retries & # of retries
radio.setRetries(15, 15);
radio.setAutoAck(false);
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop(void) {
int num ;
num = random(0, 100);
SentMessage[0] = num;
DataToLcd((String) SentMessage[0], 0);
radio.write(SentMessage, 1); // Send value through NRF24L01
delay(1000);
}
void DataToLcd(String message1, int delayValue) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("NRF Transmitter");
lcd.setCursor(0, 1);
lcd.print("Sending data:");
lcd.setCursor(13, 1);
lcd.print(message1);
delay(delayValue);
}
Receiver Code
#include "nRF24L01.h" //NRF24L01 library created by TMRh20 https://github.com/TMRh20/RF24
#include "RF24.h"
#include "SPI.h"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x3F for a 16 chars and 2 line display
int SentMessage[1] = {000}; // Used to store value before being sent through the NRF24L01
RF24 radio(7, 8); // NRF24L01 used SPI pins + Pin 9 and 10 on the NANO
const byte address[6] = "00001";
void setup(void) {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Initializing");
lcd.setCursor(0, 1);
lcd.print("Transmitter");
delay(2000);
radio.begin(); // Start the NRF24L01
// Max power
radio.setPALevel( RF24_PA_MAX ) ;
// Min speed (for better range I presume)
radio.setDataRate( RF24_250KBPS ) ;
// 8 bits CRC
radio.setCRCLength( RF24_CRC_8 ) ;
// increase the delay between retries & # of retries
radio.setRetries(15, 15);
radio.setAutoAck(false);
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop(void) {
int num ;
num = random(0, 100);
SentMessage[0] = num;
DataToLcd((String) SentMessage[0], 0);
radio.write(SentMessage, 1); // Send value through NRF24L01
delay(1000);
}
void DataToLcd(String message1, int delayValue) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("NRF Transmitter");
lcd.setCursor(0, 1);
lcd.print("Sending data:");
lcd.setCursor(13, 1);
lcd.print(message1);
delay(delayValue);
}
Demo
Code description
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.
RF24 radio(7, 8); // CE, CSN
Next we need to create a byte array which will represent the address, or the so called pipe through which the two modules will communicate.
const byte address[6] = "00001";
We can change the value of this address to any 5 letter string and this enables to choose to which receiver we will talk, so in our case we will have the same address at both the receiver and the transmitter.
Comments