arduinoprojects

git clone https://git.tarina.org/arduinoprojects
Log | Files | Refs

CCS811_test.ino (1287B)


      1 /***************************************************************************
      2   This is a library for the CCS811 air
      3 
      4   This sketch reads the sensor
      5 
      6   Designed specifically to work with the Adafruit CCS811 breakout
      7   ----> http://www.adafruit.com/products/3566
      8 
      9   These sensors use I2C to communicate. The device's I2C address is 0x5A
     10 
     11   Adafruit invests time and resources providing this open source code,
     12   please support Adafruit andopen-source hardware by purchasing products
     13   from Adafruit!
     14 
     15   Written by Dean Miller for Adafruit Industries.
     16   BSD license, all text above must be included in any redistribution
     17  ***************************************************************************/
     18 
     19 #include "Adafruit_CCS811.h"
     20 
     21 Adafruit_CCS811 ccs;
     22 
     23 void setup() {
     24   Serial.begin(9600);
     25 
     26   Serial.println("CCS811 test");
     27 
     28   if(!ccs.begin()){
     29     Serial.println("Failed to start sensor! Please check your wiring.");
     30     while(1);
     31   }
     32 
     33   // Wait for the sensor to be ready
     34   while(!ccs.available());
     35 }
     36 
     37 void loop() {
     38   if(ccs.available()){
     39     if(!ccs.readData()){
     40       Serial.print("CO2: ");
     41       Serial.print(ccs.geteCO2());
     42       Serial.print("ppm, TVOC: ");
     43       Serial.println(ccs.getTVOC());
     44     }
     45     else{
     46       Serial.println("ERROR!");
     47       while(1);
     48     }
     49   }
     50   delay(500);
     51 }