CO2-triggered ventilation

CO2換気アラート ・ CO2 联动通风

When CO2 rises, turn on a fan. Good for grow tents and closed rooms.

CO2が上がったらファンを回す。締め切った温室・部屋の換気に。

CO2 升高时开启风扇,适合密闭的温室或房间通风。

Parts (BOM)

PartRolePortsLinks
M5Stack Core2 Controller grove_i2c, grove_analog, grove_uart, mbus official page
Unit CO2 CO2 sensor grove_i2c official page
Unit Fan Ventilation fan grove official page

Wiring

How to build

A simple greenhouse helper that watches the CO2 level in the air. When CO2 rises above a safe level, the M5Stack Core2 turns on a ventilation fan to bring in fresh air, then turns it off once the air clears. Everything snaps together with plug-in Grove cables, so no soldering is needed.

  1. Lay out the parts — Place the three parts on your desk: the M5Stack Core2 (the screen unit, this is the brain), the Unit CO2 sensor, and the Unit Fan. You should also have two red Grove cables (they usually come in the boxes).
  2. Connect the CO2 sensor to the Core2 — Both the CO2 sensor and the Fan use I2C, which is the red Port.A. Plug one red Grove cable from the Core2's red Port.A into the Unit CO2 sensor. The connectors only fit one way, so push gently until it clicks.
  3. Daisy-chain the Fan to the sensor — Because I2C devices can share one line, plug the second red Grove cable from the spare I2C socket on the Unit CO2 into the Unit Fan. Now the Core2 talks to both the sensor and the fan over the same red I2C bus.
  4. Power up and prepare to flash — Connect the Core2 to your computer with a USB-C cable and turn it on (press the power button on the left side). Install the UIFlow / Thonny tool with MicroPython for Core2 if you have not already, and select the correct USB port.
  5. Flash the program — Copy the MicroPython sketch below into the editor and run/upload it to the Core2. The screen should start showing a CO2 number after a few seconds.
  6. Test it — Breathe gently toward the CO2 sensor from a short distance. The reading should climb; when it passes the threshold the fan switches on. Step away and the reading falls, and the fan turns off. If it reacts, your build works.

Sample code (micropython)

# CO2-triggered ventilation for M5Stack Core2
# Fan turns ON when CO2 is high, OFF when air clears.
from m5stack import lcd
import unit            # M5 Unit library
import time

# Both units are on the red Port.A (I2C).
co2 = unit.get(unit.CO2, unit.PORTA)   # Unit CO2 sensor
fan = unit.get(unit.FAN, unit.PORTA)   # Unit Fan (shares the I2C bus)

ON_LEVEL  = 1000   # ppm: turn fan ON above this
OFF_LEVEL = 800    # ppm: turn fan OFF below this (gap avoids flicker)
running = False

while True:
    ppm = co2.co2ppm        # read CO2 in ppm
    if ppm > ON_LEVEL:
        running = True
    elif ppm < OFF_LEVEL:
        running = False

    # fan.speed(0-100). If your library differs, adjust here.
    fan.speed(100 if running else 0)

    lcd.clear()
    lcd.print('CO2: %d ppm' % ppm, 10, 40)
    lcd.print('Fan: %s' % ('ON' if running else 'OFF'), 10, 80)
    time.sleep(2)

Tips & safety

Open the interactive diagram →

UnitKit — describe what you want to build, get a parts list and wiring diagram.