/*** * ____ ___ ____ _ _ * / ___/ _ \___ \ / \ _ __ ___ _ __ ___| | * | | | | | |__) | / _ \ | '_ ` _ \| '_ \ / _ \ | * | |__| |_| / __/ / ___ \| | | | | | |_) | __/ | * \____\___/_____| /_/__ \_\_| |_| |_| .__/ \___|_| _ * | | | |/ _|_ _| / ___|| |_ _ _| |_| |_ __ _ __ _ _ __| |_ * | |_| | |_ | | \___ \| __| | | | __| __/ _` |/ _` | '__| __| * | _ | _| | | ___) | |_| |_| | |_| || (_| | (_| | | | |_ * |_| |_|_| |_| |____/ \__|\__,_|\__|\__\__, |\__,_|_| \__| * |___/ */ // Small example, with CO2 sensor and LED ring. // Required libraries: // LED Ring: #include "src/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.h" // CO2 sensor: #include "src/lib/SparkFun_SCD30_Arduino_Library/src/SparkFun_SCD30_Arduino_Library.h" #include // How many LEDs on the ring? const int LED_COUNT = 12; // Where is LED ring connected to micro-controller? const int NEOPIXELS_PIN = 5; // Define LED ring and CO2 sensor Adafruit_NeoPixel led_ring(LED_COUNT, NEOPIXELS_PIN, NEO_GRB + NEO_KHZ800); SCD30 sensor; // Define variables int which_led; uint16_t co2; // The code in setup() will be run once, at startup. void setup() { // Transmission speed Serial.begin(115200); // Initialize LED ring. led_ring.begin(); led_ring.setBrightness(255); // Initialize sensor (should be connected to D6 & D5), without auto-calibration. Wire.begin(12, 14); sensor.begin(false); // One measurement every 10s sensor.setMeasurementInterval(10); } // The code in loop() will be run as long as the micro-controller is powered up, in an infinite loop. void loop() { if (sensor.dataAvailable()) { // New measurement is available. Let's display it! co2 = sensor.getCO2(); Serial.print("CO2 : "); Serial.print(co2); Serial.println(" ppm."); } // Light the next LED which_led = which_led + 1; // Come back to first LED if needed. if (which_led >= LED_COUNT) { which_led = 0; } // First, disable every LED led_ring.clear(); // Check if air is good enough if (co2 <= 1000) { // Light the LED green if CO2 ppm is low // position, red, green, blue led_ring.setPixelColor(which_led, 0, 255, 0); } else { // Red otherwise. // position, red, green, blue led_ring.setPixelColor(which_led, 255, 0, 0); } led_ring.show(); // Wait half a second before next loop. // Micro-controller might crash if it has too much work to do. Please don't remove it! delay(500); }