/* This is the code for the AirGradient DIY CO2 Traffic light with an ESP8266 Microcontroller. For build instructions please visit https://www.airgradient.com/diy-co2-traffic-light/ Compatible with the following sensors: SenseAir S8 (CO2 Sensor) Please install ESP8266 board manager (tested with version 3.0.0) Please install the following libraries: AirGradient Adafruit NeoPixel Library 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 #include Adafruit_NeoPixel pixels(64, D8, NEO_GRB + NEO_KHZ800); AirGradient ag = AirGradient(); void setup(){ Serial.begin(9600); ag.CO2_Init(); pixels.begin(); pixels.setBrightness(24); } void loop(){ int CO2 = ag.getCO2_Raw(); Serial.print("C02: "); Serial.println(ag.getCO2()); if (CO2 > 1200) { showColor("red"); } else if (CO2 > 800) { showColor("orange"); } else { showColor("green"); } delay(10000); } void showColor(String clr) { pixels.clear(); if (clr=="green"){ for(int i=0; i<65; i++) { pixels.setPixelColor(i, 0, 255, 0); } } if (clr=="orange"){ for(int i=0; i<65; i++) { pixels.setPixelColor(i, 255, 99, 0); } } if (clr=="red"){ for(int i=0; i<65; i++) { pixels.setPixelColor(i, 255, 0, 0); } } pixels.show(); }