IOT Live Weather Station Monitoring Using NodemCU ESP8266
This post is all about IoT based Live Weather Station Monitoring Using NodemCU ESP8266. We will interface DHT11 Humidity & Temperature Sensor, BMP180 Barometric Pressure Sensor, and FC37 Rain Sensor with NodeMCU ESP8266-12E Wifi Module. We will measure humidity, temperature, Barometric pressure, and rainfall and upload the data to a web server.
Once the code is uploaded you can find the IP address of NodeMCU in the serial monitor. With the same IP, you can go to any web browser and display the data in a beautiful widget format. The project is very interesting and can be used in remote areas or in a freezer where the data is to be monitored.
You can check this weather station project as well:
1. ESP8266 & BME280 Based Mini Weather Station
2. IoT Weather Station with ESP8266 OpenWeatherMap
3. MQTT Weather Station with GSM
What is a Weather Station?
A weather station is a device that collects data related to the weather & environment using different sensors. There are two types of weather stations, one which is having own sensors and the second type of weather station is where we pull data from the weather station servers. In this tutorial, we will go for the first one, i.e. we will design our own weather station.
Weather station sensors may include a thermometer to take temperature readings, a barometer to measure the atmospheric pressure, Hygrometer to measure humidity, rain sensor to measure rainfall, an anemometer to measure wind speed, and more. Weather stations are also called weather centers, personal weather stations, professional weather stations, home weather stations, weather forecaster, and forecasters.
Components Required
The components needed for this project, i.e., IOT Live Weather Station Monitoring Using NodemCU ESP8266 are given below. All these components can be purchased from Amazon. The purchase link is given below.
S.N. | Components Name | Quantity | Purchase Links |
---|---|---|---|
1 | NodeMCU ESP8266 Board | 1 | Amazon | AliExpress |
2 | BMP180 Sensor | 1 | Amazon | AliExpress |
3 | DHT11 Sensor | 1 | Amazon | AliExpress |
4 | Rain Sensor FC-37 | 1 | Amazon | AliExpress |
5 | Resistor 4.7K | 2 | Amazon | AliExpress |
6 | Connecting Wires | 10 | Amazon | AliExpress |
7 | Breadboard | 1 | Amazon | AliExpress |
DHT11 Humidity & Temperature Sensor:
About DHT11
The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and spits out a digital signal on the data pin. Its fairly simple to use, but requires careful timing to grab data. The digital signal is fairly easy to read using any microcontroller.
Features of DHT11
- Ultra low cost
- 3 to 5V power and I/O
- 2.5mA max current use during conversion (while requesting data)
- Good for 20-80% humidity readings with 5% accuracy
- Good for 0-50°C temperature readings ±2°C accuracy
- No more than 1 Hz sampling rate (once every second)
- Body size 15.5mm x 12mm x 5.5mm
- 4 pins with 0.1″ spacing
BMP180 Barometric Pressure Sensor:
About BMP180
The BMP180 is the new digital barometric pressure sensor of Bosch Sensortec, with a very high performance, which enables applications in advanced devices such as smartphones, tablet PCs, and sports devices. It follows the BMP085 and brings many improvements, like the smaller size and the expansion of digital interfaces.
The ultra-low power consumption down to 3 μA makes the BMP180 the leader in power saving for your devices. BMP180 is also distinguished by its very stable behavior (performance) with regard to the independence of the supply voltage.
Features of BMP180
- Vin: 3 to 5VDC
- Logic: 3 to 5V compliant
- Pressure sensing range: 300-1100 hPa (9000m to -500m above sea level)
- Up to 0.03hPa / 0.25m resolution
- -40 to +85°C operational range, +-2°C temperature accuracy
- This board/chip uses I2C 7-bit address 0x77.
Rain Sensor:
Rain sensors are used in the detection of water beyond what a humidity sensor can detect.
The rain sensor detects water that completes the circuits on its sensor boards’ printed leads. The sensor board acts as a variable resistor that will change from 100k ohms when wet to 2M ohms when dry. In short, the wetter the board the more current that will be conducted.
Circuit Diagram & Connections
Below is the circuit diagram for making Live weather Sation Monitoring Using NodeMCU. Assemble the circuit as shown in the figure below.
Source Code/Programs
The program for Live Weather Station Monitoring Using NodeMCU ESP8266 is divided into two parts, i.e 1. Main Arduino code and 2. index.h HTML file.
But before that add these two libraries:
1. BMP180 Library: Download
2. DHT11 ESP Library: Download
index.h Code
Copy this code and paste it on a text document. Then save this file by name index.h, so you will get a file in the form of .h as a code.
Now move this file to the folder where the main ino code is located.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
const char MAIN_page[] PROGMEM = R"=====( <!DOCTYPE html> <html> <head> <title>www.how2electronics.com</title> </head> <style> @import url(https://fonts.googleapis.com/css?family=Montserrat); @import url(https://fonts.googleapis.com/css?family=Advent+Pro:400,200); *{margin: 0;padding: 0;} body{ background:#544947; font-family:Montserrat,Arial,sans-serif; } h2{ font-size:14px; } .widget{ box-shadow:0 40px 10px 5px rgba(0,0,0,0.4); margin:100px auto; height: 330px; position: relative; width: 500px; } .upper{ border-radius:5px 5px 0 0; background:#f5f5f5; height:200px; padding:20px; } .date{ font-size:40px; } .year{ font-size:30px; color:#c1c1c1; } .place{ color:#222; font-size:40px; } .lower{ background:#00A8A9; border-radius:0 0 5px 5px; font-family:'Advent Pro'; font-weight:200; height:130px; width:100%; } .clock{ background:#00A8A9; border-radius:100%; box-shadow:0 0 0 15px #f5f5f5,0 10px 10px 5px rgba(0,0,0,0.3); height:150px; position:absolute; right:25px; top:-35px; width:150px; } .hour{ background:#f5f5f5; height:50px; left:50%; position: absolute; top:25px; width:4px; } .min{ background:#f5f5f5; height:65px; left:50%; position: absolute; top:10px; transform:rotate(100deg); width:4px; } .min,.hour{ border-radius:5px; transform-origin:bottom center; transition:all .5s linear; } .infos{ list-style:none; } .info{ color:#fff; float:left; height:100%; padding-top:10px; text-align:center; width:25%; } .info span{ display: inline-block; font-size:40px; margin-top:20px; } .weather p { font-size:20px;padding:10px 0; } .anim{animation:fade .8s linear;} @keyframes fade{ 0%{opacity:0;} 100%{opacity:1;} } a{ text-align: center; text-decoration: none; color: white; font-size: 15px; font-weight: 500; } </style> <body> <div class="widget"> <div class="clock"> <div class="min" id="min"></div> <div class="hour" id="hour"></div> </div> <div class="upper"> <div class="date" id="date">21 March</div> <div class="year">Temperature</div> <div class="place update" id="temperature">23 °C</div> </div> <div style="text-align: center;"><a href="https://www.how2electronics.com" style="align:center">www.how2electronics.com</a></div> <div class="lower"> <ul class="infos"> <li class="info temp"> <h2 class="title">TEMPERATURE</h2> <span class='update' id="temp">21 °C</span> </li> <li class="info weather"> <h2 class="title">PRESSURE</h2> <span class="update" id="pressure">0 mb</span> </li> <li class="info wind"> <h2 class="title">RAIN</h2> <span class='update' id="rain">0%</span> </li> <li class="info humidity"> <h2 class="title">HUMIDITY</h2> <span class='update' id="humidity">23%</span> </li> </ul> </div> </div> <script> setInterval(drawClock, 2000); function drawClock(){ var now = new Date(); var hour = now.getHours(); var minute = now.getMinutes(); var second = now.getSeconds(); //Date var options = {year: 'numeric', month: 'long', day: 'numeric' }; var today = new Date(); document.getElementById("date").innerHTML = today.toLocaleDateString("en-US", options); //hour var hourAngle = (360*(hour/12))+((360/12)*(minute/60)); var minAngle = 360*(minute/60); document.getElementById("hour").style.transform = "rotate("+(hourAngle)+"deg)"; //minute document.getElementById("min").style.transform = "rotate("+(minAngle)+"deg)"; //Get Humidity Temperature and Rain Data var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var txt = this.responseText; var obj = JSON.parse(txt); //Ref: https://www.w3schools.com/js/js_json_parse.asp document.getElementById("rain").innerHTML = obj.Rain + "%"; document.getElementById("temperature").innerHTML = Math.round(obj.Temperature) + "°C"; document.getElementById("temp").innerHTML = Math.round(obj.Temperature) + "°C"; document.getElementById("humidity").innerHTML = Math.round(obj.Humidity) + "%"; document.getElementById("pressure").innerHTML = Math.round(obj.Pressuremb) + " mb"; } }; xhttp.open("GET", "readADC", true); //Handle readADC server on ESP8266 xhttp.send(); } </script> </body> </html> )====="; |
Weather Station Main Code
From this code change replace the WiFi SSID & Password with the SSID & Password of your WiFi router. And then you can upload the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
#include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> #include <SFE_BMP180.h> #include <Wire.h> #include "index.h" //Our HTML webpage contents with javascripts #include "DHTesp.h" //DHT11 Library for ESP #define LED 2 //On board LED #define DHTpin 14 //D5 of NodeMCU is GPIO14 SFE_BMP180 pressure; #define ALTITUDE 1655.0 // Altitude in meters DHTesp dht; //SSID and Password of your WiFi router const char* ssid = "Alexahome"; const char* password = "hngzhowxiantan"; ESP8266WebServer server(80); //Server on port 80 void handleRoot() { String s = MAIN_page; //Read HTML contents server.send(200, "text/html", s); //Send web page } float humidity, temperature; void handleADC() { char status; double T,P,p0,a; double Tdeg, Tfar, phg, pmb; status = pressure.startTemperature(); if (status != 0) { // Wait for the measurement to complete: delay(status); status = pressure.getTemperature(T); if (status != 0) { // Print out the measurement: Serial.print("temperature: "); Serial.print(T,2); Tdeg = T; Serial.print(" deg C, "); Tfar = (9.0/5.0)*T+32.0; Serial.print((9.0/5.0)*T+32.0,2); Serial.println(" deg F"); status = pressure.startPressure(3); if (status != 0) { // Wait for the measurement to complete: delay(status); status = pressure.getPressure(P,T); if (status != 0) { // Print out the measurement: Serial.print("absolute pressure: "); Serial.print(P,2); pmb = P; Serial.print(" mb, "); phg = P*0.0295333727; Serial.print(P*0.0295333727,2); Serial.println(" inHg"); p0 = pressure.sealevel(P,ALTITUDE); // we're at 1655 meters (Boulder, CO) Serial.print("relative (sea-level) pressure: "); Serial.print(p0,2); Serial.print(" mb, "); Serial.print(p0*0.0295333727,2); Serial.println(" inHg"); a = pressure.altitude(P,p0); Serial.print("computed altitude: "); Serial.print(a,0); Serial.print(" meters, "); Serial.print(a*3.28084,0); Serial.println(" feet"); } else Serial.println("error retrieving pressure measurement\n"); } else Serial.println("error starting pressure measurement\n"); } else Serial.println("error retrieving temperature measurement\n"); } else Serial.println("error starting temperature measurement\n"); int rain = analogRead(A0); //Create JSON data String data = "{\"Rain\":\""+String(rain)+"\",\"Pressuremb\":\""+String(pmb)+"\",\"Pressurehg\":\""+String(phg)+"\", \"Temperature\":\""+ String(temperature) +"\", \"Humidity\":\""+ String(humidity) +"\"}"; digitalWrite(LED,!digitalRead(LED)); //Toggle LED on data request ajax server.send(200, "text/plane", data); //Send ADC value, temperature and humidity JSON to client ajax request delay(dht.getMinimumSamplingPeriod()); humidity = dht.getHumidity(); temperature = dht.getTemperature(); Serial.print("H:"); Serial.println(humidity); Serial.print("T:"); Serial.println(temperature); //dht.toFahrenheit(temperature)); Serial.print("R:"); Serial.println(rain); } void setup() { Serial.begin(115200); Serial.println(); // dht11 Sensor dht.setup(DHTpin, DHTesp::DHT11); //for DHT11 Connect DHT sensor to GPIO 17 pinMode(LED,OUTPUT); //BMP180 Sensor if (pressure.begin()) Serial.println("BMP180 init success"); else { Serial.println("BMP180 init fail\n\n"); while(1); // Pause forever. } WiFi.begin(ssid, password); //Connect to your WiFi router Serial.println(""); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } //If connection successful show IP address in serial monitor Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); //IP address assigned to your ESP server.on("/", handleRoot); //Which routine to handle at root location. This is display page server.on("/readADC", handleADC); //This page is called by java Script AJAX server.begin(); //Start server Serial.println("HTTP server started"); } void loop() { server.handleClient(); //Handle client requests } |
Working of the Live Weather Station
First Assemble the circuit as shown above in the circuit diagram and upload the main ino file to the NodeMCU board.
Once code is uploaded, get an ESP8266 IP address from serial monitor.
Now copy this ip address and paste it in any web browser like google chrome and hit enter. You will get a beautiful widget with weather information as shown below.
Video Preview & Tutorial
You can watch the video below if you have any problem regarding the coding section and circuit assembling.
You can check this project as well: Wireless Weather Station.
32 Comments
sir at the last phase of the project whe i was open web browser it shows the error “site cant be reached” plez solve my problem thank you
Connect the NodeMCU with the phone hotspot and try. Sometimes some ISP doesn’t work with NodeMCU.
sir i rec some unknow formate serial monitor plz help me clear it
Check baud rate
Connected to MOP
IP address: 192.168……..
HTTP server started
Exception (3):
epc1=0x4000bf64 epc2=0x00000000 epc3=0x00000000 excvaddr=0x40240219 depc=0x00000000
ctx: cont
sp: 3ffffd00 end: 3fffffc0 offset: 01a0
3ffffea0: 74736f00 00000001 3ffef6e4 40203216
3ffffeb0: 3ffffe00 3ffef70c 80000000 4020714c
3ffffec0: 00000001 4020107c 3ffffef0 40209b7e
3ffffed0: 00000001 4020107c 3ffef6e4 401000e1
3ffffee0: 3ffef6e4 3ffee5a0 3ffef6e4 40201c06
3ffffef0: 3ffe0000 3fff0000 8000001c 80fe8508
3fffff00: 3ffef6e4 3ffee5a0 3ffee560 40203636
3fffff10: 0000002f 80000000 81ff0100 0000008f
3fffff20: 80005054 54d74fad 40100500 0000420e
3fffff30: 00000001 3ffee5a0 00000001 40100170
3fffff40: 00000001 00000000 3ffee560 3ffee8dc
3fffff50: 00000001 3ffee584 3ffee560 3ffee8dc
3fffff60: 00000001 3ffee584 3ffee560 402038d3
3fffff70: 00000000 00000000 00001388 feefeffe
3fffff80: 00000000 00000000 00000001 40100170
3fffff90: 3fffdad0 00000000 3ffee89c 40203974
3fffffa0: 3fffdad0 00000000 3ffee89c 40207980
3fffffb0: feefeffe feefeffe 3ffe8508 40100f6d
<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1392, room 16
tail 0
chksum 0xd0
csum 0xd0
v3d128e5c
~ld
BMP180 init success
I have got this error… please help me out
Hi can you further let me now how to do matlab analysis on thingspeak for this project. It will be a greattt help. Thanks.
Hi, can you please let me know how to do matlab analysis at thingspeak on this project. It would be a great help. thanks.
How did you get the rain value in terms of percentage? and what is the range?
Go to board manager . installed esp8266 community version 2.5.2 and try its working
3fffffb0: feefeffe feefeffe 3ffe8524 401010b9
can you please modify the code if we dont want to use BMP sensor? please help
Exception (3):
epc1=0x4000bf64 epc2=0x00000000 epc3=0x00000000 excvaddr=0x402405f9 depc=0x00000000
ctx: cont
sp: 3ffef630 end: 3ffef8f0 offset: 0190
3ffef7c0: 00000001 3ffee5b4 402405f9 402066bf
3ffef7d0: 3fff0958 00000001 3fff0754 40203212
3ffef7e0: 3ffef800 3ffef840 80fef820 40201bb8
3ffef7f0: 00000001 40209e98 3ffef820 40209e66
3ffef800: 3ffef840 3ffee5d0 3fff0754 401000d9
3ffef810: 3fff0754 3ffee5d0 3fff0754 40201bf0
3ffef820: 3ffe0000 00000000 80000142 80100337
3ffef830: 3fff0754 3ffee5d0 3ffee590 40203632
3ffef840: 0000002f 80000000 81ff1200 0000009f
3ffef850: 80005054 cf9eb8fd 40100c20 0000413a
3ffef860: 3ffee5d0 00000000 3ffee590 00000001
3ffef870: 00000001 3fff0754 00001388 3ffef938
3ffef880: 00000000 3fff0c64 3ffee590 3ffef938
3ffef890: 00000001 3ffee5b4 3ffee590 402038d3
3ffef8a0: 4020a318 00000000 00001388 80efef00
3ffef8b0: 00000000 3fff0c64 00000001 401008e8
3ffef8c0: 3fffdad0 00000000 3ffef8f8 40203974
3ffef8d0: 3fffdad0 00000000 3ffef8f8 40207690
3ffef8e0: feefeffe feefeffe 3ffe8504 40100875
<<<stack<<<
Can I know which software did you use for the making the schematic?
Hello Sir Can I use YL-83 Rain Sensor Module instead of FC-37 Rain Sensor Module?
I guess both are the similar sensor, you can use.
sir can you send documentation of this project
when i compile the program and output not come and error given nodemcu compilng error
Hi,
Dear, I cannot reach the site through the generated IP number 192.168.xxx.xxx
Via the serial monitor: Connected to Ziggo-ap-1214480
IP address: 192.168.xxx.xxx
HTTP server started
————— CUT HERE FOR EXCEPTION DECODER —————
Exception (3):
epc1 = 0x4000bf64 epc2 = 0x00000000 epc3 = 0x00000000 excvaddr = 0x40240589 depc = 0x00000000
ctx: cont
sp: 3ffffd00 end: 3fffffc0 offset: 0190
3ffffe90: 00000001 3ffee5a4 40240589 40206933
3ffffea0: 3ffefee8 00000001 3ffefce4 40203212
3ffffeb0: 3fffff00 3fffff10 80fffef0 40201bb8
3ffffec0: 00000001 40209e34 3ffffef0 40209e02
3ffffed0: 3fffff10 3ffee5c0 3ffefce4 401000e1
3ffffee0: 3ffefce4 3ffee5c0 3ffefce4 40201bf0
3ffffef0: 3ffe0000 3fff0000 80fee8fc 80000030
3fffff00: 3ffefce4 3ffee5c0 3ffee580 40203632
3fffff10: 0000002f 80000000 81ff0600 0000021f
3fffff20: 80005054 822751ff 40100400 0000672c
3fffff30: 3ffee5c0 00000000 00000001 00000001
3fffff40: 00000001 3ffefce4 3ffee580 3ffee8fc
3fffff50: 00000001 3ffee5a4 3ffee580 3ffee8fc
3fffff60: 00000001 3ffee5a4 3ffee580 402038d3
3fffff70: 00000000 00000000 00001388 80efef00
3fffff80: 00000000 00000000 00000001 40100170
3fffff90: 3fffdad0 00000000 3ffee8bc 40203974
3fffffa0: 3fffdad0 00000000 3ffee8bc 40207904
3fffffb0: feefeffe feefeffe 3ffe8504 40100ee1
<<< stack <<<
————— CUT HERE FOR EXCEPTION DECODER —————
etching Jan 8 2013, rst cause: 2, boot mode: (3,6)
load 0x4010f000, len 3584, room 16
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ ld
BMP180 init success
…….
Connected to Ziggo-ap-xxxxxxx
IP address: 192.168.xxx.xxx
HTTP server started
I really don’t know what to do anymore, can you help because I see more of these problems with the questions. Ps also the smartphone does not work with the IP address
Would it be possible to connect this to something like IFTTT so I can set up alerts when hitting certain values (eg temperature gets too high/pressure drops/it starts raining)
sir, why it cannot found the MAIN_PAGE?
Can I do with this project without resistors?
I couldn’t find them because of lockdown.
Sir, will it be ok to make this project without resistors ?
I couldn’t find it anywhere due to lockdown.
The resistor is used for voltage divider network. Nodemcu supports only 3.3V.
I upload the code fine. But when I put in the IP, I get nothing. What’s up? I have other weather stations that work. I like what you use.
I got it working. One of the few I’ve tried that actually work, so nice moves!
I would like to get the temperature in fahrenheit. Is there code I could add to the ino to change it to fahrenheit?
Thanks for all your precious time!!!
where does the circuit diagram is configure?
how did you get this working please teel us/me because I did not a working station
i still got unkown characters in serial monitor even after change baud rate to the correct value(115200)
void handleRoot() {
String s = MAIN_page; //Read HTML contents
server.send(200, “text/html”, s); //Send web page
}
at ‘MAIN_page’ was not declared in this scope
please rectify these error
Sir getting unknown question marks at serial monitor
can’t be able to select port it will shows disabled tried every solution possible on net still not able to get port enabled can anyone help me?
how to collect data in excel for analysis