Arduino Wiring & Test

You can easily wire this breakout to any microcontroller, we'll be using an Adafruit Metro (Arduino compatible) with the Arduino IDE. But, you can use any other kind of microcontroller as well as long as it has I2C clock and I2C data lines. Note this chip uses clock stretching so make sure your microcontroller supports that in hardware!

I2C Wiring

  • Connect Vin to the power supply, 3-5V is fine. Use the same voltage that the microcontroller logic is based off of. For most Arduinos, that is 5V
  • Connect GND to common power/data ground
  • Connect the SCL pin to the I2C clock SCL pin on your Arduino. 
    On an UNO & '328 based Arduino, this is also known as A5, on a Mega it is also known as digital 21 and on a Leonardo/Micro, digital 3
  • Connect the SDA pin to the I2C data SDA pin on your Arduino. 
    On an UNO & '328 based Arduino, this is also known as A4, on a Mega it is also known as digital 20 and on a Leonardo/Micro, digital 2
  • Connect the WAKE pin to ground.

This sensor uses I2C address 0x5A.

Don't forget to tie WAKE to Ground - this is required!

Download Adafruit_CCS811 library

To begin reading sensor data, you will need to download Adafruit_CCS811 from our github repository. You can do that by visiting the github repo and manually downloading or, easier, just click this button to download the zip

Rename the uncompressed folder Adafruit_CCS811 and check that the Adafruit_CCS811 folder contains Adafruit_CCS811 .cpp and Adafruit_CCS811 .h

Place the Adafruit_CCS811 library folder your arduinosketchfolder/libraries/ folder. 
You may need to create the libraries subfolder if its your first library. Restart the IDE.

We also have a great tutorial on Arduino library installation at:
http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use

Load Test Example

Open up File->Examples->Adafruit_CCS811->CCS811_test and upload to your Arduino wired up to the sensor. This example connects to the sensor and starts taking readings.

Once uploaded to your Arduino, open up the serial console at 9600 baud speed to see the readings. Your sensor will take 3 zero readings while it does some internal calibration and correction things and then start outputting real data. In clean air and a typical indoor space your serial monitor will look something like this:

AMS recommends that you run this sensor for 48 hours when you first receive it to "burn it in", and then 20 minutes in the desired mode every time the sensor is in use. This is because the sensitivity levels of the sensor will change during early use.

Library Reference

To create the object, use

Download: file
Adafruit_CCS811 ccs;

initialize the sensor with:

Download: file
if(!ccs.begin()){
    Serial.println("Failed to start sensor! Please check your wiring.");
    while(1);
  }

To poll the sensor for available data you can use:

Download: file
bool dataAvailable = ccs.available(); //returns true if data is available to be read

Data can be read using:

Download: file
bool error = ccs.readData(); //returns True if an error occurs during the read

and then the readings can be accessed with:

Download: file
int eCO2 = ccs.geteCO2(); //returns eCO2 reading
int TVOC = ccs.getTVOC(); //return TVOC reading

Approximate ambient temperature can be read using:

Download: file
float temp = ccs.calculateTemperature();
This guide was first published on Aug 02, 2017. It was last updated on Aug 02, 2017. This page (Arduino Wiring & Test) was last updated on Jan 15, 2018.