In this post we are going to construct an IoT based weather monitor system using Arduino which can report us weather status like atmospheric pressure, temperature, humidity, air quality, light intensity etc. of your locality in real time and the data from the sensors are logged to an IoT cloud service called Thingspeak for monitoring and analysis.
We will see:
- What is IoT based weather monitoring system?
- Why we need an IoT based weather monitoring system.
- Types of sensors involved in weather monitoring.
- Block diagram of IoT based weather monitoring system.
- Circuit diagram and description.
- How to setup your Thingspeak account?
- Program code for Arduino and ESP8266.
- How to upload data to generic ESP8266?
- Prototype images.
- How to operate the circuit?
What is an IoT based weather monitoring system?
It is a system that involves in acquiring weather and environment data using advanced electronic sensors and sending them to a web server via internet for real time weather monitoring and storage of data for future analysis and study.
Why we need an IoT based weather monitoring system?
- Ease of monitoring your local weather conditions in real time from anywhere in the world.
- For storing weather and environment data for short and long term for studying weather pattern changes and to understand how human induced climate change affected your local weather.
- Easy deployment of the setup for monitoring local atmospheric conditions and microclimates for weather forecasting and prediction.
Types of sensors involved in weather monitoring:
We can find wide spectrum of electronic sensors involved in weather monitoring system depending on the kind of application.
Farmers need to know the temperature, relative humidity, soil moisture, rain fall etc. to enhance their crop production and the following type of sensors are utilized to obtain the data:
- Temperature sensor.
- Humidity / hygrometer sensor.
- Soil moisture sensor.
- Rain sensor etc.
For an airplane pilot he/she needs to know wind speed, wind direction, atmospheric pressure, precipitation, visibility etc. before they takeoff and they use the following sensors:
- Barometric sensor – for measuring atmospheric pressure.
- Anemometer – for measuring wind speed.
- Rain sensor.
- Visibility sensor – for measuring visibility during snow, rain, storm etc.
In conclusion, the sensors used for monitoring weather depends on the type application we going to deploy for.
Block diagram of IoT based weather monitoring system:
We are going to develop the weather monitoring system using the above illustrated blocks. The brain of the project is an Arduino board and the surrounding blocks are digital and analog sensors for acquiring local weather and environment data.
A generic ESP8266 is used for interfacing the circuit setup with internet via 2.4 GHz Wi-Fi band. The ESP8266 sends the sensor data to a cloud server where the data gets updated in real time and also gets stored for future analysis. We are utilizing a 16 x 2 LCD display to showcase the sensor data, so that we can observe real-time data locally.
Full circuit diagram for IoT based weather monitoring system:
The above circuit consists of the following modules:
- 5V / 3.3V Power supply regulator.
- Arduino Uno.
- 16 x 2 display with I2C adapter module.
- DHT11 temperature & humidity sensor.
- MQ-135 sensor air quality sensor.
- BMP180 – Barometric sensor.
- Light depend resistor (LDR).
- Generic ESP8266 Wi-Fi module.
Now, let’s explore what each of the module does and how it is interfaced with other modules.
Power supply 5V and 3.3V:
The above illustrated module takes 9V to 12V DC supply from a wall adapter and converts to 5V and 3.3V for providing power to Arduino board and sensors.
There are multiple 5V and 3.3V supply outputs in this module and you need to connect 5V supply to 5V sensor modules and 3.3V supply to 3.3V sensor modules. Mismatching will lead to malfunction of the respective modules / sensors.
A button is provided on the module to turn ON/OFF the 5V / 3.3V output. A green LED indicates that the module is powered ON. There is also a USB power output but we won’t be using it for this project.
16 x 2 LCD display:
We are utilizing a 16 x 2 LCD display to showcase sensor data locally and it can display 16 alphanumeric characters in 2 rows.
An I2C display module is used in this project to reduce the number of wires that connect from microcontroller to LCD display to four; otherwise we need to connect 16 wires.
I2C display module operates on I2C bus and has the following four pins:
- SDA – Serial data.
- SCL – Serial clock.
- Vcc – 5V.
- GND – ground.
The Vcc pin connects to 5V of the power supply module and GND connects to GND of the supply, the SDA connects to A4 of Arduino and SCL connects to A5.
The I2C module has backlight control, by removing the jumper we can turn off the backlight and vice-versa. You can adjust the display contrast by rotating the potentiometer (blue color on the module) using a small screw driver.
DHT11 temperature and humidity module:
DHT11 is a digital sensor responsible for collecting temperature and humidity data from your surroundings. It has three terminals namely:
Vcc connects to 5V supply, GND connects to GND and data pin connects to A0 of Arduino.
Note: The pin diagram for DHT11 module could differ from manufacture to manufacture and it is recommended to take a good look at your module to see which pins are Vcc, GND and Data before you apply power to the circuit.
BMP180 barometric sensor:
The above illustrated module is a barometric sensor which is capable of measuring atmospheric data; it can give out data like, atmospheric pressure at ground level, atmospheric pressure at sea level and altitude.
We will be only extracting atmospheric pressure data at ground and sea level to display it on the LCD, but we will be sending only the atmospheric pressure data at ground level to Thingspeak server, which is the relevant data for your locality.
It has the following pins:
- SDA – Serial data.
- SCL – Serial clock.
- Vcc – 3.3V.
- GND – ground.
Care must be taken while connecting the supply to this module as it operates on 3.3V DC and 5V will kill the module. It operates on I2C bus, same as I2C display adapter module.
MQ-135 air quality sensor module:
MQ-135 is an analog air quality sensor which takes air samples from your surroundings and gives out an analog voltage at its output terminal. MQ-135 can detect the following gases:
- Smoke, CO2 etc.
The operating voltage of MQ-135 is 5V and consumes around 160mA, the sensor has built-in heater for heating the sensor for its normal operation and if the sensor is exposed to strong wind we may get incorrect readings. The sensor takes typically around 3 to 5 minutes to reach optimum temperature depending on surrounding air flow.
The sensor has good sensitivity to detect the above mentioned gases, but the disadvantage is it cannot differentiate which gas or gases have been detected.
Generic ESP8266 module:
The above illustrated module is called generic ESP8266 which is responsible for connecting the weather monitoring system to internet. This module is inserted on a breakout board adapter so that ESP8266 can be interfaced on a breadboard.
Pin diagram of ESP8266:
ESP8266 is not a just another ordinary module, it has a full-fledged 32-bit microcontroller which requires a program code to function. We will be using a programmer to upload the code to this ESP8266 module which we will see in the later part of this article. It operates on 3.3V and communicates on serial interface with Arduino.
Light depend resistor – LDR:
LDR is responsible for collecting data about the intensity of light at your surroundings and it is a passive analog sensor.
The LDR is essentially a resistor that is sensitive to the light, when higher intensity light falls on the photosensitive surface its resistance drops and when less light is received its resistance increases.
In other words, the resistance is inversely proportional to the intensity of the light on the photosensitive surface of LDR.
This concludes all the modules and sensors used in the circuit setup.
Program code for Arduino:
I2C LCD library: Click here
DHT library: Click here
BMP180 library: Click here
Program code for Generic ESP8266
Download Thingspeak Library: Click here
Insert your Wi-Fi credentials here the code:
Insert your Thingspeak credentials here:
How to upload code to generic ESP8266 module:
- You need to download ESP8266 board package.
- You need an ESP8266 programmer board.
1) How to download ESP8266 board package?
- Copy this link: http://arduino.esp8266.com/stable/package_esp8266com_index.json
- Now open Arduino IDE and click on File > Preferences.
- A window will open like this:
- Paste the URL on the box and click “OK”.
- Now go to Tools > Board > Boards Manager.
A window will popup:
- Type “ESP8266” on the box as shown and you will get installation option, select the latest version and click install.
- Now the IDE will download the necessary packages and this could take more than 5 minute to complete.
- Now go to Tools > Board > ESP8266 boards > select “Generic ESP8266”.
- Now, copy the given ESP8266 program code and paste it on to Arduino IDE software.
- Now press compile button (Green tick button). The compilation of code may take more than couple of minutes so be patient. If the compilation failed please check whether have you selected the “Generic ESP8266 Module” in the board option or not.
- After successful compilation of code, now it’s time to upload the code to ESP8266.
2) USB ESP8266 Programmer:
The above illustrated USB device is used for programming the generic ESP8266 module.
Please note that two pins on the programmer must be shorted before you upload the code, otherwise you will get errors while uploading.
Now insert the ESP8266 on the programmer and plug it to your PC’s USB port, like this and click upload:
Once you successfully uploaded the code, you will the below info on your IDE:
Now, you may insert the ESP8266 on your main circuit setup.
How to setup your Thingspeak account for receiving data?
- To send sensor data to Thingspeak, you need a Thingspeak account and you can sign-up here.
- Create a new channel and do the following to your Thingspeak channel:
- Scroll down and press save.
- Please take note of your channel ID and you need to copy and insert the ID to the ESP8266 code.
- Now go to API key tab and you will see “write API” and “read API” keys. Write API key is a secret code for writing data to your Thingspeak channel.
- You need copy and paste the write API key to the ESP8266 code.
Prototype images of IoT based weather monitoring system:
How to operate the IoT based weather monitoring system:
- Make sure that you have connected all the wirings properly and all the modules are connected.
- Plug a 9V to 12V DC adapter to the power supply module’s DC socket and press the ON switch.
- You will see sensor data on the LCD cycling between sensors as shown below:
DHT11 temperature and humidity:
BMP180 atmospheric pressure at ground and sea level (unit is Pa):
MQ-135 Air quality sensor:
LDR sensor – intensity of the light:
Lower percentage indicates low light intensity and higher the percentage indicates higher light intensity.
Please note that air quality and light intensity values are between 0 and 100% and no unit. Also please note that MQ-135 sensor needs to heat up for its proper functioning, so initially while the sensor is heating up it will throw incorrect values and incorrect quality status like toxic or poor.
Data on Thingspeak:
- DHT11 sensor:
BMP180 and LDR:
Note: Initially zero value will get updated on all the 5 fields on Thingspeak and after that real time data starts updating.
If you have any questions regarding this project, feel free to ask us in the comment, you will get a guaranteed reply from us.