IoT based weather monitoring system using Nodemcu and Blynk
Hello, welcome back. In this project, we will learn how to make a Weather monitoring system using the Nodemcu and Blynk app. This project primarily involves three sensors: the rain sensor, the DHT11 sensor, and the LDR sensor. With these sensors, we can monitor factors such as rainfall, temperature, humidity, and light levels. The unique aspect of this project is that it allows us to monitor all these factors over the internet, making it a great example of IoT technology. Additionally, this project can be implemented at a low cost and is useful for applications in farms and greenhouses.
The process of this system
When powering up the system, the NodeMCU board connects to the Blynk app through the Blynk cloud. It also receives values from sensors. The NodeMCU board then sends these values to both the Blynk app and the LCD. As a result, sensor values can be viewed on the Blynk app interface and the LCD.
OK, let’s do this project step by step. The required components are given below.
- Nodemcu ESP8266 board x 1 — Our Store / Amazon
- Rain sensor x 1 — Our Store / Amazon
- DHT11 sensor x 1 — Our Store / Amazon
- LDR sensor x 1 — Our Store / Amazon
- LCD x 1 — Our Store / Amazon
- I2C module x 1 — Our Store / Amazon
- Breadboard x 1 — Our Store / Amazon
- Jumper wires x 1 — Our Store / Amazon
Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.
Step 1
Firstly, identify these components.c
Step 2
Secondly, connect these components. To do this, use the circuit diagram below.
Step 3
Thirdly, let’s set up the Blynk app. For that, follow the steps below.
- First, download and install the Blynk app on your phone. After, sign up for this app using your email address. Then, click the “New project” button.
- Next, enter the project name as you like and select the device and connection type. Then click the “Confirm” button.
- OK, now we can see the project interface. Next, let’s add the widgets to the interface. For that, click the “+” icon in the corner and include the three Gauge widgets and one LED widget.
- OK, let’s set up this widget one by one. For that, Name the Gauge widgets as Temperature, Humidity, and Rainfall, respectively. Also, set the PINs to V0, V1, and V2 and set the display values from 0 to 100.
- Then, click the LED widget and set the PIN as V3.
- Finally, customize this widget to your liking.
OK, the Blynk app is ready for our project.
Step 4
Now, let’s create the program for this weather monitoring system. It is as follows.
- WI-Fi Library — Download
- Blynk Library — Download
- DHT11 Library — Download
- I2C library — Download
- The complete program of this project – Download
/*Weather monitoring system with Nodemcu
* https://srituhobby.com
*/
#include <LiquidCrystal_I2C.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
DHT dht(D3, DHT11); //(sensor pin,sensor type)
BlynkTimer timer;
char auth[] = ""; //Enter the Auth code which was send by Blink
char ssid[] = ""; //Enter your WIFI Name
char pass[] = ""; //Enter your WIFI Password
void weather() {
float h = dht.readHumidity();
float t = dht.readTemperature();
int r = analogRead(A0);
bool l = digitalRead(D4);
r = map(r, 0, 1023, 100, 0);
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V0, t); //V0 is for Temperature
Blynk.virtualWrite(V1, h); //V1 is for Humidity
Blynk.virtualWrite(V2, r); //V2 is for Rainfall
if (l == 0) {
WidgetLED led1(V3);
led1.on();
lcd.setCursor(9, 1);
lcd.print("L :");
lcd.print("High");
lcd.print(" ");
} else if (l == 1) {
WidgetLED led1(V3);
led1.off();
lcd.setCursor(9, 1);
lcd.print("L :");
lcd.print("Low");
lcd.print(" ");
}
lcd.setCursor(0, 0);
lcd.print("T :");
lcd.print(t);
lcd.setCursor(0, 1);
lcd.print("H :");
lcd.print(h);
lcd.setCursor(9, 0);
lcd.print("R :");
lcd.print(r);
lcd.print(" ");
}
void setup() {
Serial.begin(9600); // See the connection status in Serial Monitor
lcd.init();
lcd.backlight();
Blynk.begin(auth, ssid, pass);
dht.begin();
// Setup a function to be called every second
timer.setInterval(10L, weather);
}
void loop() {
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
}
Code explanation
Firstly, library files are included.
#include <LiquidCrystal_I2C.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
Next, objects are created for these libraries.
LiquidCrystal_I2C lcd(0x27, 16, 2); //I2C address, LCD length, and width
DHT dht(D3, DHT11); //(sensor pin,sensor type)
BlynkTimer timer;
OK, now let’s include the Blynk app Auth token and Wi-Fi connection details.
char auth[] = "VEilfTlAm3vxyrTMCNwrE8VA695ElEv8"; //Enter the Auth code which was send by Blink
char ssid[] = "Dialog 4G 025"; //Enter your WIFI Name
char pass[] = "b2016ee3"; //Enter your WIFI Password
This is the main function of this program,
void weather() {
float h = dht.readHumidity(); //Gets the humidity value through the DHT11 sensor
float t = dht.readTemperature();//Gets the temperature value through the DHT11 sensor
int r = analogRead(A0);//Gets the rainfall value through the rain sensor
bool l = digitalRead(D4);//Gets the light value through the LDR sensor
r = map(r, 0, 1023, 100, 0);//Converts the rainfall value from 0 to 100
//The functionality of the DHT11 sensor is checked
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
//Sensor values are sent to the Blynk app
Blynk.virtualWrite(V0, t); //V0 is for Temperature
Blynk.virtualWrite(V1, h); //V1 is for Humidity
Blynk.virtualWrite(V2, r); //V2 is for Rainfall
//LDR sensor values are checked using the IF condition. If the value is 0, the LED widget is light up
if (l == 0) {
WidgetLED led1(V3);
led1.on();
lcd.setCursor(9, 1);
lcd.print("L :");
lcd.print("High");
lcd.print(" ");
//If the value is 1, the LED widget is dimmed
} else if (l == 1) {
WidgetLED led1(V3);
led1.off();
lcd.setCursor(9, 1);
lcd.print("L :");
lcd.print("Low");
lcd.print(" ");
}
//Sensor values are printed on the LCD
lcd.setCursor(0, 0);
lcd.print("T :");
lcd.print(t);
lcd.setCursor(0, 1);
lcd.print("H :");
lcd.print(h);
lcd.setCursor(9, 0);
lcd.print("R :");
lcd.print(r);
lcd.print(" ");
}
In the setup function,
void setup() {
Serial.begin(9600); // The serial monitor is beginning
//The LCD, Blynk, and DHT11 libraries are starts
lcd.init();
lcd.backlight();
Blynk.begin(auth, ssid, pass);
dht.begin();
// This code the main function is called
timer.setInterval(10L, weather);
}
In the loop function, the Blynk library is run.
void loop() {
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
}
Step 5
Now, select the board and port. Afterward, upload this code to the Nodemcu board.
Step 6
Lastly, run the Blynk app and enjoy this project. The full video guide is given below. So, we will meet in the next tutorial.
IoT based weather monitoring system using Nodemcu and Blynk
Hi , I am Rivanth and i tried the above project but while uploading the sketch in the arduino….It’s showing hardsetting via rts
What should I do??
Hi,
I just want to know whether I could use ESP32 instead of ESP8266 as my Wi-Fi module.
Please reply at the earliest.
Thank you,
Madhav
How much cost happrn to build this Project successfully
Check the components list
can u give a brief explaination of the connections given in this
plss reply
hi
I am facing an error while uploading code related to LCD I2c It shows an error that says “no such file or directory”
What should I do?
Please include the I2C library