Projects / Office CO2 ventilation advisor

Office CO2 ventilation advisor

Beginner1.5 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32

    Wire the sensor

    Connect I2C and power and read ppm on the serial monitor.

  2. ESP32

    Check outdoor air

    Place near an open window and expect about 400 to 500 ppm.

  3. ESP32

    Breathe near it

    Briefly breathe towards the sensor and see the value jump.

  4. ESP32USB9.2 mA

    Add the ring

    Wire the data line through 330 Ω and check the colours.

  5. ESP32ON

    Add the relay and fan

    Wire the 12 V side with the common ground.

  6. ESP32

    Test thresholds

    Close the room for a while and watch the fan start above 1200 ppm.

  7. ESP32

    Mount

    Fix it at head height away from the door.

In short

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

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
SCD40 VCCESP32 3V3Power, check your module's rating
SCD40 GNDESP32 GNDGround
SCD40 SDAESP32 GPIO21I2C data
SCD40 SCLESP32 GPIO22I2C clock
LED ring VCCESP32 VIN (5 V from USB)Power
LED ring GNDESP32 GNDGround
LED ring DIN330 Ω resistor then ESP32 GPIO5Data line
Relay module VCC12 V adapter +Coil supply for a 12 V module
Relay module INESP32 GPIO4Control, check it triggers at 3.3 V
12 V adapter +Relay COMFan supply
Relay NOFan +Switched
Fan - and adapter -ESP32 GNDCommon 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.

CheckExpected
Fresh airAbout 400 to 500 ppm and green
After breathing near itReading rises quickly
Above 1200 ppmRed and fan on
Below 800 ppmGreen 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 →

Ask Lark AI

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.