Back to All Blog Posts
Tutorial EltroNerd Engineering

IoT Weather Station using ESP32 and BME280 sensor

IoT Weather Station using ESP32 and a BME sensor (BME280/BME680) to measure temperature, humidity, and pressure, with Wi-Fi logging.

IoT Weather Station using ESP32 and BME Sensor

Monitoring weather conditions is a classic IoT project.
In this project, we will build a real-time weather station using an ESP32 and a BME280/BME680 sensor to measure:

  • Temperature (°C)
  • Humidity (%)
  • Atmospheric Pressure (hPa)

The ESP32 will send the data over Wi-Fi to a web dashboard, cloud server, or MQTT broker, making it accessible from anywhere.


Hardware Requirements

  • ESP32 Development Board
  • BME280 or BME680 sensor module
  • Jumper wires and breadboard
  • USB cable for programming

Working Principle

  1. Sensor Measurement:

    • BME280/BME680 communicates with ESP32 via I2C (SDA/SCL) or SPI.
    • Provides accurate temperature, humidity, and pressure readings.
  2. Data Transmission:

    • ESP32 connects to Wi-Fi.
    • Publishes data to a web server, cloud database, or MQTT broker.
  3. Visualization:

    • Data can be displayed in real-time using web dashboard, Blynk, Thingspeak, or Home Assistant.

Arduino Code Example

We’ll use the Adafruit BME280 library. Install via Arduino IDE Library Manager.

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

#define SEALEVELPRESSURE_HPA (1013.25)

const char* ssid = "Your_SSID";
const char* password = "Your_PASSWORD";

Adafruit_BME280 bme; // I2C

void setup() {
  Serial.begin(115200);

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

  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  Serial.print("Connecting to Wi-Fi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nWi-Fi connected!");
}

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

  Serial.print("Temperature: "); Serial.print(temperature); Serial.println(" °C");
  Serial.print("Humidity: "); Serial.print(humidity); Serial.println(" %");
  Serial.print("Pressure: "); Serial.print(pressure); Serial.println(" hPa");
  Serial.println("------------------------");

  // Optional: Send data to web server
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    String url = "http://yourserver.com/log?temp=" + String(temperature) +
                 "&hum=" + String(humidity) + "&pres=" + String(pressure);
    http.begin(url);
    int httpCode = http.GET();
    if (httpCode > 0) {
      Serial.println("Data sent successfully");
    }
    http.end();
  }

  delay(5000); // read every 5 seconds
}

How to Use

Connect the BME sensor to ESP32:

  • VCC → 3.3V

  • GND → GND

  • SDA → GPIO21

  • SCL → GPIO22

Upload the code to ESP32 and open Serial Monitor.

Try this project in your browser

Compile code and simulate hardware output with EltroNerd Cloud IDE.

Launch Cloud IDE