Molemi IoT
  • Space farming using food computers for sustainable farming
  • Introduction to Arduino
    • Introduction to Electronics
    • The Breadboard
  • Controlling LEDs with an Arduino
    • The Code
    • Adding a button to control the LEDs
      • The Code
  • Introducing Sensors
    • The CO2 and air quality sensor
    • The Code
      • Explaining the Code
    • Light Intensity Sensor
  • Introducing the NodeMCU
    • Getting Started
      • A simple test for ESP8266
        • The Code
    • A light bulb switch using NodeMCU and the Blynk app
      • Setup Blynk on your Smartphone
      • The Code
    • Controlling a Centurion gate Motor with NodeMCU a 2-channel relay
      • Installing Blynk in Arduino IDE
    • Read and display the water flow sensor on Blynk
      • Setting up Blynk
      • The Code
        • Explaining the code
    • Read and Display temperature sensor readings with NodeMCU.
      • Installing libraries for DS18B20 temperature sensor.
      • Displaying the sensor readings on the serial port
        • Getting temperature readings from different DS18B20 sensors.
          • The Code
            • Display sensor readings on a web server
              • Build the web server
                • Designing and building the web page
                • The Code
    • Display the DHT11 sensor reading on a web server using NodeMCU.
      • Monitoring Room Temp & Humidity using Blynk
      • Installing DHT library on the ESP8266
        • Installing the Asynchronous Web Server library
          • The Code
          • Designing and building the web page
  • Data Science for Farming
    • Getting Started with Colaboratory
    • Introduction to Python for DS using Colab
  • Machine Learning for Farming
  • Molemi Personal Food Computer
    • Bill of Materials
  • Setting up WaziGate on a Raspberry Pi
  • Setting up DHT11 on Raspberry Pi
  • Using Telegram To Control Outputs
Powered by GitBook
On this page
  • Objectives:
  • What do you need ?
  • Setup the Circuit
  • The Code

Was this helpful?

  1. Introducing Sensors

The CO2 and air quality sensor

This page will demonstrate how to setup the circuit for the Keyes CO2 and air quality sensor and serial print the sensor values.

PreviousIntroducing SensorsNextThe Code

Last updated 5 years ago

Was this helpful?

Objectives:

  • The aim of this activity is to measure the amount of CO2 in the environment and measure the air quality based on the ambient temperature.

  • Connect the circuit for the CCS811 sensor.

  • Write the code (and upload on the Arduino Uno board) to serial print the CO2, ambient temperature and volatile organic compounds.

What do you need ?

  • Arduino Uno Board.

  • male-to-male jumper cables.

  • USB power cable for the Uno.

  • keyestudio CCS811 Carbon Dioxide Temperature Air Quality Sensor

Setup the Circuit

  1. Insert the CO2 sensor of the breadboard.

  2. Connect the GND pin of the sensor to one of the GND pins of the Arduino Uno.

  3. Connect the VCC pin of the sensor to the 5V pin of the Uno.

  4. Connect the SDA pin of the sensor to the Analog pin 4 (A4) of the Uno.

  5. Connect the SCL pin of the sensor to the analog pin 5 (A5) of the Uno.

  6. Connect the WAKE pin of the sensor to the other GND pin of the Uno.

The Code

  • Open your Arduino IDE software and configure the board and the port accordingly.

  • Add the following code to your IDE:

#include "Adafruit_CCS811.h"
Adafruit_CCS811 ccs;

void setup() {
  Serial.begin(9600);
  Serial.println("CCS811 test");
  
  if(!ccs.begin()){
    Serial.println("Failed to start sensor! Please check your wiring.");
    while(1);
  }
  //calibrate temperature sensor
  while(!ccs.available());
  float temp = ccs.calculateTemperature();
  ccs.setTempOffset(temp - 25.0);
}

void loop() {
  if(ccs.available()){
    float temp = ccs.calculateTemperature();
    if(!ccs.readData()){
      Serial.print("CO2: ");
      Serial.print(ccs.geteCO2());
      Serial.print("ppm, TVOC: ");
      Serial.print(ccs.getTVOC());
      Serial.print("ppb   Temp:");
      Serial.println(temp);
    }
    else{
      Serial.println("ERROR!");
      while(1);
    }
  }
  delay(500);
}

Open the serial port. Blow on the sensor and see how the sensor values changes.

Download the and include it in your Arduino IDE.

Adafruit CCS811 library
The circuit for the CO2 and air quality sensor
Pin description of the CCS811 sensor