Full width home advertisement

Post Page Advertisement [Top]

 I check the weather app on my phone constantly before deciding whether to open my workshop windows or run the dehumidifier. At some point it hit me — I have a whole box of unused sensors sitting in a drawer, so why am I relying on an app pulling data from a weather station five kilometers away when I could just measure the actual air in my own room? So I built a small ESP32 weather station with a BME280 sensor, and now I get temperature, humidity, and pressure readings specific to my workshop, not the nearest airport.

This guide walks through the full build — wiring, code, and a simple web server so you can check the readings from your phone without needing any external display.

DIY ESP32 Weather Station with BME280

Why the BME280 Specifically?

There are cheaper sensors out there, like the DHT22, that measure temperature and humidity. The BME280 goes a step further and adds barometric pressure to the mix, which is genuinely useful — pressure trends are one of the more reliable ways to predict incoming weather changes before they actually happen. It also communicates over I2C, which means simple 4-wire wiring and no messy timing-sensitive protocols to fight with, unlike some cheaper sensors.

What You'll Need

  • 1x ESP32 development board
  • 1x BME280 sensor module (make sure it's genuinely a BME280, not a BMP280 — the BMP280 looks nearly identical but leaves out humidity measurement entirely)
  • Jumper wires and a breadboard
  • Optional: a small OLED display if you want readings visible locally, without opening a browser

Step 1: Wiring the Sensor

The BME280 communicates over I2C, so the wiring is short and simple:

  • VCC → 3.3V on the ESP32
  • GND → GND
  • SCL → GPIO 22
  • SDA → GPIO 21

That's genuinely it for the hardware side. If your module has extra pins like CSB or SDO, you can leave those disconnected — they're only needed if you're using SPI mode instead of I2C, which isn't necessary for this build.

Step 2: Installing the Libraries

In the Arduino IDE, open the Library Manager and install Adafruit BME280 Library along with Adafruit Unified Sensor, which it depends on. These handle all the internal calibration math the sensor chip needs — you really don't want to be doing that math by hand.

Step 3: Reading the Sensor

Here's a simple sketch to confirm everything's wired correctly and print readings to the Serial Monitor:

cpp
#include <Wire.h>
#include <Adafruit_BME280.h>

Adafruit_BME280 bme;

void setup() {
  Serial.begin(115200);
  if (!bme.begin(0x76)) {
    Serial.println("Could not find BME280 sensor - check wiring or I2C address");
    while (1);
  }
}

void loop() {
  Serial.print("Temperature: ");
  Serial.print(bme.readTemperature());
  Serial.println(" °C");

  Serial.print("Humidity: ");
  Serial.print(bme.readHumidity());
  Serial.println(" %");

  Serial.print("Pressure: ");
  Serial.print(bme.readPressure() / 100.0F);
  Serial.println(" hPa");

  delay(5000);
}

If this doesn't work right away, the most common issue is the I2C address. Most BME280 modules default to 0x76, but some use 0x77. If your sketch reports it can't find the sensor, just try swapping to the other address before assuming your wiring is wrong.

DIY ESP32 Weather Station with BME280

Step 4: Turning It Into a Web-Based Weather Station

Reading values in the Serial Monitor is fine for testing, but the real value comes from checking readings on your phone without plugging anything into a computer. Here's a simple version that hosts a basic web page with live readings:

cpp
#include <WiFi.h>
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <WebServer.h>

const char* ssid = "YourWiFiName";
const char* password = "YourWiFiPassword";

Adafruit_BME280 bme;
WebServer server(80);

void handleRoot() {
  String html = "<h1>Workshop Weather Station</h1>";
  html += "<p>Temperature: " + String(bme.readTemperature()) + " C</p>";
  html += "<p>Humidity: " + String(bme.readHumidity()) + " %</p>";
  html += "<p>Pressure: " + String(bme.readPressure() / 100.0F) + " hPa</p>";
  server.send(200, "text/html", html);
}

void setup() {
  Serial.begin(115200);
  bme.begin(0x76);

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
  Serial.println(WiFi.localIP());

  server.on("/", handleRoot);
  server.begin();
}

void loop() {
  server.handleClient();
}

Once this uploads and connects to your Wi-Fi, check the Serial Monitor for the IP address it prints, and type that into your phone's browser while on the same network. You'll get a simple live-updating page with your readings — refresh it any time you want current data.

Common Problems (And How I Fixed Them)

The sensor gives readings, but temperature seems a few degrees too high. This is almost always heat coming off the ESP32 board itself, especially if the sensor is mounted right next to it. Give the BME280 a little physical distance from the board, or mount it on a short set of wires away from the main enclosure.

The pressure reading looks reasonable, but doesn't match my phone's weather app. That's actually expected, and it's not necessarily wrong — most weather apps show pressure adjusted to "sea level," while your raw sensor reading depends on your actual altitude. If you want a directly comparable number, you can adjust for this in code once you know your elevation, but for tracking pressure trends over time (which is genuinely the more useful part), the raw reading works fine as-is.

The web page loads once, then stops updating without a manual refresh. That's expected with this simple version — it's not auto-refreshing. If you want live updates without manually refreshing, the next step is adding a small JavaScript auto-refresh or switching to a WebSocket-based approach, which is a good upgrade once the basic version is solid.

Taking It Further

Once the basic sensor and web server are working, a few natural upgrades are worth considering: adding an OLED display so you don't need your phone at all, logging readings over time to spot trends (this is where pressure drops actually become genuinely useful for predicting incoming weather), or sending data to Home Assistant if you already have a dashboard set up for other sensors around the house.

DIY ESP32 Weather Station with BME280 3

Final Thoughts

This is one of the more relaxing weekend projects on this blog — no mains voltage to worry about, no complicated calibration, just a small sensor quietly doing its job. Mine's been sitting on a shelf in my workshop for months now, and checking it before deciding whether to crack a window open has become a genuinely useful little habit I didn't expect to form.

Bottom Ad [Post Page]