Overview
In this tutorial, we will interface CO2 & TVOC Gas Sensor CCS811 with Arduino & measure CO2 & TVOC in the air. The CCS811 Air Quality Breakout Board is a digital gas sensor capable of sensing a wide range of Total Volatile Organic Compounds (TVOC) & equivalent carbon dioxide (eCO2) with metal oxide (MOX) levels. We can thus use this sensor to identify the air quality whether the air is pure to breathe or not. You can also check SPG30 Air Quality Sensor which is similar to CCS811.
Earlier we did some projects like Particulate Matter Concentration (PM2.5) Measurement & Air Quality Index (AQI) using PMS5003 or MQ135 Gas Sensor. Those sensors are very good to measure the Air quality but are not capable of measuring carbon dioxide level & Total Volatile Organic Compounds level. That is why CCS811 is the best sensor available in market to measure these parameters. The CCS811 is very tiny and ultra-low power consumption device that can be used in wearables and handheld device for monitoring Indoor Air Quality.
So, this is why we should make our own CO2 & TVOC Meter using CCS811 Gas Sensor & Arduino Board. In this tutorial, we will go through the construction, working, internal architecture, and pins configuration of CCS811. Then using the CCS811 Arduino Library we will write few example codes and retrieve the value of CO2 & TVOC and display them on Serial Monitor. Using a 0.96″ I2C OLED Display, we will display the CO2 & TVOC Value on OLED Screen.
Bill of Materials
The purchase link for CCS811 Gas Sensor along with all other required component is given below. You can purchase all of them from Amazon.
| S.N. | Components Name | Quantity | Purchase Links |
|---|---|---|---|
| 1 | Arduino Nano Board | 1 | Amazon | AliExpress |
| 2 | CCS811 CO2 TVOC Sensor | 1 | Amazon | AliExpress |
| 3 | 0.96" I2C OLED Display | 1 | Amazon | AliExpress |
| 4 | Connecting Wires | 10 | Amazon | AliExpress |
| 5 | Breadboard | 1 | Amazon | AliExpress |
CCS811 Air Quality Gas Sensor Module
Overview
The CCS811 Air Quality Sensor Breakout Board is a digital gas sensor that senses a wide range of Total Volatile Organic Compounds (TVOCs) along with equivalent carbon dioxide (eCO2) and metal oxide (MOX) levels. The sensor can be used for monitoring Indoor Air Quality. The system can be used with a microcontroller unit (MCU), which includes an Analog-to-Digital converter (ADC) & an I²C interface.
You can connect CCS811 to Arduino or any other microcontroller, you will get a Total Volatile Organic Compound (TVOC) reading and an equivalent carbon dioxide reading (eCO2). CCS811 supports intelligent algorithms to process raw sensor measurements to output a TVOC value or equivalent CO2 (eCO2) levels. The sensor can support multiple measurement modes like low-power consumption mode & idle mode for extending battery life in portable applications.
This sensor measure eCO2 concentration within a range of 400 to 8192 parts per million (ppm), and TVOC concentration within a range of 0 to 1187 parts per billion (ppb). Apart from these, it can also detect Alcohols, Aldehydes, Ketones, Organic Acids, Amines, Aliphatic and Aromatic Hydrocarbons. You can go through the CCS811 Datasheet for learning more about its architecture and construction.
Features of CCS811 Gas Sensor
- Integrated MCU
- Operating Voltage: 1.8V to 3.6V
- On-board processing
- A standard I²C digital interface with an I2C Address of 0x5A or 0X5B
- Optimized low-power modes
- 2.7mm x 4.0mm x 1.1mm LGA package
- Low component count
- Proven technology platform, Compact and economical
- eCO2 Measurement range: 400 to 8192ppm
- TVOC Measurement range: 0 to 1187ppb
- Multiple drive modes for measurements every 1s, 10s, 60s, or every 250ms
- Arduino and CircuitPython compatibility
- Integrated 12-bit ADC for sensor readings and digitized conversions
- Reset / interrupt control
CCS811 Pinout Configuration
1. VCC – This is the power pin. The sensor uses 3.3V to power the board.
2. GND – Common ground for power and logic.
3. SCL – This is the I2C clock pin pulled to VCC via a 10K resistor.
4. SDA – This is the I2C data pin pulled to VCC via a 10K resistor.
5. WAKE – This is the wake-up pin for the sensor. It needs to be pulled to the GND in order to communicate with the sensor. Pull this line high or VCC put the sensor to sleep.
6. INT – This is the interrupt-output pin. It is 3V logic and one can use it to detect when a new reading is ready or when the reading gets too high or too low.
7. RST – This is the reset pin. When it is pulled to GND the sensor resets itself.
8. ADD – Single address select bit to allow the alternate address to be selected. When ADDR is low the 7-bit I²C address is decimal 90 / hex 0x5A. When ADDR is high the 7-bit I²C address is decimal 91 / hex 0x5B.
Applications
This device can be mainly used for indoor air quality monitoring in:
1. Smart phones
2. Wearables Electronics
3. Home & Building automation
4. Hand-held Accessories<
5. Hand-held Accessories
How to use CCS811 Gas Sensor with Arduino?
Now let us interface CCS811 Air Quality Gas Sensor with Arduino and measure CO2 & TVOC. To do that, follow the following circuit diagram below.
Connect the Vin & GND pin of CCS811 to 3.3V & GND Pin of Arduino. Do not power the sensor with 5V as the sensor can support a maximum of 3.6V only. Connect the sensor SDA & SCL pin to Arduino A4 & A5 Pin respectively. Connect the WAKE pin of CCS811 to GND. Do not leave the WAKE pin empty as the controller won’t read the I2C Address.
CCS811 Arduino Library Installation
The CCS811 library is used for interfacing the CCS811 Sensor with Arduino. The Libray is written by both Adafruit and Sparkfun. You can use any of the library. The download link for both the libraries ais given below.
- Download: CCS811 Adafruit Library
- Download: CCS811 Sparkfun Library
You can also download these libraries from the library manager as well. Both of these libraries are available in Arduino Library Manager.
Source Code/Program CCS811 Arduino Basic Interfacing
Though you can use any of the libraries for retrieving the value of CO2 & TVOC, I used the Adafruit library. The source code is given below. The default I2C Address of CCS811 is 0x5A while some of the CCS811 has an I2C Address of 0X5B. You can modify the I2C Address in the library file.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#include "Adafruit_CCS811.h" Adafruit_CCS811 ccs; void setup() { Serial.begin(115200); Serial.println("CCS811 test"); if(!ccs.begin()){ Serial.println("Failed to start sensor! Please check your wiring."); while(1); } // Wait for the sensor to be ready while(!ccs.available()); } void loop() { if(ccs.available()){ if(!ccs.readData()){ Serial.print("CO2: "); Serial.print(ccs.geteCO2()); Serial.print("ppm, TVOC: "); Serial.println(ccs.getTVOC()); } else{ Serial.println("ERROR!"); while(1); } } delay(500); } |
After uploading the code, open the serial monitor. If the connection is correct, then you will see the Serial Monitor displaying measured CO2 & TVOC value. In clean air and a typical indoor space your serial monitor will look something like this:
It is recommended to run CCS811 for 20 minutes every time before accurate readings are generated. In order to test the working of the sensor, you can introduce smoke or some perfume or evaporating hand sanitizer or simply blow air on the sensor. At this time, the CO2 & TVOC values both will rise high.
Displaying CO2 & TVOC Value on OLED Display
You can add an extra OLED display to the the above circuit. And using the OLED library you can display the CO2 & TVOC value on OLED Display.
The circuit diagram for connecting OLED Display with Arduino & CCS811 Sensor is given below.
The connection between the Arduino & CCS811 remains the same. Since OLED Display is the I2C Module, connect its SDA & SCL pin to the A4 & A5 of Arduino. Connect the VCC pin to 3.3V & GND to GND.
Source Code/Program
The CCS811 Arduino OLED code is given below. You need to add additional 2 libraries for OLED Display. Download the libraries from the following link & add it to the Arduino Library folder.
Here is a complete code, you can upload it to the Arduino Board.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
#include "Adafruit_CCS811.h" #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); Adafruit_CCS811 ccs; void setup() { Serial.begin(9600); display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64) delay(500); display.clearDisplay(); display.setCursor(25, 15); display.setTextSize(1); display.setTextColor(WHITE); display.println("CCS811 Sensor"); display.setCursor(25, 35); display.setTextSize(1); display.print("Initializing"); display.display(); Serial.println("CCS811 test"); if (!ccs.begin()) { Serial.println("Failed to start sensor! Please check your wiring."); while (1); } // Wait for the sensor to be ready while (!ccs.available()); } void loop() { if (ccs.available()) { if (!ccs.readData()) { Serial.print("CO2: "); Serial.print(ccs.geteCO2()); Serial.print("ppm, TVOC: "); Serial.println(ccs.getTVOC()); display.clearDisplay(); display.setTextSize(1); display.setCursor(20, 0); display.print("Air Quality"); display.setTextSize(2); display.setCursor(0, 20); display.print("CO2:"); display.print(ccs.geteCO2()); display.setTextSize(1); display.print(" ppm"); display.setTextSize(2); display.setCursor(0, 45); display.print("TVOC:"); display.print(ccs.getTVOC()); display.display(); } else { Serial.println("ERROR!"); display.clearDisplay(); display.setTextSize(2); display.setCursor(0, 5); display.print("ERROR!"); while (1); } } delay(1000); } |
The OLED display will start displaying the CO2 & TVOC value soon after the code is uploaded. You can introduce gas near to it to test the sensor.
Video Tutorial & Guide
The sensor can also be interfaced with ESP8266 & ESP32. The ESP32/ESP8266 CCS811 Web Server Project is explained very briefly.

















8 Comments
Hello! in my test the program gets stuck in void setup().
Hello, in my tests it always shows message on the serial monitor “Failed to start sensor! Please check your wiring.”
I’ve tested it several times with Arduino Uno and an ESP32, I can’t connect the sensor. Can you help me?
Please change the I2c address in the library. the CCS811 sensor has multiple I2C address.
Hi, I used this code, and used the same connections for the CCS811. Basically my sensor gives me the right values (~ 400 PPM) for 1/2 minutes, but after 15 minutes the values are wrong (~ 2000 PPM) and out of the ordinary. I wanted to ask if anyone knew the problem, and how to fix it.
Thank you and wait for info.
Hello, a nice and simple project. Please tell me how you can add 5 more pieces of ws2812 led to this project so that they would change color from green – yellow to red as CO2 ppm increases . That would be really cool. How to do it? Is it very difficult?
用3個LED燈(紅黃綠),你代碼添加:氣體濃度3個檢測到CO2變化量(0~1023)值,啟動有顏色的LED///////With 3 LED lights (red, yellow and green), your code adds: gas concentration 3 detected CO2 change (0 ~ 1023) value, start the colored LED
Hi. As stated above the Sensor need s about 15-20 Minutes to calibrate and warm up. So it is more than possible, that the readings after 15 minutes shows the right Values according your test area…
hi, i don’t know what to change in the library. can you help me?