CO2-Monitor
MH-Z19B-CO2-Messgerät mit OLED und Lüftungswarnung, praktisch für Schlafzimmer und Büros.
BME280 plus OLED: Temperatur, Luftfeuchte und Druck auf dem Display, einer Webseite und in Home Assistant.
Klima & Heizung Board: ESP32 DevKit V1 (WROOM-32) Level: ●○○ ⏱ 1 Std.
Viele billige Platinen, die als BME280 verkauft werden, sind in Wirklichkeit BMP280, der gar keine Feuchte misst. Lesen Sie die Chip-ID im Sketch: 0x60 ist ein BME280, 0x58 ein BMP280. Die I2C-Adresse ist je nach Platine 0x76 oder 0x77.
ESP32 und OLED heizen die kleine Platine auf, ein Messwert im geschlossenen Gehäuse kann also ein bis zwei Grad zu hoch sein. Halten Sie den Sensor an einem kurzen Kabel fern vom Prozessor oder schlafen Sie zwischen den Messungen. Der Druck vom Sensor ist der Stationsdruck; für den Vergleich mit Wetterberichten wenden Sie eine Höhenkorrektur an.
| Modul | Modul-Pin | ESP32-Pin | Hinweis |
|---|---|---|---|
| BME280 SDA / SCL | I2C | GPIO21 / GPIO22 | address 0x76 or 0x77 |
| OLED SDA / SCL | I2C | GPIO21 / GPIO22 | address 0x3C |
| VCC / GND | 3V3 / GND |
#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();
}
}
Teile-Set kaufen · Geschätzte Summe: €10.12
Andere Länder: Bestellen Sie diese Teile über die Links unten bei AliExpress.
Einige Links sind Affiliate-Links: Wir erhalten ggf. eine Provision, für dich entstehen keine Mehrkosten.
MH-Z19B-CO2-Messgerät mit OLED und Lüftungswarnung, praktisch für Schlafzimmer und Büros.
PMS5003-Partikelsensor plus BME280: PM1 / PM2.5 / PM10, Temperatur und Feuchte auf einer Webseite.
Zwei Fühler oben und unten im Schrank mit Router, Switch und NAS und ein Alarm, bevor die Geräte im Sommer überhitzen.
Kommentare
Noch keine Kommentare. Teilen Sie Ihre Erfahrung oder stellen Sie eine Frage.