Arduino Uno with nRF24L01- Send and Receive Temperature and Humidity Data Wirelessly

nRF24L01 Arduino UNO Wireless Communication

There are various wireless communication technologies used in building IoT applications and RF (Radio Frequency) is one of them. nRF24L01 is a single-chip radio transceiver module that operates on 2.4 - 2.5 GHz (ISM band). This transceiver module consists of a fully integrated frequency synthesizer, a power amplifier, a crystal oscillator, a demodulator, a modulator, and Enhanced ShockBurs protocol engine. Output power, frequency channels, and protocol setup are easily programmable through an SPI interface.

 

The operating voltage range of this Transceiver module is 1.9V to 3.6V. It has Built-in Power Down and Standby modes that make it power-saving and easily realizable.

We previously used nRF24L01 with Arduino to build a Gesture controlled Robot, here we will simply interface nRF24L01 with Arduino Uno to send and receive temperature & humidity data wirelessly from the DHT11 sensor.

 

Arduino Uno doesn’t have any inbuilt wireless communication support like Bluetooth or Wi-Fi, but it can be easily interfaced with other Wi-Fi or wireless modules like LoRa, nRF, Bluetooth and can be used to build IoT based Applications. Here we have used Arduino with ESP8266, with LoRa, with 433 MHz RF Module, with nRF24L01 module and with Bluetooth to establish wireless communication for IoT projects. We have also built few IoT based Weather stations using the DHT11 sensor.

 

Components Required

  • Arduino Uno (2)
  • nRF24L01 (2)
  • 16*2 LCD
  • LCD I2C Module
  • DHT11 Sensor

 

NRF24L01 Transceiver Module Circuit diagram

The circuit diagrams for Arduino nRF24L01 based transmitter and receiver are given below. Here, we are sending the temperature and humidity values wirelessly from one Arduino to another using the nRF24L01 module. To get the temperature and humidity values, we are using the DHT11 sensor that is connected to the transmitting side Arduino. Transmitting Arduino will get temperature and humidity values from DHT11 and then sends it to another Arduino via the nRF24L01 module. These humidity and temperature values will be displayed on 16*2 LCD connected to the receiver side, Arduino.

 

Interfacing nRF24L01 with Arduino UNO - Transmitting Side

The transmitter side consists of an Arduino UNO, nRF24L01 module, and DHT11 sensor. Interfacing of the Arduino UNO with nRF24L01 and DHT11 is shown below. Arduino continuously gets data from the DHT11 sensor and sends it to the nRF24L01 Transmitter. Then the nRF transmitter transmits the data into the environment.

nRF24L01 with Arduino UNO Circuit Diagram

Arduino nRF24L01 Based Sender

 

nRF24L01

Arduino Uno

VCC

3.3V

GND

GND

CE

Pin 9

CSN

Pin10

SCK

Pin 13

MOSI

11

MISO

12

DHT11

Arduino Uno

VCC

5V

GND

GND

DATA

3

 

Interfacing nRF24L01 with Arduino UNO - Receiving Side

The receiver side consists of an Arduino UNO, nRF24L01 module, and 16*2 LCD module. The receiver side nRF module receives the data from the transmitter and sends it to Arduino. Interfacing of the Arduino with nRF24L01 and LCD module is shown below.

nRF24L01 Arduino UNO Based Receiver Circuit Diagram

Arduino nRF24L01 Based Receiver

nRF24L01

Arduino Uno

VCC

3.3V

GND

GND

CE

Pin 9

CSN

Pin10

SCK

Pin 13

MOSI

11

MISO

12

LCD With I2C Module

Arduino Uno

VCC

5V

GND

GND

SCL

A5

SDA

A4

 

nRF24L01 with Arduino UNO Programming - Transmitter and Receiver Side

To use the nRF24L01 transceiver module with Arduino, first install the nRF24L01 library. Here two nRF24L01 modules are used as transmitter and receiver, so we have to write two separate codes for transmitter and receiver. Both the programs are the same except for the transmitting and receiving options. In the transmitter side program, the receiver option will be commented out, and in the receiver side program, the transmitter option will be commented out.

Check the complete program for nRF24L01 Arduino Uno Transmitter and Receiver have given at the end of this document.

First of all, including all the required library files. SPI library is used for SPI communication between nRF24L01 and Arduino, and the DHT11 library is used to calculate the temperature and humidity values.

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include "DHT.h"

 

Then define the Radio pipe addresses for the communication and nRF transmitter’s CN and CSN pins.

const uint64_t pipeOut = 0xE8E8F0F0E1LL;
RF24 radio(9, 10);

 

After that, we declared temperature and humidity variables as a composite variable structure. In this program, h & t is used to send and receive data from the RF module.

struct MyData {
  byte h;
  byte t;
};

 

Inside the void setup function, we initialize the RF module data rate to a minimum of 250 Kbps.

void setup()
{
  Serial.begin(9600);
  dht.begin();
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(pipeOut);
}

 

Inside the void loop function, read the temperature and humidity data from the DHT11 sensor and save this data into data.t and data.h variables.

data.h = dht.readHumidity();
data.t = dht.readTemperature();
Function radio.write reads the data and then puts it in a variable.
radio.write(&data, sizeof(MyData));

 

On the receiver side program, the void recvData function is used to receive the transmitted data.

void recvData()
{
  if ( radio.available() ) {
    radio.read(&data, sizeof(MyData));
    }

 

nRF24L01 Arduino Sender and Receiver Testing

Once the hardware and program are ready, upload both nRF24L01 transmitter and receiver codes in both Arduino modules. The transmitter module will send the temperature and humidity values to Receiver Module. And the receiver module will display it on its 16x2 LCD as shown below

nRF24L01 Arduino Sender and Receiver

This is how you can use nRF24L01 as a wireless communication medium between two Arduinos. The complete working video of this project is given below.

 

Code

Transmitter Side

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include "DHT.h"
const uint64_t pipeOut = 0xE8E8F0F0E1LL; 
#define DHTPIN 3
#define DHTTYPE DHT11 
DHT dht(DHTPIN, DHTTYPE);
RF24 radio(9, 10); //  CN and CSN  pins of nrf
struct MyData {
  byte h;
  byte t;
};
MyData data;
void setup()
{
  Serial.begin(9600); 
  dht.begin();
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(pipeOut);
}
void loop()
{
  data.h = dht.readHumidity();
  data.t = dht.readTemperature();
  if (isnan(data.h) || isnan(data.t)){
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
  Serial.print("Humidity: ");
  Serial.print(data.h);
  Serial.print("Temperature: ");
  Serial.print(data.t);
  radio.write(&data, sizeof(MyData));
}

 

Receiver Side

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const uint64_t pipeIn = 0xE8E8F0F0E1LL; 
RF24 radio(9, 10);
struct MyData {
  byte h; 
  byte t;
};
MyData data;
void setup()
{
  Serial.begin(9600); 
  radio.begin();
  lcd.begin();
  lcd.home();
  lcd.backlight();
  lcd.clear();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.openReadingPipe(1, pipeIn);
  radio.startListening();
  //lcd.println("Receiver ");
}
void recvData()
{
  if ( radio.available() ) {
    radio.read(&data, sizeof(MyData));
    }
}
void loop()
{
  recvData();
  Serial.print("Humidity: ");
  Serial.print(data.h);
  lcd.setCursor(0,0);
  lcd.print("Humidity:"); 
  lcd.print(data.h);
  lcd.print("%");
  lcd.setCursor(0,1);
  Serial.print("Temperature: ");
  Serial.print(data.t);
  lcd.print("Temperature:");
  lcd.print(data.t);
  lcd.print(" C");  
  //Serial.print("\n");
}

Video

21 Comments

If i was looking to get the data read directly to the serial monitor on the arduino ide would the code for the receiver be much different, I eventually want the receiver connected to the cloud and view my data there but only learning so baby steps

nice project, nice code. after copying the code directly and wiring the the project, there is data generated on the transmit site but nothing coming across to the receive side. I have spent hours and gone wire by wire and even changed RF24L01 module to no avail. I am out of ides and would appreciate input

only problem i had was with the lcd code, managed to get it going and working.
Would this work better with the DHT22 because the DHT11 which I know is not as good seems to run slow.
Also when i have disconnected the power from the transmitter side, i seem to lose signal until I do a reset.
When it comes to running this as a stand alone project in the real world, is there any way to make them connect without the reset?

Very useful, thank you sir.
If I want to use 2 Nrf24L01 (transmitter) with 1 Nrf24L01(receiver),
how can I set up the channel or address?
Could you make a example ?
That will be a big help to me.

Hello, I encountered this error in the implementation of this project, please help.

:
sketch_aug09b:8:1: error: 'DHT' does not name a type
DHT dht(DHTPIN, DHTTYPE);
^~~
C:\Users\javan\AppData\Local\Temp\arduino_modified_sketch_473151\sketch_aug09b.ino: In function 'void setup()':
sketch_aug09b:18:3: error: 'dht' was not declared in this scope
dht.begin();
^~~
C:\Users\javan\AppData\Local\Temp\arduino_modified_sketch_473151\sketch_aug09b.ino:18:3: note: suggested alternative: 'data'
dht.begin();
^~~
data
C:\Users\javan\AppData\Local\Temp\arduino_modified_sketch_473151\sketch_aug09b.ino: In function 'void loop()':
sketch_aug09b:26:12: error: 'dht' was not declared in this scope
data.h = dht.readHumidity();
^~~
C:\Users\javan\AppData\Local\Temp\arduino_modified_sketch_473151\sketch_aug09b.ino:26:12: note: suggested alternative: 'data'
data.h = dht.readHumidity();
^~~
data
Multiple libraries were found for "nRF24L01.h"
Used: C:\Users\javan\Documents\Arduino\libraries\nRF24-RF24-7c3d6ec
Not used: C:\Users\javan\Documents\Arduino\libraries\NRFLite
Not used: C:\Users\javan\Documents\Arduino\libraries\RF24
Not used: C:\Users\javan\Documents\Arduino\libraries\RF24-master
Multiple libraries were found for "DHT.h"
Used: C:\Users\javan\Documents\Arduino\libraries\DHT-sensor-library-master
Not used: C:\Users\javan\Documents\Arduino\libraries\Grove_Temperature_And_Humidity_Sensor
Not used: C:\Users\javan\Documents\Arduino\libraries\DHT_sensor_library
exit status 1
'DHT' does not name a type

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Hello, I encountered this error in the implementation of this project, please help.

:
sketch_aug09b:8:1: error: 'DHT' does not name a type
DHT dht(DHTPIN, DHTTYPE);
^~~
C:\Users\javan\AppData\Local\Temp\arduino_modified_sketch_473151\sketch_aug09b.ino: In function 'void setup()':
sketch_aug09b:18:3: error: 'dht' was not declared in this scope
dht.begin();
^~~
C:\Users\javan\AppData\Local\Temp\arduino_modified_sketch_473151\sketch_aug09b.ino:18:3: note: suggested alternative: 'data'
dht.begin();
^~~
data
C:\Users\javan\AppData\Local\Temp\arduino_modified_sketch_473151\sketch_aug09b.ino: In function 'void loop()':
sketch_aug09b:26:12: error: 'dht' was not declared in this scope
data.h = dht.readHumidity();
^~~
C:\Users\javan\AppData\Local\Temp\arduino_modified_sketch_473151\sketch_aug09b.ino:26:12: note: suggested alternative: 'data'
data.h = dht.readHumidity();
^~~
data
Multiple libraries were found for "nRF24L01.h"
Used: C:\Users\javan\Documents\Arduino\libraries\nRF24-RF24-7c3d6ec
Not used: C:\Users\javan\Documents\Arduino\libraries\NRFLite
Not used: C:\Users\javan\Documents\Arduino\libraries\RF24
Not used: C:\Users\javan\Documents\Arduino\libraries\RF24-master
Multiple libraries were found for "DHT.h"
Used: C:\Users\javan\Documents\Arduino\libraries\DHT-sensor-library-master
Not used: C:\Users\javan\Documents\Arduino\libraries\Grove_Temperature_And_Humidity_Sensor
Not used: C:\Users\javan\Documents\Arduino\libraries\DHT_sensor_library
exit status 1
'DHT' does not name a type

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I precisely needed to thank you so much again. I am not sure the things I might have gone through without those thoughts provided by you directly on this subject matter. Completely was a very alarming difficulty for me, but being able to view a new skilled form you resolved it took me to jump with delight. I'm just happy for this service and even have high hopes you are aware of a powerful job your are undertaking instructing the mediocre ones by way of your webblog. Probably you have never come across all of us.

I and also my guys came reading the best techniques found on the blog and so immediately developed an awful feeling I had not expressed respect to the web site owner for those tips. The young boys appeared to be absolutely joyful to read all of them and already have seriously been tapping into them. Appreciation for simply being very accommodating and also for getting this kind of brilliant things most people are really desperate to be aware of. My very own sincere regret for not expressing gratitude to you sooner.

I'm just commenting to make you be aware of of the nice discovery my wife's girl had checking yuor web blog. She picked up such a lot of issues, which include how it is like to have an amazing teaching heart to make a number of people without difficulty fully understand chosen tricky subject matter. You undoubtedly exceeded people's desires. Thank you for displaying those practical, safe, educational and in addition unique thoughts on that topic to Evelyn.

I am glad for commenting to let you know of the incredible discovery my girl undergone going through your webblog. She noticed some issues, including what it's like to possess an awesome coaching style to have certain people easily completely grasp chosen complicated issues. You truly surpassed visitors' expectations. Many thanks for showing such precious, trusted, informative and in addition unique tips about that topic to Janet.

I wish to convey my love for your kindness giving support to those who actually need guidance on this particular topic. Your real dedication to getting the solution all-around turned out to be unbelievably useful and have continually encouraged others much like me to reach their desired goals. Your amazing warm and friendly report indicates so much to me and extremely more to my fellow workers. Warm regards; from everyone of us.

I am commenting to let you be aware of of the useful discovery my girl found reading your blog. She discovered a wide variety of things, most notably how it is like to possess a very effective giving character to make many more with no trouble master a variety of advanced topics. You actually exceeded her desires. Thanks for showing such effective, dependable, explanatory as well as cool guidance on this topic to Sandra.

Thank you a lot for giving everyone an extraordinarily terrific opportunity to read in detail from this website. It is often very enjoyable and as well , stuffed with a good time for me personally and my office co-workers to visit the blog really 3 times a week to read through the fresh stuff you will have. Not to mention, I'm also always contented for the astounding strategies you serve. Some 1 points in this posting are undeniably the finest we have ever had.

I together with my pals appeared to be checking out the best strategies found on your website while all of the sudden I had a terrible feeling I never thanked the website owner for those techniques. The men ended up absolutely thrilled to study all of them and have now sincerely been taking pleasure in these things. Thank you for indeed being really thoughtful as well as for choosing some ideal subjects most people are really wanting to be aware of. Our own sincere regret for not saying thanks to sooner.

I simply wished to say thanks again. I do not know the things I might have done in the absence of the type of basics documented by you directly on such a situation. It had become a very frightful difficulty in my position, but discovering your professional manner you dealt with that took me to cry with delight. I'm grateful for this help and thus hope that you comprehend what a great job that you're putting in training men and women via your web blog. Most probably you have never encountered all of us.

I would like to voice my admiration for your kindness in support of men and women who have the need for help on in this area of interest. Your very own dedication to passing the solution along has been incredibly beneficial and have continuously permitted girls like me to attain their endeavors. This informative publication denotes this much to me and additionally to my mates. Thanks a lot; from each one of us.

I am commenting to let you be aware of of the beneficial experience my child obtained browsing your web page. She came to find lots of issues, which included how it is like to have a wonderful helping character to let many people without difficulty fully understand a number of advanced topics. You really did more than people's expectations. Thanks for churning out those important, safe, informative and cool thoughts on this topic to Emily.

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.