Temperature & humidity station
BME280 plus an OLED screen: temperature, humidity and pressure on the display, a web page and Home Assistant.
Reads PM1.0 / PM2.5 / PM10 particles and classifies air quality. Useful during smoke and dust seasons.
Level: Intermediate Board: ESP32 DevKit V1 (WROOM-32) Climate
The PMS5003 fan needs 5 V; its data pins are 3.3 V logic.
Buy the parts kit · Estimated total: $20.50
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.
| Module | Module pin | ESP32 pin | Note |
|---|---|---|---|
| PMS5003 VCC / GND | 5V / GND | ||
| PMS5003 TX | UART | GPIO16 (RX2) | |
| PMS5003 RX | UART | GPIO17 (TX2) | optional |
#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 <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();
}
int pm1 = -1, pm25 = -1, pm10 = -1;
bool readPMS() {
static uint8_t b[32]; int n = 0; uint32_t t0 = millis();
while (millis() - t0 < 2000) {
if (!Serial2.available()) continue;
uint8_t c = Serial2.read();
if (n == 0 && c != 0x42) continue;
if (n == 1 && c != 0x4D) { n = 0; continue; }
b[n++] = c;
if (n == 32) {
uint16_t sum = 0; for (int i = 0; i < 30; i++) sum += b[i];
if (sum != (uint16_t)(b[30] << 8 | b[31])) return false;
pm1 = b[10] << 8 | b[11]; pm25 = b[12] << 8 | b[13]; pm10 = b[14] << 8 | b[15];
return true;
}
}
return false;
}
String buildJson() { return String("{\"PM1\":") + pm1 + ",\"PM2_5\":" + pm25 + ",\"PM10\":" + pm10 + "}"; }
void setup() {
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, 16, 17);
connectWiFi();
startWeb();
}
void loop() {
server.handleClient();
static uint32_t t = 0;
if (millis() - t > 3000) { t = millis(); readPMS(); }
}Flash a ready firmware from the browser Paste your error into the AI Error Doctor
BME280 plus an OLED screen: temperature, humidity and pressure on the display, a web page and Home Assistant.
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.
MH-Z19B CO2 meter with an OLED and a ventilation alert, handy for bedrooms and offices.
Comments
No comments yet. Share your experience or ask a question.