Connect a Sensirion SCD40 CO2 sensor to an ESP8266 D1 mini and run it with ESPHome. This allows you to measure CO2, temperature, and humidity in your room and integrate the data into Home Assistant, Prometheus, or MQTT.
| SCD40 | ESP8266 |
|---|---|
| VCC | 3V3 |
| GND | G |
| SCL | D1 (GPIO5) |
| SDA | D2 (GPIO4) |
The white sticker on the SCD40 module is a protective membrane and must remain in place.
Use the provided scd40.yaml configuration with ESPHome. It includes support for CO2, temperature, humidity, captive portal, OTA upgrades, MQTT, Prometheus metrics, and manual baseline calibration.
Flash the firmware the first time via USB with esphome run scd40.yaml. Subsequent updates can be done wirelessly using OTA.
Enable the ESPHome API integration in Home Assistant. Entities for CO2, temperature, humidity, Wi-Fi RSSI, and uptime will be available automatically. MQTT integration is also possible if desired.
ESPHome can expose Prometheus metrics at the /metrics endpoint when the web_server and prometheus components are enabled. Use a Prometheus server running on another machine to scrape these metrics and visualize them with Grafana.
The configuration includes a manual calibration feature. Ventilate the room with fresh outdoor air, then trigger calibration with the exposed button entity. The sensor will adjust its baseline to the specified target ppm value.