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.

  1. Arduino Due: https://educ8s.tv/part/ArduinoDue
  2. Arduino Mega: https://educ8s.tv/part/ArduinoMega
  3. Arduino Nano: https://educ8s.tv/part/ArduinoNano
  4. 3.2″ TFT display: https://educ8s.tv/part/32TFT
  5. DHT22: https://educ8s.tv/part/DHT22
  6. NRF24L01: https://educ8s.tv/part/NRF24L01
  7. DS3231 RTC: https://educ8s.tv/part/DS3231
  8. Small Breadboard: https://educ8s.tv/part/SmallBreadboard
  9. Wires: https://educ8s.tv/part/Wires
  10. Header Pins: https://educ8s.tv/part/HeaderPins
  11. 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.

Outdoor Sensor

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.

Weather Monitoring Station

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.

Weather Monitor

 

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[