Skip to content

Instantly share code, notes, and snippets.

@ghtomcat
Created October 29, 2020 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ghtomcat/92dc282cc27d254b09708ed1ba1b3d47 to your computer and use it in GitHub Desktop.
Save ghtomcat/92dc282cc27d254b09708ed1ba1b3d47 to your computer and use it in GitHub Desktop.
/***************************************************************************
This is a library for the BME680 gas, humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BME680 Breakout
----> http://www.adafruit.com/products/3660
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
to interface.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing products
from Adafruit!
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
***************************************************************************/
#include <Wire.h>
#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD30
SCD30 airSensor;
#include <Adafruit_NeoPixel.h>
#define PIN 4
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(11, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(115200);
Wire.begin();
airSensor.begin();
delay(5000);
strip.begin();
strip.setBrightness(64);
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
if (airSensor.dataAvailable())
{
Serial.print("co2(ppm):");
Serial.print(airSensor.getCO2());
Serial.print(" temp(C):");
Serial.print(airSensor.getTemperature(), 1);
Serial.print(" humidity(%):");
Serial.print(airSensor.getHumidity(), 1);
Serial.println();
int ppm=airSensor.getCO2();
int c;
if (ppm>2000) { c=strip.Color(255,0,0); }
if (ppm>1000 && ppm<2000) { c=strip.Color(255,165,0); }
if (ppm<1000) { c=strip.Color(0,128,0); }
int ct=map(ppm, 0, 2000, 1, 11);
for(uint16_t i=0; i<strip.numPixels(); i++) {
if (i<=ct) {
strip.setPixelColor(i, c);
} else {
strip.setPixelColor(i, strip.Color(0,0,0));
}
}
strip.show();
} else {
Serial.println("Waiting for new data");
delay(500);
}
delay(2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment