diff --git a/Ardunio_CCS811.ino b/Ardunio_CCS811.ino new file mode 100644 index 0000000..530d093 --- /dev/null +++ b/Ardunio_CCS811.ino @@ -0,0 +1,62 @@ +/*************************************************************************** + This is a library for the CCS811 air + + This sketch reads the sensor + + Designed specifically to work with the Adafruit CCS811 breakout + ----> http://www.adafruit.com/products/3566 + + These sensors use I2C to communicate. The device's I2C address is 0x5A + + Adafruit invests time and resources providing this open source code, + please support Adafruit andopen-source hardware by purchasing products + from Adafruit! + + Written by Dean Miller for Adafruit Industries. + BSD license, all text above must be included in any redistribution + ***************************************************************************/ + +#include "Adafruit_CCS811.h" + +Adafruit_CCS811 ccs; + +void setup() { + Serial.begin(115200); + + Serial.println("CCS811 Reading CO2 and VOC"); + Sensor_ON(); + if(!ccs.begin()){ + Serial.println("Failed to start sensor! Please check your wiring."); + while(1); + } + //calibrate temperature sensor + while(!ccs.available()); + float temp = ccs.calculateTemperature(); + ccs.setTempOffset(temp - 25.0); +} + +void loop() { + if(ccs.available()){ + float temp = ccs.calculateTemperature(); + if(!ccs.readData()){ + Serial.println("CO2: "+String(ccs.geteCO2())+"ppm, TVOC: "+String(ccs.getTVOC())+"ppb Temp:"+String(temp)); + } + else{ + Serial.println("Sensor read ERROR!"); + ccs.readData(); + } + } + delay(500); +} + +void Sensor_ON(){ + pinMode(A3,OUTPUT); + digitalWrite(A3, LOW); +} + +void Sensor_OFF(){ + pinMode(A3,OUTPUT); + digitalWrite(A3, HIGH); +} + +