Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
|