Built-in project · Arduino Uno R3

CCS811 air quality on an Arduino Uno

A CJMCU-811 CCS811 board on the Uno’s I2C pins, read with Adafruit_CCS811.h: the serial monitor prints eCO2 in ppm and TVOC in ppb every second. The whole build, an Arduino Uno and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner About 10 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $37. On Mokxi they're free.

CCS811 air quality · Arduino Uno R3live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

What you'll learn

  • Sensors
  • School
  • Using the Air quality
  • Difficulty: Beginner
  • Time: About 10 minutes
  • Board: Arduino Uno R3
  • Parts: 2

How it works

A CJMCU-811 CCS811 board on the Uno’s I2C pins, read with Adafruit_CCS811.h: the serial monitor prints eCO2 in ppm and TVOC in ppb every second.

Arduino Uno R3 runs the sketch below. The circuit around it: Air quality, CCS811. delay waits 250 milliseconds. Serial.begin opens the serial port at 9600 baud.

Parts list

2 parts, plus the jumper wires. They retail for about $37; on Mokxi they're free.

Wiring table

Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.

Part and pinConnects to
Air quality, CCS811 pin VCCArduino Uno R3 pin 3V3
Air quality, CCS811 pin GNDArduino Uno R3 pin GND
Air quality, CCS811 pin SDAArduino Uno R3 pin A4
Air quality, CCS811 pin SCLArduino Uno R3 pin A5
Air quality, CCS811 pin WAKGround

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// A CCS811 air quality sensor on the CJMCU-811 board.
//
// The CCS811 answers at 0x5A. It starts in boot mode; begin() starts its
// application and sets the 1 second drive mode, so a new eCO2 (equivalent
// CO2, in ppm) and TVOC (volatile organic compounds, in ppb) arrive every
// second.
//
//   CJMCU-811  VCC -> 3.3V, GND -> GND, SCL -> A5, SDA -> A4, WAK -> GND
//
// The chip runs on 3.3 V only. WAK is "wake": the chip only listens while
// it is low, so tie it to GND (or to a pin you hold low while you talk).
// Move the eCO2 and TVOC sliders while it runs.
//
// THINGS TO TRY. Leave WAK unwired: begin() gets no answer. Then light an
// LED when eCO2 goes over 1000 ppm, a sign the room needs fresh air.

#include <Wire.h>
#include "Adafruit_CCS811.h"

Adafruit_CCS811 ccs;

void setup() {
  Serial.begin(9600);
  if (!ccs.begin()) {
    Serial.println("No CCS811 at 0x5A: check SDA, SCL, power and WAK to GND.");
    while (1) {}
  }
  Serial.println("CCS811 found at 0x5A");
  while (!ccs.available()) {}
}

void loop() {
  if (ccs.available()) {
    if (ccs.readData() == 0) {
      Serial.print("eCO2 ");
      Serial.print(ccs.geteCO2());
      Serial.print(" ppm, TVOC ");
      Serial.print(ccs.getTVOC());
      Serial.println(" ppb");
    } else {
      Serial.println("CCS811 error");
    }
  }
  delay(250);
}

Code walkthrough

The key functions of the sketch, and what each one does.

setup sketch.ino

Runs once when the board starts. It gets the pins and libraries ready.

void setup() {
  Serial.begin(9600);
  if (!ccs.begin()) {
    Serial.println("No CCS811 at 0x5A: check SDA, SCL, power and WAK to GND.");
    while (1) {}
  }
  Serial.println("CCS811 found at 0x5A");
  while (!ccs.available()) {}
}

loop sketch.ino

Runs over and over for as long as the board has power. This is where the project does its work.

void loop() {
  if (ccs.available()) {
    if (ccs.readData() == 0) {
      Serial.print("eCO2 ");
      Serial.print(ccs.geteCO2());
      Serial.print(" ppm, TVOC ");
      Serial.print(ccs.getTVOC());
      Serial.println(" ppb");
    } else {
      Serial.println("CCS811 error");
    }
  }
  delay(250);
}

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • Upload fails or nothing runs after wiring pins 0 and 1 to a module. Arduino Uno R3
    Pins 0 and 1 are the USB serial port. Move the module to other pins, or unplug it while uploading. Also check the right board is selected.
  • Pins misbehave or the board resets when you power motors or servos from it. Arduino Uno R3
    Each I/O pin gives about 20 mA, 40 mA max. Power motors and servos from their own supply and join its ground to the Uno's GND.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.