Smart IoT Weather Station with ESP32 and BME280
Smart IoT Weather Station with ESP32 and BME280 file NXZhQVWQmvuhdCZsHHPC4Q

Smart IoT Weather Station with ESP32 and BME280

1. Introduction

This project creates a weather monitoring system using the ESP32 microcontroller and a BME280 sensor. The system captures temperature, humidity, and pressure data, displays it locally on an OLED screen, and transmits it to an IoT cloud platform like ThingSpeak for remote monitoring.

2. Learning Objectives

By completing this project, you will:
✔ Understand how to interface an ESP32 with the BME280 sensor.
✔ Learn how to send data to an IoT cloud platform (ThingSpeak / Blynk) using Wi-Fi.
✔ Gain hands-on experience with I2C communication, data visualization, and IoT cloud integration.
✔ Learn how to optimize power management and PCB design for IoT applications.


3. Tools and Components

Hardware:

  • ESP32 Dev Board (Wi-Fi & Bluetooth enabled microcontroller)
  • BME280 Sensor (Temperature, Humidity & Pressure measurement)
  • 0.96” OLED Display (SSD1306) (Optional for local display)
  • Jumper Wires for connections
  • Breadboard for prototyping
  • 5V DC Power Adapter or LiPo Battery (For stable operation)

Software:

  • Arduino IDE (For coding & ESP32 programming)
  • ThingSpeak / Blynk (For IoT cloud integration)
  • ESP32 Libraries (BME280, OLED, MQTT, Wi-Fi)
  • EasyEDA / KiCad (For PCB design, if required)

4. Circuit Wiring and Connection

The ESP32 connects to the BME280 sensor and the OLED display using the I2C protocol, which means both modules share the same SDA (Data Line) and SCL (Clock Line).

Wiring Details:

1️⃣ Connect ESP32’s 3.3V pin to BME280’s VCC and OLED VCC for power supply.
2️⃣ Connect ESP32’s GND pin to BME280’s GND and OLED GND.
3️⃣ Connect ESP32’s GPIO 21 (SDA) to BME280’s SDA and OLED’s SDA.
4️⃣ Connect ESP32’s GPIO 22 (SCL) to BME280’s SCL and OLED’s SCL.

👉 If using a custom PCB, include a 3.3V voltage regulator and a pull-up resistor (4.7kΩ) for stable I2C communication.


5. Coding for Data Logging & IoT Integration

Below is the ESP32 Arduino code that reads sensor values and uploads them to ThingSpeak using HTTP requests.

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <WiFi.h>
#include <HTTPClient.h>

#define WIFI_SSID "Your_WiFi_Name"
#define WIFI_PASSWORD "Your_WiFi_Password"
#define API_KEY "Your_ThingSpeak_API_Key"
#define THINGSPEAK_URL "http://api.thingspeak.com/update"

Adafruit_BME280 bme; // Create BME280 sensor object

void setup() {
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(1000);
}
Serial.println("Connected to WiFi");

if (!bme.begin(0x76)) {
Serial.println("Could not find BME280 sensor!");
while (1);
}
}

void loop() {
float temperature = bme.readTemperature();
float humidity = bme.readHumidity();
float pressure = bme.readPressure() / 100.0F; // Convert to hPa

Serial.printf("Temp: %.2f°C, Humidity: %.2f%%, Pressure: %.2f hPa\n",
temperature, humidity, pressure);

// Send data to ThingSpeak
String url = String(THINGSPEAK_URL) + "?api_key=" + API_KEY +
"&field1=" + String(temperature) +
"&field2=" + String(humidity) +
"&field3=" + String(pressure);

HTTPClient http;
http.begin(url);
int httpCode = http.GET();
http.end();

delay(15000); // Update every 15 seconds
}

6. Debugging & Optimization Tips

Check Wi-Fi Connection: If the ESP32 fails to connect, verify the SSID and password.
Confirm I2C Address: Run an I2C scanner script to ensure the BME280’s address is correctly set.
Optimize Power Consumption: If running on battery power, use deep sleep mode to extend battery life.
Ensure API Key Accuracy: A wrong ThingSpeak API Key will result in failed uploads.


7. Enhancements & Future Improvements

🔹 Display Data on OLED: Modify the code to show real-time readings on an OLED display.
🔹 Use MQTT for IoT Communication: Instead of HTTP, implement MQTT for faster & efficient IoT data transfer.
🔹 Integrate IFTTT for Alerts: Send SMS or Email notifications if the temperature exceeds a set threshold.
🔹 Build a Custom PCB: Design a compact PCB board for a professional and portable version.
🔹 Use Solar Power: Make it self-sustainable by adding a solar panel with a LiPo battery.


Final Thoughts

This ESP32 IoT Weather Station is a powerful, scalable, and customizable project that provides real-time weather monitoring and IoT cloud integration. 🚀