1. Introduction
In this project, we are building a professional IoT Weather Station. Using the ESP32 and the BME280 sensor, we will create a system that sends real-time temperature, humidity, and pressure data to a custom Mobile App. This allows you to monitor your home environment from anywhere in the world using the
Blynk IoT platform.
2. Components
ESP32 Development Board (30 or 38 pins)
BME280 Sensor Module (I2C Version)
Jumper Wires & Breadboard
Smartphone (Android or iOS)
Micro-USB Cable
ESP32 Development Board (30 or 38 pins)
BME280 Sensor Module (I2C Version)
Jumper Wires & Breadboard
Smartphone (Android or iOS)
Micro-USB Cable
3. Circuit and Connections
The BME280 uses the I2C protocol. It is important to use the 3.3V pin on the ESP32, as 5V can damage the sensor.
| BME280 Pin | ESP32 Pin | Function |
| VCC | 3.3V | Power |
| GND | GND | Ground |
| SCL | GPIO 22 | I2C Clock |
| SDA | GPIO 21 | I2C Data |
4. How to Design the Mobile App
We will use the Blynk IoT app to create the dashboard.
Install Blynk: Download the Blynk IoT app on your phone and create an account.
Create Template: On the Blynk Cloud website, create a new template named "Weather Station" for ESP32 via WiFi.
Setup Datastreams: Create three Virtual Pin datastreams:
V1: Temperature (Unit: °C)
V2: Humidity (Unit: %)
V3: Pressure (Unit: hPa)
Add Widgets: In the Mobile App, drag and drop 3 Gauges or Labeled Values.
Assign Pins: Click each widget and set its DataStream to V1, V2, and V3 respectively.
5. Circuit Working
The BME280 sensor detects changes in air pressure and humidity using a tiny internal membrane. It converts these physical changes into digital data and sends them to the ESP32 via the I2C bus. The ESP32 connects to your Wi-Fi and "pushes" this data to the Blynk Cloud every 2 seconds. Your mobile app then pulls this data from the cloud to update the gauges on your screen.
6. Code
Library Setup: In Arduino IDE, go to Manage Libraries and install: Blynk, Adafruit BME280, and Adafruit Unified Sensor.
#define BLYNK_TEMPLATE_ID "Your_Template_ID"
#define BLYNK_TEMPLATE_NAME "Weather Station"
#define BLYNK_AUTH_TOKEN "Your_Auth_Token"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <Adafruit_BME280.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Your_WiFi_Name";
char pass[] = "Your_WiFi_Password";
Adafruit_BME280 bme;
BlynkTimer timer;
void sendSensorData() {
float t = bme.readTemperature();
float h = bme.readHumidity();
float p = bme.readPressure() / 100.0F;
Blynk.virtualWrite(V1, t); // Send to App Widget V1
Blynk.virtualWrite(V2, h); // Send to App Widget V2
Blynk.virtualWrite(V3, p); // Send to App Widget V3
}
void setup() {
Serial.begin(115200);
if (!bme.begin(0x76)) {
Serial.println("BME280 sensor not found!");
while (1);
}
Blynk.begin(auth, ssid, pass);
timer.setInterval(2000L, sendSensorData); // Update every 2 seconds
}
void loop() {
Blynk.run();
timer.run();
}
7. Code Working
Auth Token: This is the unique "key" that identifies your device to the Blynk app.
BlynkTimer: We use a timer instead of delay(). This ensures the Wi-Fi connection doesn't drop while the ESP32 is waiting to read the sensor.
VirtualWrite: This command sends the float variables (t, h, p) to the cloud "Virtual Pins" V1, V2, and V3.
Auth Token: This is the unique "key" that identifies your device to the Blynk app.
BlynkTimer: We use a timer instead of delay(). This ensures the Wi-Fi connection doesn't drop while the ESP32 is waiting to read the sensor.
VirtualWrite: This command sends the float variables (t, h, p) to the cloud "Virtual Pins" V1, V2, and V3.
8. Tips
I2C Scanner: If the sensor isn't found, run an "I2C Scanner" sketch to find its address (usually 0x76 or 0x77).
Power Stability: The ESP32 draws more power when using Wi-Fi. Ensure you use a high-quality USB cable.
Static IP: Assigning a static IP to the ESP32 in your router settings makes the connection even more stable for 24/7 monitoring.
I2C Scanner: If the sensor isn't found, run an "I2C Scanner" sketch to find its address (usually 0x76 or 0x77).
Power Stability: The ESP32 draws more power when using Wi-Fi. Ensure you use a high-quality USB cable.
Static IP: Assigning a static IP to the ESP32 in your router settings makes the connection even more stable for 24/7 monitoring.
9. Uses
Smart Home: Monitor room temperature while you are at work.
Agriculture: Check greenhouse conditions remotely from your phone.
HVAC Testing: Verify if your air conditioning system is cooling rooms evenly.
Smart Home: Monitor room temperature while you are at work.
Agriculture: Check greenhouse conditions remotely from your phone.
HVAC Testing: Verify if your air conditioning system is cooling rooms evenly.
10. Conclusion
Building an IoT Weather Station with the ESP32 is a powerful way to master internet-connected electronics. By combining high-precision sensors with the Blynk platform, you have created a tool that is both practical and professional. This project serves as a perfect foundation for more advanced IoT systems, such as smart irrigation or home climate control.
11. Project Workflow
To understand how this IoT system works, we can break it down into four simple stages. This "Data Journey" ensures that the information is accurate and delivered in real-time.- Sensing Stage: The BME280 sensor continuously monitors the physical environment. It detects microscopic changes in air pressure and humidity and converts them into digital signals.
- Processing Stage: The ESP32 acts as the "brain." Every 2 seconds as set by our
BlynkTimer. it requests the latest data from the sensor via the I2C pins (GPIO 21 & 22). Transmission Stage: The ESP32 uses its built-in Wi-Fi module to connect to your home router. It packages the sensor data with your unique Auth Token and sends it to the Blynk IoT Cloud Server.
Visualization Stage: Your Blynk Mobile App is also connected to the Blynk Cloud. As soon as the cloud receives new data from your ESP32, it pushes that information to the Virtual Pins (V1, V2, V3) on your phone's dashboard, updating the gauges instantly.
- Sensing Stage: The BME280 sensor continuously monitors the physical environment. It detects microscopic changes in air pressure and humidity and converts them into digital signals.
- Processing Stage: The ESP32 acts as the "brain." Every 2 seconds as set by our
BlynkTimer.it requests the latest data from the sensor via the I2C pins (GPIO 21 & 22). Transmission Stage: The ESP32 uses its built-in Wi-Fi module to connect to your home router. It packages the sensor data with your unique Auth Token and sends it to the Blynk IoT Cloud Server.
Visualization Stage: Your Blynk Mobile App is also connected to the Blynk Cloud. As soon as the cloud receives new data from your ESP32, it pushes that information to the Virtual Pins (V1, V2, V3) on your phone's dashboard, updating the gauges instantly.