HA CO2 Temperature Humidity WiFi | SCD40 + ESP32 S2 Mini

HA CO2 Temperature Humidity WiFi | SCD40 + ESP32 S2 Mini

Enhance Your Home Assistant with an ESP32 S2 Mini and SCD40 Sensor

Monitoring air quality is essential for a healthier living environment. With an ESP32 S2 Mini and an SCD40 sensor, you can easily track CO2 levels, temperature, and humidity directly from Home Assistant using ESPHome. This guide explains how I’ve done it.

Why Use the SCD40 Sensor?

The Sensirion SCD40 is a compact CO2 sensor known for its high accuracy and reliability. It provides:

  • CO2 Monitoring: Helps maintain optimal indoor air quality.
  • Temperature and Humidity Tracking: Essential for climate control and comfort.
  • I2C Communication: Easy integration with ESP-based devices.

Required Components

To get started, you’ll need:

  • SCD40 SensorBuy here
  • ESP32 S2 MiniBuy here
  • 4 Dupont Cables – For connections
  • ESPHome Installed on Home Assistant

Wiring the SCD40 to ESP32 S2 Mini

The SCD40 sensor communicates via I2C, requiring only two data lines:

  • SDA (Data Line) → Connect to GPIO 8 on ESP32 S2 Mini
  • SCL (Clock Line) → Connect to GPIO 9 on ESP32 S2 Mini
  • VCC (Power) → Connect to 3.3V
  • GND (Ground) → Connect to GND

ESPHome Code

Add the following YAML configuration to your ESPHome setup:

esphome:
  name: sensore-scd40
  friendly_name: Sensore SCD40

esp32:
  board: lolin_s2_mini
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: ""

ota:
  - platform: esphome
    password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Fallback Hotspot"
    password: ""

captive_portal:
    
i2c:
  sda: 8
  scl: 9
  scan: true

sensor:
  - platform: scd4x
    co2:
      name: "SCD40 CO2"
    temperature:
      name: "SCD40 Temperature"
    humidity:
      name: "SCD40 Humidity"
    address: 0x62
    update_interval: 10s

Integrating with Home Assistant

Once uploaded, your ESP32 S2 Mini will appear in Home Assistant. Add it through ESPHome Integration, and you’ll see live readings of CO2, temperature, and humidity in your dashboard.

Final Thoughts

Using an ESP32 S2 Mini with an SCD40 sensor is a cost-effective way to monitor air quality in real-time. With ESPHome and Home Assistant, you can automate ventilation, receive alerts for high CO2 levels, and optimize indoor comfort.

Would you like to see more projects like this? Let me know in the comments!