
IoT-Based Smart Weather Monitoring System Using ESP32
1. Introduction
This project involves building a smart weather monitoring system using an ESP32, DHT22, and BMP280 to measure temperature, humidity, and atmospheric pressure. The collected data will be displayed on an OLED screen and sent to the Blynk IoT platform for remote monitoring via a smartphone.
2. Learning Objectives
- Understand ESP32 integration with sensors.
- Learn how to send real-time data to an IoT platform.
- Develop Wi-Fi and MQTT communication skills.
- Gain experience in circuit design and debugging.
3. Components and Tools Required
- ESP32 – Wi-Fi-enabled microcontroller.
- DHT22 Sensor – Measures temperature and humidity.
- BMP280 Sensor – Measures barometric pressure and altitude.
- OLED Display (0.96″) – Shows readings locally.
- 10kΩ Resistor – Required for the DHT22 data pin.
- Jumper Wires & Breadboard – For prototyping.
- 5V Power Supply – To power the ESP32.
4. Understanding the Components
ESP32 Microcontroller
The ESP32 is a powerful IoT microcontroller with built-in Wi-Fi and Bluetooth, supporting multiple communication protocols like I²C, SPI, and UART.
DHT22 Sensor
The DHT22 is a digital sensor that measures temperature and humidity with high accuracy. It requires a 10kΩ pull-up resistor on its data pin to function correctly.
BMP280 Sensor
The BMP280 is a barometric pressure sensor that also provides altitude estimation. It communicates via I²C or SPI, making it easy to interface with ESP32.
Blynk IoT Platform
Blynk is a cloud-based platform that allows real-time monitoring and control of IoT devices through a smartphone app. The ESP32 will send sensor data to Blynk for remote access.
5. Circuit Connections
ESP32 Pin Wiring:
- DHT22 Sensor:
- VCC → 3.3V
- GND → GND
- Data Pin → GPIO 4 (with a 10kΩ pull-up resistor)
- BMP280 Sensor (I²C Mode):
- VCC → 3.3V
- GND → GND
- SDA → GPIO 21
- SCL → GPIO 22
- OLED Display (I²C Mode):
- VCC → 3.3V
- GND → GND
- SDA → GPIO 21
- SCL → GPIO 22
Note: Both the BMP280 and OLED Display share the same I²C bus.
6. Code Implementation (Arduino IDE)
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
#include <Adafruit_BMP280.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// Wi-Fi and Blynk credentials
char auth[] = "Your_Blynk_Auth_Token";
char ssid[] = "Your_WiFi_SSID";
char pass[] = "Your_WiFi_Password";
// Sensor and OLED configurations
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP280 bmp;
Adafruit_SSD1306 display(128, 64, &Wire, -1);
// Blynk Virtual Pins
#define VIRTUAL_TEMP V1
#define VIRTUAL_HUMIDITY V2
#define VIRTUAL_PRESSURE V3
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, pass);
Blynk.begin(auth, ssid, pass);
dht.begin();
if (!bmp.begin(0x76)) {
Serial.println("BMP280 not detected!");
while (1);
}
// Initialize OLED
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("OLED not found");
while (1);
}
display.clearDisplay();
}
void loop() {
Blynk.run();
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
float pressure = bmp.readPressure() / 100.0F;
// Send data to Blynk
Blynk.virtualWrite(VIRTUAL_TEMP, temperature);
Blynk.virtualWrite(VIRTUAL_HUMIDITY, humidity);
Blynk.virtualWrite(VIRTUAL_PRESSURE, pressure);
// Display on OLED
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.print("Temp: "); display.print(temperature); display.println(" C");
display.print("Humidity: "); display.print(humidity); display.println(" %");
display.print("Pressure: "); display.print(pressure); display.println(" hPa");
display.display();
Serial.print("Temp: "); Serial.print(temperature); Serial.print(" C, ");
Serial.print("Humidity: "); Serial.print(humidity); Serial.print(" %, ");
Serial.print("Pressure: "); Serial.print(pressure); Serial.println(" hPa");
delay(2000);
}
7. Testing & Debugging Tips
- Wi-Fi Connection Issues: Ensure the correct Wi-Fi credentials are used and that the ESP32 is within range.
- DHT22 Not Responding: Check wiring and ensure the 10kΩ pull-up resistor is correctly connected.
- BMP280 Not Detected: Verify the I²C address (either 0x76 or 0x77) in the code.
- OLED Display Issues: Ensure proper initialization and check I²C wiring.
8. Possible Extensions & Improvements
- Additional Sensors: Add a rain sensor and wind speed sensor for a complete weather station.
- Cloud Storage: Use Google Sheets or Firebase for historical data logging.
- Alternative IoT Protocols: Replace Blynk with MQTT for better scalability.
- Power Optimization: Implement a low-power mode for battery operation.
- Solar Power Integration: Use a solar panel and Li-Ion battery for an off-grid setup.