CO2-triggered ventilation
CO2換気アラート ・ CO2 联动通风
When CO2 rises, turn on a fan. Good for grow tents and closed rooms.
CO2が上がったらファンを回す。締め切った温室・部屋の換気に。
CO2 升高时开启风扇,适合密闭的温室或房间通风。
Parts (BOM)
Wiring
- M5Stack Core2 → Unit CO2 (grove_i2c)
- M5Stack Core2 → Unit Fan (grove_analog)
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.
- 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).
- 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.
- 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.
- 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.
- 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.
- 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
- Use a hysteresis gap (ON at 1000 ppm, OFF at 800 ppm) so the fan does not rapidly flicker on and off when CO2 hovers near one value. Adjust the numbers to suit your room or greenhouse.
- The Unit Fan is low-voltage and USB-safe. If you ever upgrade to a larger mains-powered fan through a relay, that involves household high voltage — have a qualified person wire it, and never touch mains wiring while plugged in.
- If the screen shows no number or an error, check that both red Grove cables are clicked in fully and that you plugged into the red Port.A (I2C), not another color.
- CO2 sensors need a minute or two to warm up after power-on, so give it a moment before trusting the first readings.
Open the interactive diagram →
UnitKit — describe what you want to build, get a parts list and wiring diagram.