IoT based weather monitoring system using Nodemcu and Blynk

IoT based weather monitoring system using Nodemcu and Blynk

Hello, welcome back. In this tutorial, we will learn how to make a Weather monitoring system using the Nodemcu and Blynk app. Also, this project is mainly based on three sensors. That is the rain sensor, DHT11 sensor, and LDR sensor. Through this, we can see factors such as rainfall, temperature, humidity, and amount of light. Also, the speciality is that we can monitor all this over the internet. So, it is clear that this project is a creation of IoT technology. Also, we can do this project at a low cost and use it for farms and greenhouses.

The process of this system

When power up this system. the Nodemcu board connects to the Blynk app through the Blynk cloud. Also, it receives values through sensors. Then, the Nodemcu board sends those values to the Blynk app and the LCD display. Due to this process sensor values can be seen on the Blynk app interface and on the LCD.

OK, let’s do this project step by step. The required components are given below.

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.

IoT based weather monitoring system using Nodemcu and Blynk

Step 3

Thirdly, let’s set up the Blynk app. For that, follows 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.
IoT based weather monitoring system using Nodemcu and Blynk
  • Next, enter the project name as you like and select the device and connection type. Then click the “Confirm” button.
IoT based weather monitoring system using Nodemcu and Blynk
  • 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 includes 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 0 to 100.
  • Then, click the LED widget and set the PIN as V3.
IoT based weather monitoring system using Nodemcu and Blynk
  • Finally, customize this widget to your liking.
IoT based weather monitoring system using Nodemcu and Blynk

OK, the Blynk app is ready for our project.

Step 4

Guys, let’s creates the program for this weather monitoring system. It is as follows.

/*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 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 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

IoT based weather monitoring system using Nodemcu and Blynk

Similar Posts

7 Comments

  1. 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??

  2. 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

Leave a Reply

Your email address will not be published. Required fields are marked *