Measuring Air Quality With IoT

DZone 's Guide to

Measuring Air Quality With IoT

Wondering how to build an air quality sensor? Look no further than this tutorial on how to use IoT devices to measure air quality.

· IoT Zone ·
Free Resource

Pollution is increasing day by day, and health risks are increasing with the increasing pollution. A simple air quality detection system can be made to detect the quality of the air around us. So, let us get into it and create an air quality monitor with a variety of IoT devices.


  • Intel Edison
  • Grove Base Shield
  • Air Quality Sensor
  • Jumper Cables
  • USB Cable

Air Quality Sensor

This sensor is designed for comprehensive monitoring over indoor air conditions. It’s responsive to a wide scope of harmful gases, such as carbon monoxide, alcohol, acetone, thinner, formaldehyde, and so on. Due to the measuring mechanism, this sensor cannot output specific data to describe target gas concentrations quantitatively. But, it’s still competent enough to be used in applications that require only qualitative results, like auto refresher sprayers and auto air cycling systems.

Image title

Image title


  • Responsive to a wide scope of target gases
  • Cost efficient
  • Durable


  1. Power on the Edison board
  2. Wait 15-20 seconds to boot up
  3. Stack the Grove Base Shield
  4. Connect the air quality sensor to the A0 port


Download this file!

Save this to your Arduino folder.

Then, open the example below by the path:

 File / Example / AirQuality_Sensor / AirQuality_Sensor 

Upload the code and see the results in your serial monitor.

Image title


#include "AirQuality.h"
#include "Arduino.h"

AirQuality airqualitysensor;
int current_quality = -1;
void setup()

void loop()
    current_quality = airqualitysensor.slope();
    if (current_quality >= 0) // if a valid data returned.  
        if (current_quality == 0)
            Serial.println("High pollution! Force signal active");
        else if (current_quality == 1)
            Serial.println("High pollution!");
        else if (current_quality == 2)
            Serial.println("Low pollution!");
        else if (current_quality == 3)
            Serial.println("Fresh air");
    if (airqualitysensor.counter == 122) //set 2 seconds as a detected duty  
        airqualitysensor.last_vol = airqualitysensor.first_vol;
        airqualitysensor.first_vol = analogRead(A0);
        airqualitysensor.counter = 0;
        airqualitysensor.timer_index = 1;
        PORTB = PORTB ^ 0x20;
    } else



  • Require relatively clean air as an initial condition
  • Long time exposure to highly polluted air can significantly weaken its sensitivity
air quality ,grove base shield ,intel edison ,iot ,pollution ,sensor ,tutorial

Published at DZone with permission of Pooja Baraskar , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}