Measuring the air quality with CCS811 and GP2Y1010AU0F

In this video I show you how to set up the basics for a "home air quality station". You will be able to measure the room temperature, the amount of CO2/VOCs and the amount of dust in the air. I will improve this device in the future with an LCD and some extra sensors, so please don't forget to subscribe and check back for the next stage of this circuit.



Wiring diagram

The CCS811 sensor (bottom) uses the i2C protocol to connect to the Arduino. The dust sensor (top) is connected via a digital pin and an analog pin. The capacitor is a 220 uF electrolytic capacitor (pay attention to the polarity). The resistor is a 1…

The CCS811 sensor (bottom) uses the i2C protocol to connect to the Arduino. The dust sensor (top) is connected via a digital pin and an analog pin. The capacitor is a 220 uF electrolytic capacitor (pay attention to the polarity). The resistor is a 150 Ohm resistor.



Arduino source code

//Info: GP2Y1010AU0F Dust sensor
//The dust sensor reaches the maximum output pulse 0.28 ms after the LED was turned on
//This sensor is based on voltage measurement
//CCS811 is a thermometer-VOC meter and uses a premade library
//Sharp GP2Y1010AU0F datasheet: https://pdf1.alldatasheet.com/datasheet-pdf/view/412700/SHARP/GP2Y1010AU0F.html
//CCS811 datasheet: https://pdf1.alldatasheet.com/datasheet-pdf/view/1047395/AMSCO/CCS811.html
//CCS811 library: https://github.com/adafruit/Adafruit_CCS811
 
//VOC sensor
#include "Adafruit_CCS811.h" //We load the library for the gas sensor
Adafruit_CCS811 ccs;
float co2Amount; //Amount (mg/m^3) of CO2, later, it will be converted to ug/m^3
float temperature; //temperature measured by the CCS811
 
//Dust sensor
int dustmeasurePin = A6; //The output of the dust sensor is connected to A6 (AD converter pin)
int dustLEDPin = 2; //The IR pin inside the dust sensor is connected to D2 (digital output pin)
float outBits = 0; //AD-converter raw output
float dustDensity = 0; //dust density, based on the formula (see later)
 
//String for storing the formatted output data
String outputData;
 
void setup()
{
    Serial.begin(9600); //Start serial
 
    Serial.println("*Dust and VOC sensor"); //Print message. I use '*' to tell the receives software that this is not a measurement data
 
    if(!ccs.begin()) //if we are not able to start the VOC sensor, print the following message
    {
        Serial.println("* Failed to start sensor! Please check your wiring.");
        while(1); //And hold the code here
    }
   
    while(!ccs.available());
 
    float temp = ccs.calculateTemperature(); //calculate the temperature
    ccs.setTempOffset(temp - 25.0); //set the offset using the
 
    pinMode(dustLEDPin,OUTPUT); //the pin for the dust sensor's LED is set as an output
}
 
 
void loop()
{
    if (Serial.available() > 0) //if there's something on the serial
    {
    char commandCharacter = Serial.read(); //we use characters (letters) for controlling the switch-case
 
        switch (commandCharacter)
        {
          case 'S': //S: start
 
          while(Serial.read() != 'N') //while we don't send N through the serial, the following functions are looping:
          {
             measureDust();
             delay(500);
             measureVOCs();
             delay(500);
             printFormattedData();        
          }
          break;
 
          default:
              //
          break;    
        }    
  }
}
 
void measureDust()
{
  digitalWrite(dustLEDPin,LOW); //turn ON the LED
 
  delayMicroseconds(280); // wait 0.28 ms = 280 us
 
  outBits = analogRead(dustmeasurePin); //measure the peak of the output pulse  
 
  digitalWrite(dustLEDPin,HIGH); //turn OFF the LED    
 
  /*
  If you want to get the converted data on the Arduino terminal,
  //uncomment this part and replace the outbits to dustDensity in printFormattedData()
 
  dustDensity = 1000* ( 0.17 * ((5.0 / 1024) * outBits) - 0.1); //dust density in ug/m^3
  */  
}
 
void measureVOCs()
{
    if(ccs.available()) //If we can communicate with the VOC sensor
    {
        if(!ccs.readData()) //if we are not reading (i.e. the devide is available)
        {
            co2Amount = ccs.geteCO2(); //read CO2
            ccs.getTVOC(); //read temperature
            temperature = ccs.calculateTemperature(); //calculate temperature
        }
        else
        {
            Serial.println("ERROR!"); //Print error message
            while(1); //wait here
        }
    }
}
 
void printFormattedData() //Formatting the output so the receiver software can process it
{  
  //output:      T                     Dust              CO2
  outputData = (String)temperature + '\t' + (String)outBits + '\t' + (String)co2Amount ; //for the output
  Serial.println(outputData);
 
  //outBits can be replaced to dustDensity to print the converted data instead of the raw data.  
}

Previous
Previous

Brief introduction of strain gauges - Part 1

Next
Next

TB6600 and Arduino - Wiring and demonstration