Arduino Wireless Weather Station Project
Hi guys, today we will be building a very interesting Arduino project, a wireless weather station using the ultra fast Arduino Due, a DHT22 temperature and humidity sensor and the NRF24L01 RF Transceiver communication module.
The project is a two part project as we will be building two devices; the monitoring station, and the outdoor sensor. he monitoring station is enabled for wireless communication, it receives weather data from the outdoor sensor and displays it on the attached 3.2″ Color TFT display. The station is built using the fast 32bit Arduino Due, a big 3.2” Color TFT display, DS3231 real time clock, NRF24L01 and a DHT22 temperature and humidity sensor which is used to determine the indoor temperature and humidity. Asides the temperature and humidity from both the outdoor sensor and the DHT22 attached to the weather station, the station also displays the current time and date. The readings of the outdoor sensor are received by the weather station every second in order to show that we have a reliable communication link established between the weather station and the outdoor sensor. The Indoor temperature and humidity from the indoor sensor however, is updated every minute since it is directly connected to the weather station and there is no need to ensure connection.
The transmitter(outdoor sensor) is much simpler. It consists of an Arduino Nano, a DHT22 sensor and the NRF24L01 wireless transceiver module. The device reads the temperature and the humidity every second, and sends them via the NRF24L01 module to the weather station. The communication is a one way link, thus it is impossible to verify if the data was received by the monitoring station or not. I didn’t bother too much about this since its just for learning purpose, but I would have implemented an algorithm (Acknowledgement) to confirm delivery if this was a product to be released to the public.
Required Parts and Where to Buy
The following components/parts are required to build this project and they can be bought via the links in front of them.
- Arduino Due: https://educ8s.tv/part/ArduinoDue
- Arduino Mega: https://educ8s.tv/part/ArduinoMega
- Arduino Nano: https://educ8s.tv/part/ArduinoNano
- 3.2″ TFT display: https://educ8s.tv/part/32TFT
- DHT22: https://educ8s.tv/part/DHT22
- NRF24L01: https://educ8s.tv/part/NRF24L01
- DS3231 RTC: https://educ8s.tv/part/DS3231
- Small Breadboard: https://educ8s.tv/part/SmallBreadboard
- Wires: https://educ8s.tv/part/Wires
- Header Pins: https://educ8s.tv/part/HeaderPins
- Xiaomi Powerbank: https://educ8s.tv/part/Powerbank
Full disclosure: All of the links above are affiliate links. I get a small percentage of each sale they generate. Thank you for your support!
[adsense]The cost of the project is around 40$. You can lower the cost of the project by 5$ if you use the Arduino Mega instead of the Arduino Due. I haven’t tested it, but it should work fine as well but it will be much slower. The speed of the Arduino Due is its major advantage when it comes to this project since it is desired to update the display every seconds and it will take a very fast processor or MCU to do that without the display flickering.
Schematics
We will start by connecting the components for the outdoor sensor (transmitter). Connect the component as shown in the schematics below.
To make the connections easier to follow, here is a description of the pin connections between the Arduino Nano and the other components.
NRF24L01▶ ARDUINO NANO
GND ▶ GND
VCC ▶ 3.3V
CE ▶ D7
CS ▶ D8
SCK ▶ D11
MOSI ▶ D12
MISO ▶ D13
DHT22 ▶ ARDUINO NANO
VCC ▶ VCC
GND ▶ GND
DATA ▶ D4
Go over the connections once to ensure everything is as it should be, and then proceed to connecting the components for the monitoring station as shown in the schematics below. Since the TFT comes as a shield, there is no need getting wire since it is not that difficult.
To make the connections easier, the pin connections between the components and the Arduino Due is described below.
NRF24L01 ▶ ARDUINO DUE
VCC ▶ 3.3V
GND ▶ GND
CE ▶ D6
CS ▶ D7
SCK ▶ 52
MOSI ▶ 51
MISO ▶ 50
DHT22 ▶ ARDUINO DUE
VCC ▶ VCC
GND ▶ GND
DATA ▶ D8
Go over the connections once more to ensure everything is as it should be before proceeding to the next section.
Code
Just like the schematics, we will have two different sketches/firmware for this project. One of the sketches will be for the outdoor sensor(transmitter) while the other one will be for the monitoring station.
To effectively and easily communicate with all the components that will be used to build the two devices, we will be using the following Arduino libraries which can be downloaded from the links in front of them.
LIBRARIES
DISPLAY: https://github.com/Bodmer/TFT_HX8357_Due
NRF24L01: https://github.com/TMRh20/RF24
DHT22: https://github.com/adafruit/DHT-sensor-library
DS3231: https://github.com/SodaqMoja/Sodaq_DS3231
To start with the code for the transmitter, It is almost identical with the code of the NRF24L01 tutorial on this website the only difference being the fact that instead of sending dummy data like was done in that tutorial, we are sending real data that we get from the DHT22 sensor. Please, be sure to use the correct library for the NRF24L01 module. The code starts by including the libraries that we will be using, after which we declare the pins of the Arduino to which our DHT is connected to and create an instance of the RF24 library to serve as reference and enable the NRF module communicate with the Arduino and the other module.
#include "DHT.h" #include <SPI.h> #include "RF24.h" #define DHTPIN 4 #define DHTTYPE DHT22 RF24 myRadio (7, 8); byte addresses[][6] = {"0"}; const int led_pin = 13;
Next, we create the struct package for organizing the data into packets to be sent by the NRF, after which we pass the pin to which the DHT pin is connected and the DHT TYPE as arguments to the DHT
struct package { float temperature ; float humidity ; }; typedef struct package Package; Package data; DHT dht(DHTPIN, DHTTYPE);
After all this is done, we proceed to the void setup() function. Here we initiate serial communication, initialize the DHT module, initialize the NRF module, setting the communication channel, signal power, and the data rate.
void setup() { Serial.begin(9600); pinMode(led_pin, OUTPUT); dht.begin(); myRadio.begin(); myRadio.setChannel(115); myRadio.setPALevel(RF24_PA_MAX); myRadio.setDataRate( RF24_250KBPS ) ; myRadio.openWritingPipe( addresses[0]); delay(1000); }
Next, we move to the void loop() function. Basically, the loop() function reads the values from the sensor and then sends it to the receiver. An LED is turned on and off to show valid transmission.
void loop() { digitalWrite(led_pin, HIGH); // Flash a light to show transmitting readSensor(); Serial.println(data.humidity); Serial.println(data.temperature); myRadio.write(&data, sizeof(data)); digitalWrite(led_pin, LOW); delay(1000); }
That’s all for the transmitter(Outdoor sensor) code.
Next we will examine the code for the Receiver which is the weather monitoring station itself.
The receiver/weather monitoring station, displays both data received from the outdoor sensor and the data generated from its own DHT22(indoor sensor). Since the data is to be displayed on a TFT, We will be adding the TFTLCD library our list of libraries.
After downloading the hotel, we follow the same process as the first one, We include the libraries, declare the pin of the Arduino to which the components are connected and some variables that will be used later on.
#include <Sodaq_DS3231.h> //RTC Library https://github.com/SodaqMoja/Sodaq_DS3231 #include "DHT.h" #include "RF24.h" #define DHTPIN 8 #define DHTTYPE DHT22 DHT dht(DHTPIN, DHTTYPE); RF24 myRadio (6, 7); float remoteHumidity = 0.0; float remoteTemperature = 0.0; String dateString; String hours; int minuteNow=0; int minutePrevious=0; el(RF24_PA_MAX); myRadio.setDataRate( RF24_250KBPS ) ; myRadio.openWritingPipe( addresses[0]); delay(1000);
Next, we create the struct package again, this time to help receive the data that was sent.
struct package { float temperature ; float humidity ; }; typedef struct package Package; Package data;
Next is the void setup() function. We initiate communication with the DHT module and the RTC module. We then initialize the display, setting our preferred orientation for the display, displaying the UI and then start wireless communication
void setup() { Serial.begin(9600); tft.init(); tft.setRotation(1); tft.fillScreen(TFT_BLACK); tft.setTextFont(1); // Select font 1 which is the Adafruit GLCD font delay(100); rtc.begin(); dht.begin(); delay(2000); //setRTCTime(); startWirelessCommunication(); printUI(); }
In the loop() section, we first check for wireless data, then we print the current time, indoor temperature, indoor humidity, remote temperature and remote humidity.
void loop() { checkForWirelessData(); getAndPrintTime(); printIndoorTemperature(); printIndoorHumidity(); printRemoteTemperature(); printRemoteHumidity(); }
That’s it for this section. You can crosscheck to ensure everything is at it should be, before turning on the system.
As usual the code for the two sketches is attached under the download section below.
——————–
CODE OF THE PROJECT
——————–
The functions printIndoorTemperature(), printIndoorHumidity(), printRemoteTemperature(), and printRemoteHumidity() will continuously print the indoor and outdoor readings provided there is a new value else, it remains the same. We read the temperature and the humidity once a minute and we only update the display if there is a change in the values. This way we reduce flickering of the display.
That’s it for this tutorial, thanks for watching and reading. You can show support by dropping comments here and subscribing to our channel on YouTube.
SUBSCRIBE ON YOUTUBE
——————–
Never miss a video: Subscribe to educ8s.tv[
Hi , thank you for sharing this project, I am fairly new to arduino and was looking for a way to send data from the dht22 wirelessly to an arduino uno using nRF24L01+ modules and your code was the closest I could get to the components and the librarys I am using I had to make changes to the code to make it work for me, what I would like to know is how to change from Celcius to Fahrenheit? I would be grateful if you could let me know.
Hello
WARNING: library TFT HX8357 Due claiming to working with architecture [sam] and may be incompatible with your current board working under architecture [avr].
What can i do ??
Same problem here. Did u get it to work? and how?
can you help me with sending heart rate sensor data and temperature sensor data using nrf24l01 modules and display on lcd screen
using arduino uno and mega 2560
please help me and send me codings to
adityabeast3110@gmail.com
Grate Grate project
I’m doing something similar.
I have Arduino pro mini with 1c2 oled display + Nrf24l01 and a x&y joystick.
The main unit is an Arduino mega with a Nrf24l01+ dht22, ds3231, 8 relay module.+sd card (for logging)
I’m reading the humidity and temperatures and displaying them on the remote screen.
I would like to know how to make a menu system on the remote
Say
Main =display current temps
Menu 1 turn on/off relay 1
Menu 2 turn on/off relay 2
And so on.
Thanks in advance.
Michael
I got this working!, thank you very much for the amazing project tutorial. I just did not understand how we are controlling the Indoor sensor to read only every one minute?
Hello Sami, thanks for the comment.
With this line of code: “if(minuteNow!=minutePrevious)” we check it the time has changed in order to print the time. Before printing the time we read the sensor as well
This is a great project and you are a great teacher!
I almost have this finished; I am having trouble with the remote showing on the screen but will recheck all the connections and such next.
I cannot get the clock to show minutes on the screen. The line shows:
Wednesday 24/11/2016 18:
This is all, the minutes never show up and the clock is keeping time as I see the hour just changed to 19, as it should.
This is my first project and I am loving all that I’m learning! Can you please help me with the minute error?
Thank you.
Maybe the date string is too long. Try to remove the 2016 and see what happens.
Jon,
Same thing happened to me when I was building it, I just shortened the day names to Mon,Tue,Wed… instead of Monday,Tuesday, Wednesday and such. worked perfect.
Sami
Good suggestion, I will try that soon. However, I don’t think that is the solution as I already changed the font size down to 1 and I had the same display error, only smaller.
Thanks again, great great project and learning going on.
I have an inverted screen, that being the text is upside down and backwards (mirror). Any suggestions? I also only have about 3/4 of the screen in use for some strange reason.
Hello,
thank you for providing this great project. I built it and it works fine. Now I want to upgrade it with an carbon dioxid sensor and want to bring the data into internet to ThingSpeak.
For the carbon dioxid sensor I found the MQ138.
For the internet-Connection I think a WIFI-module like the ESP8266 would be great. And there I have the first problem. How can I connect this module to this weatherstation project? On this page I found a circuit diagram:
http://arduino-er.blogspot.de/2015/04/connect-esp8266-wifi-module-to-arduino.html
The problem is that the Due Pin 53 is blocked by the TFT display. Does anybody know how I can solve this problem?
Hi I am also getting this error message, what can I do?
“WARNING: library TFT_HX8357_Due-master claims to run on [sam] architecture(s) and may be incompatible with your current board which runs on [avr] architecture(s).”
did anyone ever figure thus out? im having the same problem
Thank you so much, I have watched a few of your videos. I have made this weather station…apart from the RTC as it has not arrived yet! This is the first project I have attempted, I am going to add Pressure sensor (BMP180) to display pressure, Altitude and Relative air density as I need these for my sport. As I learn C I will add more functions to data log and share to my network or Tablet (Cloud) and play with an HMI touch screen too:-)
Thanks for all your work in sharing this knowledge, I’m very excited to start this new journey!!!
i am getting the problem of printing NAN in the display can some one give salutation for this ??????
Hello,
With your help, I finally managed to make the small improvements that I told you about.
However, I would like to make a final improvement.
I would like the change of summer / winter time to be automatic because currently twice a year it is necessary to connect the station to a computer, which is not always easy!
Can you help me to finalize this beautiful Wireless Weather Station.
Unfortunately I do not know how to write the skecth to make this ultimate improvement.
Thanks a lot for your help.
Regards
P.S sory for my very poor English
Hi!
This is a great project, just got it working:)
Even though I have very little experience with Arduino, it was fairly simple thanks to your instruction videos and code. I’m currently working on implementing barometric pressure reading as well.
In the future I would like to expand the weather station with more transmitters, one in each room,
have tried to figure out how to do this myself, but it seems a bit complicated.
It would be fantastic if you could make another video explaining this:)
Again, thanks for a great project!
hi
can we do this wicht a wemos d1
if we can, casn you send me the code. its very interesting
bye
saludos desde vigo spain
Hi
I love your work! Thank you!
I promised my son to build the weather station for his birthday. Since no HX8357 was available anymore, an ili9486 was sent.
Now I have a problem with the code.
Is there a solution for the ili9486 TFT or can you help us further on how to proceed?
Thanks for an answer.
Hello Peter, unfortunately, I do not own a screen like this, so I can’t help you. I will take a look through and if the screen is popular and easy to get, I will make a tutorial about it. Cheers!
Nick,
I received a TFT_320QVT_9341 screen that looks identical to the one you have in your video. Will this display be compatible with your code? Thank you.
Nick
I really have enjoyed your projects. On this I am having problems with the wireless communications. One issue that I have is the sck mosi and miso plug into 50 51 and 52 on Arduino Mega . However this is the connector that my TFT display plugs into! How did you attach the Rf24l01 connections and Tft display as they use the same connector?
Thank you
Thank you very much for your information that has helped a lot.
Hi, Hopefully you are still watching this site for anyone having problems. When I try to verify this sketch i get an error ” My Radio does not name a type”. I have gone through this many times unable to repair the error. Any ideas? Thanks
Jim
I built this and it worked, thanks! My display didn’t work properly…. I didn’t read this until and hour ago: –
If your display does not work correctly, check the User_Setup.h file that comes with the display library Try to use HX8357B driver to see if that works.
I changed it to #define ILI9481 and it worked fine!
I am going to make a modification to the project so the inside display will show the lowest remote temperature.
I’ve made it and it’s working fine.
The display is very bright, and so I had the idea of implementing a PIR sensor to wake the display up only when someone is moving in front of it.
Can you please help me with this? For the sketch alterations and for the PIR sensor connections?
Thanks!
Eduardo
Sir if we using big display like led dot matrix then the code is working or not?
Ordered two displays to work with an Arduino Due. Get a blank (lit up) screen on both. Could both displays be bad? One has a black area on it, the other has a line across the top. The transmitter (using an Arduino Uno) appears to work (getting temp and humidity readings on the serial monitor.). I’ve tried the TFT_HX8357 Due and the TFT-HX 8357 libraries.