CO2 Traffic Light with AirGradient DIY Sensor

by Achim Haug

If you have our AirGradient DIY Kit with the CO2 sensor, there is a very simple way to build a stand-alone CO2 traffic light.

This built will show you the current CO2 levels in the room in three easy to see colors: Green, Orange and Red.

This is an easy way to tell you when you should get fresh air into the room. High CO2 not only decrease your cognitive performance but also increases the risk of virus transmission.

So this built could be especially interesting for schools to know when they should open the windows for ventilation.

CO2 Color Bands

We have preconfigured the code with the following bands:

Green: <900 ppm CO2

Orange: 900 - 1400 ppm CO2

Red: > 1400 ppm CO2

If you like a different configuration it is easy to change in the code.

The Parts

So if you have our kit, the only additional component you need is the RGB LED shield:

RGB LED Shield V1.0.0 for LOLIN (WEMOS) D1 mini

If you do not have the kit yet, please check our DIY Shop.

The Built

Please follow the DIY Kit Build Instructions but you only need to solder the Wemos D1 mini and the CO2 sensor.

The RGBLed can fit on top of the D1 Mini the same way as the OLED display of the kit. However you need to adjust the RGB shield to use pin D8 instead of the default D4. To do this, add a solder bridge at D8 and remove the connection on D4.

Once your built is done, it should look like this:

Please be careful of your eyes once you switch it on. The LEDs can be very bright. Best is you 3D print our enclosure. The LEDs will shine very nicely through the enclosure.

The Code

In the Arduino library manager install the Adafruit NeoPixel Library. I used version 1.10.0 that works well. Please also say Yes when it asks you to install dependent libraries.

Once you installed the library, just paste the code below and flash it to the Wemos D1.

This code does not send any data to a backend server but you can combine it with the sample code for the Wifi connection.

/*
This is the code for the AirGradient DIY Air Quality Sensor with an ESP8266 Microcontroller.

It is a high quality sensor showing PM2.5, CO2, Temperature and Humidity on a small display and can send data over Wifi.

For build instructions please visit https://www.airgradient.com/diy/

Compatible with the following sensors:
SenseAir S8 (CO2 Sensor)

Please install ESP8266 board manager (tested with version 3.0.0)

If you are a school or university contact us for a free trial on the AirGradient platform.
https://www.airgradient.com/schools/

MIT License
*/

#include <Adafruit_NeoPixel.h>
#include <AirGradient.h>

Adafruit_NeoPixel pixels(7, D8, NEO_GRB + NEO_KHZ800);
AirGradient ag = AirGradient();


void setup(){
  Serial.begin(9600);
  ag.CO2_Init();
  pixels.begin();
}

void loop(){
int CO2 = ag.getCO2_Raw();
Serial.print("C02: ");
Serial.println(ag.getCO2());

if (CO2 > 1400) {
  showColor("red");
} else if (CO2 > 900) {
  showColor("orange");
} else {
  showColor("green");
}

delay(10000);
}

void showColor(String clr) {
  
pixels.clear();

if (clr=="green"){
  for(int i=0; i<8; i++) { 
    pixels.setPixelColor(i, 0, 255, 0);
    pixels.show();   
  }
}

if (clr=="orange"){
  for(int i=0; i<8; i++) { 
    pixels.setPixelColor(i, 255, 99, 0);
    pixels.show();   
  }
}

if (clr=="red"){
  for(int i=0; i<8; i++) { 
    pixels.setPixelColor(i, 255, 0, 0);
    pixels.show();   
  }
}

}

We will also add this example code into our library in one of the next updates.