wireless weather station thumbnail

Ultimate Weather Station Build – Using nRF24L01 and Arduino

In this article we build a wireless weather station with some simple sensors to monitor your local weather.

I decided to make my own wireless weather station because I wanted to build a system that could be expanded upon and used to eventually control and monitor my garden and outdoors environment.

Having a remote receiver has made it very easy for me to read my local weather data using the nRF24l01 2.4Ghz wireless module with and Arduino or compatible board and some sensors. So, I’ll stop the talking here and get on with the show !

 

 

Why make a Wireless Weather station ?

There are a few reasons why I’ve built a wireless weather station instead of buying one.

 

  • It’s Fun           If you like making things, this is actually a fun and useful project to build.

 

  • It’s Useful and Practical   –   This project can be used to monitor weather conditions in your very own backyard, you can’t get more local than that. Later on you can use this weather data to monitor conditions for your gardens and with additional sensors monitor such things as soil moister and rainfall then feed this data back to an irrigation controller that you could also build, where you’ll learn not only about electronics and microcontrollers but also about weather parameters.

 

  • It’s Highly Customizable – As a maker, you have complete control over your whole system, what sensors you add, how the data is stored, viewed and manipulated.

 

Now that you’ve got an idea of why you would make your own wireless weather station, the next question that you’d probably ask is:

 

How would you build a Wireless Weather Station ?

 

wireless weather station block diagram

 

We’ll get into the specific components and coding a little further down in this article, but first I’ll outline all the major components that we’ll use in this wireless weather station.

Because the systems is wireless, we’ll need two wireless transceiver modules. We’ll keep it simple and use a one way wireless link, so one of the wireless modules is setup as a transmitter and the other as a receiver.

One microcontroller has sensors connected to it and intern processes the sensor data, packages it up in a neat little data packet then sends this data packet to the transmitter, the transmitter then transmits the data packet which is then received by the receiving unit.

At the receiving unit, the receiver module parses the data packet to a microcontoller that decodes the data packet and places the data into variables that we then display on some sort or display, be it PC monitor or a stand alone LCD Display. Don’t get too worried about the data packets and decoding as this is actually very simple.

 

Why use the nRF24L01 wireless module

I chose this module because it is commonly available, cheap, easy to use with the RF24 library and is packet with useful features.

I’ve covered this setup before in a previous article that I’ve linked to below with other relevant articles:

 

How to Setup and use the nRF24L01 in your projects

 

What Wireless Module to Use ?

 

How to Build an nRF24L01 Adapter

 

The nRF24L01 wireless module operates on the 2.4GHz ISM band, it has a selectable RF power output as well as a selectable data rate from 250kbps up to 2Mbps, where we’ll use the lowest data rate of 250kbps which is more than enough for this project. You can also select from 126 channels to prevent interference from nearby transmitters operation on the same band.


What Temperature Sensor to Choose ?

 

The temperature sensor we are using is the DHT11 which measures temperature and humidity. The DHT11 only measures as low as 0 degrees celcius, so if you require to measure below this temperature you’ll need to use another module like the DHT22 which is more expensive.

Further down, we’ll show you how to make the housing for the temperature sensor which helps to protect it from the weather and water at the same time allows air to flow through to the sensor be able to  measure temperature and humidity.

 

Build a Temperature Sensor Protector Casing

 dht11 protective housing

The DHT11 sensor casing is simply a plastic box with holes drilled all around the side to allow air to freely flow. The sensor is mounted on a PCB and is mounted towards the top of the box so that if water gets in or condenses in the box it should not get wet. Keep reading because further down you can find out how the transmitter box is attached to the main transmitter casing.

 

How to Setup the Receiver

The components required a 16×2 LCD display, Arduino Uno or compatible board, and nRF24L01 wireless module, some hook up wire and breadboard.

Now we’ll wire up the receiver by following this wiring diagram.

 

receiver wiring

 

Upload Code to the Circuit

 

Once the receiver circuit is built we upload the code. The code is written as simple as possible to help you understand how it works.

 

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

RF24 receive (2,3);                        
byte address [5] = “00001”;               
LiquidCrystal lcd(8,9,4,5,6,7);

int output_pin10 = 10;
int contrast = 75;

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

typedef struct package Package;
Package data;

void setup() {
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print(“Now Receiving”);
  pinMode(output_pin10, OUTPUT);
  analogWrite(output_pin10, contrast);
  receive.begin();
  receive.openReadingPipe(0,address);     
  receive.setPALevel(RF24_PA_MIN);       
  receive.setDataRate(RF24_250KBPS);     
  receive.setChannel(100);               
  receive.startListening();                
  }

void loop() {

  if (receive.available())                //check when received data available
  {
    receive.read(&data, sizeof(data));
    lcd.setCursor(0,1);
    lcd.print(data.temperature);
    lcd.print(“C  “);
    lcd.print(data.humidity);
    lcd.print(“%”);
    
  }
}

 

Receiver Code Explained

First we declare the libraries we are using:

  • RF24.h
  • LiquidCrystal.h

 

We then declare objects of the RF24 and LiquidCrystal libraries.

Then we setup a data structure object. This data structure is identical to the data structure the transmitter uses.

The LCD contrast requires a voltage between 0 – 5 volts, which is usually done using a variable resistor. To avoid using a variable resister we’ve used the pulse width modulator function and  output it to pin 10, then we can set the contrast using code instead of external components.

Next we setup the LCD, then the contrast pulse width modulator output.

Then we setup the wireless module parameters such as channel, datarate and address.

Finally in the main loop we read from the receiver when ever data is available using an if statement then print the temperature and humidity data to the LCD display once data is received.

 

What Components are Required for the Transmitter Circuit?

Now for the transmitter we we also need several commonly available components so this weather station can happen.

For the transmitter section we need need the following components:

 

  • Arduino Uno (or compatible Board)
  • nRF24L01 wireless module
  • hookup wire
  • DHT11 digital temperature and humidity sensor

 

We then put the circuit together as in this wiring diagram below:

 

transmitter wiring

 

 

What Code to Use in the Transmitter Microcontroller ?

 

Next we’ll load the following code in to the Arduino board that is connected to the transmitter module.

 

#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

RF24 transmit (2,3);                            //create RF24 object called transmit
byte address [5] = “00001”;                     //set address to 00001

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_MAX);             //set RF power output to maximum
  transmit.setDataRate(RF24_250KBPS);           //set datarate to 250kbps
  transmit.setChannel(100);                     //set frequency to channel 100
  transmit.stopListening();
  }

void loop() {
  data.temperature = dht.readTemperature();
  data.humidity = dht.readHumidity();
  transmit.write(&data,sizeof(data));
  delay(1000);                                 
}

 

Transmitter Code Explained

We need the following libraries:

  • RF24.h
  • DHT11.h

 

Next we’ll setup a data structure to store the weather data in. We have variables for:

  • temperature
  • humidity

 

The folowing parameters are set for the nRF24L01 to operate:

  • RF power set to maximum
  • Channel 100
  • Datarate of 250 kbps
  • Address 00001

 

The DHT11 sensor data is collected using pin 5.

The temperature and humidity data is transmitted once per second.

 

 

Transmitter Weather Proof Casing

transmitter case

Now we’ll fit the transmitter to a box that is weather proof. The box we are using is a weather proof box that has a seal under the lid.

The transmitter components are fitted to the backplate by using nylon risers. The use of the risers prevents the circuit boards from touching the metal back plate and shorting out.

On the bottom of the box a cable gland has been fitted to allow wiring from other sensor to enter the box and keep it sealed. We won’t use this cable gland in this video as it has been placed there to be able to expand the system at some later stage.

The DHT11 housing is held on the box by two small bolts and a hole has been drilled to allow the sensor wires to enter the main box to connect the microcontroller board.

 

The last thing to do is install the back plate with the transmitter circuitry. This is done by carefully placing the backplate into the box then securing it to the inside of the box with 4 mounting screws.

The very last thing is to power up the transmitter with some type of power source. Here I’ve used a mini powerbank which which should last for quite a few hours, but this is just a temporary solution to show that the system works. Ideally a the transmitter could be powered by solar power and battery storage, but we’ll leave this for another time.

Does the Weather Station Work ?

 Now that all has been completed we can test the whole system by turning on the receiver first, then turn on the transmitter. If all is working the temperature and humidity data should start being displayed on the LCD, then updated once every second.

lcd temperature and humidity display

Ultimate Weather Station Build – Using nRF24L01 and Arduino | Summary

 

There you have it, a DIY weather station which is simple and fun and you’ll learn microcontroller electronics and programming along the way.

Did you get something valuable from today’s article ? If so then make sure you Subscribe to the Smart Microcontroller email list Right Now! by entering you email into the email box below and clicking the Subscribe button.  That way you won’t miss out any useful articles like this one !

Also if you want exclusive information or my newsletter that I only share with subscribers, then also signup for the newsletter.  It’s Free !

 

Subscribe Now !

Receive updates, new information and our newsletter exclusive to subscribers only, straight to your inbox.


 

 

 

Now I want to turn it over to you, what did you think about building a wireless weather station or maybe you have a question about the components or code ? Either way leave a quick comment on one of my social media profiles at the top of the page.