title - build a wireless weather station

Build a Simple Wireless Weather Station using the nRF24L01

In this project, we put the nRF24L01 to practice and use it in a weather station to send data wirelessly to a base station that intern displays the results to a PC screen.

 

 

About the nRF24L01 wireless module

In the previous post, we looked at the nrf24L01 module, it’s features and how to easily set it up as a one way wireless link. In this project we build upon that by using this wireless module to transmit weather data back to a base station and display the results.

We start collecting basic temperature, humidity and rainfall readings then let the microcontroller process the results and send them to the nrf24L01 module to transmit to the base station.

 

Now let’s look at the sensors we will be using in this project.

Sensing Temperature and Humidity

I’m using the DHT11 module that incorporates a temperature and humidity sensor in the one unit. It is a very common module but keep in mind the temperature range is limited from 0 – 50°C so if you want to measure temperatures below 0°C, the DHT11 won’t do it. A better choice would be the DHT22 for sub-zero temperatures which can go as low as -40°C and also has a better accuracy than the DHT11.

 

Sensing Rainfall

The rain gauge sensor is a bucket tipping one and is calibrated so that for every bucket tip, 0.8mm is counted so we’ll add 0.8mm to the total rainfall tally every time it is activated.

The sensing mechanism in this rain sensor is a reed switch that is activated by a magnet attached to the side of the tipping bucket that when tipping swings by the reed switch and activates it . In addition to the circuit, a 10k pull up resistor is required when connecting the sensor to the microcontroller to ensure the input does not float and will either be 5V when the sensor is activated or 0V when there is no activity.

 

NRF24L01 Transmitter

Even though the nRF24L01 supports two way communication, I’m going to keep it simple and only use only one way transmission. If data is lost in this situation, it’s not critical. In future projects we’ll look at using two way transmission.

 

NRF24L01 Receiver – Base Station

The Base station is an Arduino Uno (compatible) board that is connected to an NRF24L01 wireless module that is set to receive mode only. When the data is received, it’s displayed on the Serial Monitor tool of the Arduino IDE. The base station does not do any processing of data but just displays data it receives and formats it so it is displayed nicely and also displays the measurement units such as “mm” for rainfall, “C” for temperature and “%” for humidity.

 

Components Required for Wireless Weather Station

 

  • 2 x Arduino uno or compatible boards
  • 2 x nrf24L01 modules
  • Tipping bucket rain gauge sensor
  • DHT11 temperature and humidity sensor
  • 10 resistor
  • Hookup wire
  • breadboard

 

Wireless Weather Station Schematic

 

The circuits are wired up as in this diagrams below.

Receiver (Base Station)

nrf24l01 receiver circuit

 

Transmitter

 

nrf24L01 transmitter circuit

 

 

Coding the Wireless Weather Station

In the code we have several parts all working together. The heart of the system is in the transmitter code that does all the processing and sorting of data and the receiver only outputs and formats the data it receives. We use the RF24 and DHT libraries.

 

NRF24L01 Transmitter Code

Looking at the transmitter we have several sections starting with the data that is sent as a structured data packet, then we have the get_rainfall() function that gets data from the rainfall sensor and finally an if-else section that checks for new measurements and it only transmits data if new results have been gathered.

 

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#include <DHT.h>

#define DHTPIN 5                // do not connect to pin 0 or pin 1
#define DHTTYPE DHT11           // Define DHT11 module
DHT dht(DHTPIN, DHTTYPE);       //create DHT object called dht

float temperature_old = 0;
float humidity_old = 0;
float rainfall_old = 0;

RF24 transmit (2,3);                            //create RF24 object called transmit

byte address [5] = “00001”;                     //set address to 00001
int rain_sensor = 4;                            //set rain sensor to pin 4

struct package
  {
    float temperature = 0;
    float humidity = 0;
    float rainfall = 0;
  };

typedef struct package Package;
Package data;

void setup() {
  dht.begin();
  transmit.begin();
  transmit.openWritingPipe(address);            //open writing pipe to address 00001
  transmit.setPALevel(RF24_PA_MIN);             //set RF power output to minimum
  transmit.setDataRate(RF24_250KBPS);           //set data rate to 250kbps
  transmit.setChannel(100);                               //set frequency to channel 100
  transmit.stopListening();
  digitalWrite(rain_sensor, LOW);               //set pin 4 low
  pinMode(rain_sensor, INPUT);                  //set pin 4 as an input
  }

//********************Function****************************************************
float get_rainfall()                          //get_rainfall function
{
  if (digitalRead(rain_sensor) == HIGH)
          {
           data.rainfall = data.rainfall + 0.8;
          }                 
}

//*********************************************************************************

void loop() {
  get_rainfall();
  data.temperature = dht.readTemperature();
  data.humidity = dht.readHumidity();
 
  if (data.rainfall != rainfall_old)               //check variables for changes and transmit updated data
        {
          transmit.write(&data,sizeof(data));         //transmit the data
        }
        else if (data.temperature != temperature_old)
        {
          transmit.write(&data,sizeof(data));         //transmit the data
        }
        else if (data.humidity != humidity_old)
        {
          transmit.write(&data,sizeof(data));         //transmit the data
        }
 
  temperature_old = data.temperature;         //update temperature_old to new reading
  humidity_old = data.humidity;               //update humidity_old to new reading
  rainfall_old = data.rainfall;               //update rainfall_old to new reading
 
  delay(300);                                 //delay to prevent false rainfall readings

}

 

 

NRF24L01 Receiver Code

 

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

RF24 receive (2,3);                         //create object called receive
byte address [5] = “00001”;                 //create an array with 5 elements, where each element is 1 byte;

struct package
  {
    float temperature = 0;
    float humidity = 0;
    float rainfall = 0;
  };

  typedef struct package Package;
  Package data;

void setup() {
  Serial.begin(9600);
  Serial.print(“Starting Receiver \n”);
  receive.begin();
  receive.openReadingPipe(0,address);      //open reading pipe 0 at address 00001
  receive.setPALevel(RF24_PA_MIN);         //Set RF output to minimum
  receive.setDataRate(RF24_250KBPS);       //set datarate to 250kbps
  receive.setChannel(100);                 //set frequency to channel 100
  receive.startListening();                

  }

void loop() {

  if (receive.available())                //check when received data available
  {
    
    receive.read(&data, sizeof(data));
    Serial.print(data.temperature);                //print data to serial monitor
    Serial.print(” C  “);
    Serial.print(data.humidity);                   //print data to serial monitor
    Serial.print(” %  “);
    Serial.print(data.rainfall);                   //print data to serial monitor
    Serial.print(” mm\n”);
  }

}

 

Build a Simple Wireless Weather Station using the nRF24L01 | Summary

Using the nrf24l01 wireless module can help to expand your projects, as I have done here to create a wireless weather station so I don’t need to worry about installing unsightly long wires and it would cost more as well.

I hope this tutorial has been useful to you.

If you liked it please share it with a Friend !

Subscribe Now !

Receive updates and new information straight to your inbox.