Example Code for Arduino-Get Data
Input the baseline value to the function `sensor.writeBaseLine();`If you don't want to set the baseline, please disable this function in the sample program. The sensor will automatically calibrate the baseline, but it would be a pretty long process. after the function uploaded to UNO, open the serial port monitor to check the carbide dioxide concentration and TVOC concentration.
Hardware Preparation
- DFRduino UNO R3 (or similar) x 1
- Gravity: CCS811 Air Quality Sensor x 1
- Jumper wires
Software Preparation
- Arduino IDE
- Download and install the CCS811 Library and examples. (About how to install the library?)
Wiring Diagram

Other Preparation Work
Please run the sensor for 48hours when using it for the first time.
Sample Code
/*!
* @file readData.ino
* @brief Read the concentration of carbon dioxide and TVOC
* @n Experiment phenomenon: read data every 0.5s, and print it out on serial port.
*
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @licence The MIT License (MIT)
* @author [LuoYufeng]([email protected])
* @version V0.1
* @date 2019-07-19
* @get from https://www.dfrobot.com
* @url https://github.com/DFRobot/DFRobot_CCS811
*/
#include "DFRobot_CCS811.h"
/*
* IIC address default 0x5A, the address becomes 0x5B if the ADDR_SEL is soldered.
*/
//DFRobot_CCS811 CCS811(&Wire, /*IIC_ADDRESS=*/0x5A);
DFRobot_CCS811 CCS811;
void setup(void)
{
Serial.begin(115200);
/*Wait for the chip to be initialized completely, and then exit*/
while(CCS811.begin() != 0){
Serial.println("failed to init chip, please check if the chip connection is fine");
delay(1000);
}
}
void loop() {
if(CCS811.checkDataReady() == true){
Serial.print("CO2: ");
Serial.print(CCS811.getCO2PPM());
Serial.print("ppm, TVOC: ");
Serial.print(CCS811.getTVOCPPB());
Serial.println("ppb");
} else {
Serial.println("Data is not ready!");
}
/*!
* @brief Set baseline
* @param get from getBaseline.ino
*/
CCS811.writeBaseLine(0x447B);
//delay cannot be less than measurement cycle
delay(1000);
}
Result

Was this article helpful?
