Temperature & humidity station

BME280 plus an OLED screen: temperature, humidity and pressure on the display, a web page and Home Assistant.

Climate & heating Board: ESP32 DevKit V1 (WROOM-32) Level: ●○○ ⏱ 1 h

Check your sensor before you trust it

Many cheap boards sold as BME280 are in reality BMP280, which has no humidity at all. Read the chip ID in the sketch: 0x60 is a BME280, 0x58 a BMP280. The I2C address is 0x76 or 0x77 depending on the board.

Getting numbers that mean something

The ESP32 and the OLED heat the little board, so a reading in a closed case can be one or two degrees too high. Keep the sensor on a short cable away from the processor, or sleep between measurements. Pressure from the sensor is the station pressure; to compare with weather reports apply a correction for your altitude.

  • Humidity sensors drift and dislike condensation. After a bathroom, give them time to recover.
  • Dim the display at night with the clock; it also extends the life of the OLED.
  • The same node, flashed with ESPHome, shows up in Home Assistant without code, see the Home Assistant node idea.

Components

  • ESP32 DevKit V1 (30 pin, WROOM-32)
  • BME280 I2C module (3.3V)
  • OLED 0.96" 128x64 I2C SSD1306
  • Dupont jumper wires (M-F, M-M)

Wiring

Module Module pin ESP32 pin Note
BME280 SDA / SCL I2C GPIO21 / GPIO22 address 0x76 or 0x77
OLED SDA / SCL I2C GPIO21 / GPIO22 address 0x3C
VCC / GND 3V3 / GND

Libraries

  • Adafruit BME280
  • Adafruit SSD1306
  • Adafruit GFX

Code

#include <WiFi.h>

const char* WIFI_SSID = "YOUR_WIFI";
const char* WIFI_PASS = "YOUR_PASSWORD";

bool connectWiFi(uint32_t timeoutMs = 20000) {
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  uint32_t t0 = millis();
  while (WiFi.status() != WL_CONNECTED && millis() - t0 < timeoutMs) {
    delay(250);
    Serial.print(".");
  }
  Serial.println();
  if (WiFi.status() == WL_CONNECTED) {
    Serial.print("IP: ");
    Serial.println(WiFi.localIP());
    return true;
  }
  return false;
}
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <Adafruit_SSD1306.h>
Adafruit_BME280 bme;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
float t = NAN, h = NAN, p = NAN;
#include <WebServer.h>

WebServer server(80);
String buildJson();   // implemented in the project below

String num(float v, int d = 1) { return isnan(v) ? String("null") : String(v, d); }

const char PAGE_HTML[] PROGMEM = R"rawliteral(
<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>ESP32</title>
<style>body{font-family:system-ui;background:#0b0f14;color:#e6edf3;margin:20px}table{border-collapse:collapse}td{padding:6px 14px;border-bottom:1px solid #223}button,input{font-size:16px;padding:8px 14px;margin:4px;border-radius:6px;border:1px solid #345;background:#16202b;color:#e6edf3}</style>
</head><body><h2>ESP32</h2><table id="t"></table>
<script>
function load(){fetch('/json').then(r=>r.json()).then(d=>{let h='';for(const k in d){h+='<tr><td>'+k+'</td><td>'+d[k]+'</td></tr>';}document.getElementById('t').innerHTML=h;});}
load();setInterval(load,2000);
</script></body></html>
)rawliteral";

void startWeb() {
  server.on("/", []() { server.send_P(200, "text/html", PAGE_HTML); });
  server.on("/json", []() { server.send(200, "application/json", buildJson()); });
  server.begin();
}
String buildJson() { return String("{"temp":") + num(t) + ","hum":" + num(h, 0) + ","hPa":" + num(p, 0) + "}"; }
void setup() {
  Serial.begin(115200);
  Wire.begin(21, 22);
  if (!bme.begin(0x76) && !bme.begin(0x77)) Serial.println("BME280 not found");
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  connectWiFi();
  startWeb();
}
void loop() {
  server.handleClient();
  static uint32_t tm = 0;
  if (millis() - tm > 2000) {
    tm = millis(); t = bme.readTemperature(); h = bme.readHumidity(); p = bme.readPressure() / 100.0;
    oled.clearDisplay(); oled.setTextColor(WHITE); oled.setTextSize(2);
    oled.setCursor(0, 0);  oled.print(t, 1); oled.print(" C");
    oled.setCursor(0, 24); oled.print(h, 0); oled.print(" %");
    oled.setCursor(0, 48); oled.print(p, 0); oled.print(" hPa");
    oled.display();
  }
}

Build tips

  • Keep the BME280 away from the ESP32 chip: self-heating adds 1–3 °C.
  • Use address 0x76 or 0x77 depending on the module.

What you need

Buy the parts kit · Estimated total: $11.00

ESP32 DevKit V1 (30 pin, WROOM-32) × 1
$4.00
Buy at AliExpress Buy at Amazon.com
BME280 I2C module (3.3V) × 1
$3.00
Buy at AliExpress Buy at Amazon.com
OLED 0.96" 128x64 I2C SSD1306 × 1
$2.50
Buy at AliExpress Buy at Amazon.com
Dupont jumper wires (M-F, M-M) × 1
$1.50
Buy at AliExpress Buy at Amazon.com
🇺🇦 Ukraine🌍 Other countries

Other countries: order these parts on AliExpress with the links below.

Some links are affiliate links: we may earn a commission at no extra cost to you.

Related ideas

CO2 monitor

MH-Z19B CO2 meter with an OLED and a ventilation alert, handy for bedrooms and offices.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●○ Intermediate
  • Build time 1–2 h
Pick parts / kit

Dust PM2.5 air monitor

PMS5003 particle sensor plus BME280: PM1 / PM2.5 / PM10, temperature and humidity on a web page.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●○ Intermediate
  • Build time 1–2 h
Pick parts / kit

Network cabinet temperature watch

Two probes at the top and the bottom of a closet with the router, switch and NAS, and an alarm before the equipment overheats in summer.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●○○ Beginner
  • Build time 1–2 h
Pick parts / kit

← All module ideas →

Comments

No comments yet. Share your experience or ask a question.

Comments are moderated.