How to Make a Weather Monitoring System with ESP32 and Blynk Cloud

How to Make a Weather Monitoring System with ESP32 and Blynk Cloud

Hello and welcome back. In this project, we will learn how to make a full weather monitoring system using an ESP32 board. For monitoring the sensor values remotely, I used the Blynk Cloud platform, which allows us to view real-time data on a mobile phone from anywhere. With this system, we can monitor temperature, humidity, rainfall, light value, and atmospheric pressure. For this project, I used a DHT11 sensor to measure temperature and humidity, an LDR sensor to detect light intensity, a rain sensor to measure rainfall, and a BMP180 sensor to measure atmospheric pressure. All these sensors are connected to the ESP32 board.

I also added an LCD screen to display the sensor values locally, so we can see the readings even without a mobile phone or internet connection. In addition, I designed a custom PCB for this project using JLCPCB. Because of this PCB, the project looks neat and compact.

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.

Step 2

Secondly, let’s order PCBs for this project.

  • Click the “Instant Quote” button and upload the Gerber file, which you can download from the link below.
  • Gerber file – Download
  • For this project, I ordered five black PCBs. Next, select the build time and shipping method. Finally, click “Save to Cart” and complete the payment.

Step 3

After that, unbox the PCB package carefully.

Step 4

Next, solder the female headers, resistor, preset, and two-pin terminal on the PCB.

Step 5

Afterward, connect the LCD and sensors to the circuit.

Step 6

Now, let’s set up the Blynk Cloud by following the instructions below.

  • First, go to the Blynk website and log in to your account. If you don’t have an account, create one using your email address. After logging in, create a new template and give it any name you like.
  • Next, go to the Datastreams tab and create five virtual pins using the following details.
  • Virtual PIN Name –> Temperature / PIN –> V0 / MIN –> 0 / MAX –> 100
  • Virtual PIN Name –> Humidity / PIN –> V1 / MIN –> 0 / MAX –> 100
  • Virtual PIN Name –> Rainfall / PIN –> V2 / MIN –> 0 / MAX –> 100
  • Virtual PIN Name –> Pressure / PIN –> V3 / MIN –> 300 / MAX –> 1100
  • Virtual PIN Name –> Light value / PIN –> V4 / MIN –> 0 / MAX –> 1
  • Now, create a web dashboard. For this dashboard, I used four gauge widgets and one LED. You can customize the widgets according to your preference. Make sure to select the datastreams we created earlier.
  • After that, go to the Devices tab and select your template. You will now be able to see the Blynk Auth Token.

Step 7

Next, connect the ESP32 board to your computer. Then, copy and paste the following program into the Arduino IDE. Make sure to install the required library files before uploading the code.

//Include the library files
#include <LiquidCrystal.h>
#include <Wire.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
#include <SFE_BMP180.h>

#define BLYNK_PRINT Serial
#define LDR 32
#define TH 33
#define Rain 35

//Create three variables for pressure
double T, P;
char status;

//Initialize the LCD display
LiquidCrystal lcd(2, 4, 5, 18, 19, 21);

// Create an object for the BMP180 sensor
SFE_BMP180 bmp;

DHT dht(TH, DHT11);
BlynkTimer timer;

// Enter your Auth token
char auth[] = "***************";

//Enter your WIFI SSID and password
char ssid[] = "************";
char pass[] = "************";

void setup() {
  // Debug console
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
  Wire.begin(23, 22);
  bmp.begin();
  dht.begin();
  lcd.begin(16, 2);
  pinMode(LDR, INPUT);
  pinMode(Rain, INPUT);
  analogReadResolution(12);

  lcd.setCursor(1, 0);
  lcd.print("System Loading");
  for (int a = 0; a <= 15; a++) {
    lcd.setCursor(a, 1);
    lcd.print(".");
    delay(200);
  }
  lcd.clear();
}

//Get the DHT11 sensor values
void DHT11sensor() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  Blynk.virtualWrite(V0, t);
  Blynk.virtualWrite(V1, h);

  lcd.setCursor(0, 0);
  lcd.print("T:");
  lcd.print(t);

  lcd.setCursor(8, 0);
  lcd.print("H:");
  lcd.print(h);
}

//Get the rain sensor values
void rainSensor() {
  int Rvalue = analogRead(Rain);
  Rvalue = map(Rvalue, 0, 4095, 0, 100);
  Rvalue = (Rvalue - 100) * -1;
  Blynk.virtualWrite(V2, Rvalue);

  lcd.setCursor(0, 1);
  lcd.print("R:");
  lcd.print(Rvalue);
  lcd.print(" ");
  Serial.println(Rvalue);
}

//Get the pressure values
void pressure() {
  status = bmp.startTemperature();
  if (status != 0) {
    delay(status);
    status = bmp.getTemperature(T);

    status = bmp.startPressure(3);  // 0 to 3
    if (status != 0) {
      delay(status);
      status = bmp.getPressure(P, T);
      if (status != 0) {
      }
    }
  }

  Blynk.virtualWrite(V3, P);
  lcd.setCursor(8, 1);
  lcd.print("P:");
  lcd.print(P);
}

//Get the LDR sensor values
void LDRsensor() {
  bool value = digitalRead(LDR);
  if (value == 0) {
    WidgetLED LED(V4);
    LED.on();
  } else {
    WidgetLED LED(V4);
    LED.off();
  }
}

void loop() {
  DHT11sensor();
  rainSensor();
  pressure();
  LDRsensor();
  Blynk.run();  //Run the Blynk library
}
  • Next, paste the Blynk Auth Token into the program, and enter your WiFi SSID and password.
  • After, select the board and port. After, click the upload button.

Step 8

Now, let’s create the Blynk mobile web dashboard. For that, follow the instructions below.

  • First, download and install the Blynk app from the Play Store or App Store.
  • Then, log in to your account and click on the template you created in the web dashboard.
  • Next, click the + icon and add four Gauge widgets and one LED widget to the dashboard.
  • Now, customize these widgets as you like. After that, click the one-by-one widget and select the data streams we created on the web dashboard.

Step 9

Finally, unplug the USB cable and provide an external power source for the system.

Step 10

Now your project is ready to try out! Watch the full video guide below, and we hope to see you in the next project.

How to Make a Weather Monitoring System with ESP32 and Blynk Cloud

Similar Posts

Leave a Reply

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