Office CO2 ventilation advisor
Build it step by step
0 of 7 doneWire the sensor
Connect I2C and power and read ppm on the serial monitor.
Check outdoor air
Place near an open window and expect about 400 to 500 ppm.
Breathe near it
Briefly breathe towards the sensor and see the value jump.
Add the ring
Wire the data line through 330 Ω and check the colours.
Add the relay and fan
Wire the 12 V side with the common ground.
Test thresholds
Close the room for a while and watch the fan start above 1200 ppm.
Mount
Fix it at head height away from the door.
How do you build an office CO2 ventilation advisor?
A traffic light shows when a room needs fresh air, with a relay link to a fan. You need ESP32 DevKit V1, SCD40 CO2 sensor, WS2812B ring 16 LEDs, Relay module 1-channel 12 V, 12 V DC fan 80 mm, 12 V 2 A DC adapter, Resistor 330 Ω and USB A to micro-USB cable (data). It takes 7 steps and about 90 minutes.
- Level
- Beginner
- Time
- About 90 min
- Parts
- 8
Parts list
- Development BoardsBuyESP32 DevKit V1 × 1
- SensorsBuySCD40 CO2 sensor × 1
- OptoelectronicsBuy
- InterfacesBuy
- Motors & ActuatorsBuy
- PowerBuy
- PassivesBuyResistor 330 Ω × 1
- Cables & WiresBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| SCD40 VCC | ESP32 3V3 | Power, check your module's rating |
| SCD40 GND | ESP32 GND | Ground |
| SCD40 SDA | ESP32 GPIO21 | I2C data |
| SCD40 SCL | ESP32 GPIO22 | I2C clock |
| LED ring VCC | ESP32 VIN (5 V from USB) | Power |
| LED ring GND | ESP32 GND | Ground |
| LED ring DIN | 330 Ω resistor then ESP32 GPIO5 | Data line |
| Relay module VCC | 12 V adapter + | Coil supply for a 12 V module |
| Relay module IN | ESP32 GPIO4 | Control, check it triggers at 3.3 V |
| 12 V adapter + | Relay COM | Fan supply |
| Relay NO | Fan + | Switched |
| Fan - and adapter - | ESP32 GND | Common ground |
Code
The SCD40 measures CO2 directly with a photoacoustic sensor and reports a new value every 5 seconds. Outdoor air is about 420 ppm; many guidance values treat under 800 as good, 800 to 1200 as getting stale and over 1200 as a sign to ventilate. The fan switches on above 1200 and off below 800, so it does not flicker. A 12 V relay module may not trigger from a 3.3 V pin; test it, and if it does not click, drive the input through a transistor or use a 3.3 V logic relay module. Keep the sensor away from your breath and from windows, and do not read the first minutes after power-up as stable. This is a ventilation helper and not a health monitor. Arduino IDE with the ESP32 boards package, board "ESP32 Dev Module".
Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Libraries: SparkFun SCD4x, Adafruit NeoPixel.
#include <Wire.h>
#include <SparkFun_SCD4x_Arduino_Library.h>
#include <Adafruit_NeoPixel.h>
SCD4x scd;
Adafruit_NeoPixel ring(16, 5, NEO_GRB + NEO_KHZ800);
const byte RELAY = 4;
bool fanOn = false;
void setColour(uint8_t r, uint8_t g, uint8_t b) {
for (int i = 0; i < 16; i++) ring.setPixelColor(i, ring.Color(r, g, b));
ring.show();
}
void setup() {
Serial.begin(115200);
pinMode(RELAY, OUTPUT); digitalWrite(RELAY, LOW);
Wire.begin(21, 22);
ring.begin(); ring.setBrightness(40); setColour(0, 0, 40);
if (!scd.begin()) { Serial.println("SCD40 not found"); while (1) {} }
}
void loop() {
if (scd.readMeasurement()) { // a new reading arrives every 5 seconds
int co2 = scd.getCO2();
Serial.print(co2); Serial.println(" ppm");
if (co2 < 800) setColour(0, 80, 0); // green
else if (co2 < 1200) setColour(80, 50, 0); // amber
else setColour(100, 0, 0); // red
if (co2 > 1200 && !fanOn) { fanOn = true; digitalWrite(RELAY, HIGH); }
if (co2 < 800 && fanOn) { fanOn = false; digitalWrite(RELAY, LOW); }
}
delay(500);
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual ESP32 Dev Module with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
SCD40 not found
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Fresh air | About 400 to 500 ppm and green |
| After breathing near it | Reading rises quickly |
| Above 1200 ppm | Red and fan on |
| Below 800 ppm | Green and fan off |
If it does not work
Sensor not found
Check SDA and SCL and the power voltage.
Ring shows wrong colours
Try NEO_RGB instead of NEO_GRB.
Relay does not click
Check the 12 V supply and the trigger voltage.
Reading looks stuck
Wait for the 5 second update.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the office CO2 ventilation advisor?
ESP32 DevKit V1, SCD40 CO2 sensor, WS2812B ring 16 LEDs, Relay module 1-channel 12 V, 12 V DC fan 80 mm, 12 V 2 A DC adapter, Resistor 330 Ω and USB A to micro-USB cable (data).
How long does the office CO2 ventilation advisor take to build?
About 90 minutes for a beginner maker, in 7 steps.
How do I know the office CO2 ventilation advisor works?
Fresh air: About 400 to 500 ppm and green. After breathing near it: Reading rises quickly. Above 1200 ppm: Red and fan on.
Sensor not found: what should I check?
Check SDA and SCL and the power voltage.
Ring shows wrong colours: what should I check?
Try NEO_RGB instead of NEO_GRB.
Relay does not click: what should I check?
Check the 12 V supply and the trigger voltage.
Reading looks stuck: what should I check?
Wait for the 5 second update.
