Air Quality Monitor

Arduino Air Quality Monitor
This is one of my electronic project. I am just a beginner in this field , but I always wanted to make electronic gadgets it has always fascinated me.I was keen since I was a kid infact there is not a single electronic item in my house which I would not have opened to peek inside and understand how its woks.
This is one of those projects that I have in mind .  It was by chance I saw an  Arduino UNO somewhere, I just fell in love with this platform. Working with microcontroler gives me the freedom to implement simple operations in code that would require a dedicated circuit implementation, you can write a code and get away from the complication of designing the circuit. As I am a software engineer by profession so I am very comfortable with writing codes.
Arduino is a very inexpensive platform and comes in different sizes and configuration you can choose it as per your need. I did this project as a side project as I wanted to measure how clean the air in the house is and how it changes over time.
Bangalore has major issue of Micro dust particles in the air and specially the area where I stay there is a lot of construction ongoing. These micro dust particles are also responsible for respiratory and Skin allergies. I am actually going to build an Air purifier for which this is a building block.
You can see the final display as below. It covers Temperature, Humidity, Time and Dust content level.
Arduino Air Quality Monitor

I am planning to add a gas sensor also to the system, still searching  the rite sensor for this task. Arduino UNO does not keep the time to do this I have connected a RTC module which can persist the time information even when the device is switched off.
Real time sensor data is displayed on the LCD screen and is also logged to a file in the SD card so that it can be analysed later. For debugging purpose I am also writing the data to the serial port so that I can monitor it from a PC.
I have also made a case out of acrylic sheet to assemble every thing and keep it together. All the parts except the Acrylic sheet have been bought online. its very easy to purchase it once you know what all do you need.
In my initial design I was using the 16X2 LCD without the serial I2C module this was giving problem as it did not leave enough free I/O pins to connect other stuff on the Arduino. By switching to  I2C module I am not loosing a single pin on Arduino as SDA and SLC pins used by I2C module is shared with RTC Clock. To minimize the noise in the reading I have taken an average of 1000 readings.
You can see the full circuit as below  This is my first attempt to design a circuit diagram, Have used Fritzing which is a open source designer for this purpose.
Arduino Air Quality Monitor


Log data is written to airlog.txt file on the SD Card. Each line in the file corresponds to a log entry. log entry are separated by a comma CSV. I have created a small program in C# to plot
the graph, you can see a sample graph just for couple of days as below. You will be surprised to see the results even in the graph below you can see the variation in the Dust levels.
Arduino Air Quality Monitor Graph

Parts Used

The list of all the parts used is as below, I would say its very easy if you have worked on circuits before this will be a piece of cake.

Arduino Air Quality Monitor

Arduino UNO

Arduino Air Quality Monitor


Interface Module

for LCD

Arduino Air Quality Monitor


Temperature & Humidity


Arduino Air Quality Monitor

Sharp Optical 

Dust Sensor 


Arduino Air Quality Monitor

SD Card

Arduino Air Quality Monitor


Arduino Air Quality Monitor

16X2 LCD


Below is the code that I have used in programing, you can modify it as per your requirement or use it as such.

#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#include <Wire.h>
#include "RTClib.h"
#include <SPI.h>
#include <SD.h>

#define DHTTYPE DHT11

// select the pins used on the LCD panel
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7);

const int chipSelect = 4;
int measurePin = A2;
int ledPower = A3;
int thermistorPin = A1;  

int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;

float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;

float avgDust = 0;
int avgDustCnt = 0;

byte termometru[8] = //icon for termometer
  4, 10, 10, 10, 14, 31, 31, 14

byte picatura[8] = //icon for water droplet
  4, 4, 14, 14, 31, 31, 31, 14

byte threeIco[8] = //raise to power 3 character
  24, 4, 24, 4, 24, 0, 0, 0

byte miliIco[8] = //micrograms character
  0, 17, 17, 17, 19, 29, 16, 16

boolean backlit = true;
RTC_DS1307 rtc;

void setup()
  lcd.begin (16, 2); // for 16 x 2 LCD module
  lcd.createChar(1, termometru);
  lcd.createChar(2, picatura);
  lcd.createChar(3, threeIco);
  lcd.createChar(4, miliIco);
  lcd.setBacklightPin(3, POSITIVE);
  while (!Serial) {
    ; // wait for serial port to connect.
  //Uncomment this line and upload the sketch to arduino after uploading
  //again comment it and upload the sketch again this will set the date and time 
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  pinMode(A3, OUTPUT);
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    lcd.print("Card failed, or not present");
    // don't do anything more:
  Serial.println("card initialized.");
  lcd.print("Card Initialized");

void loop()
  DateTime now =;
  digitalWrite(ledPower, LOW); // power on the dust sensor LED

  voMeasured = analogRead(measurePin); // read the dust value

  digitalWrite(ledPower, HIGH); // turn the dust sensor LED off

  // 0 - 5V mapped to 0 - 1023 integer values
  // recover voltage
  calcVoltage = voMeasured * (5.0 / 1024.0);

  // linear eqaution taken from
  // Chris Nafis (c) 2012
  dustDensity = (0.172 * calcVoltage - 0.0999) * 1000;

  avgDust += dustDensity;
  if (avgDustCnt == 1000)
    // make a string for assembling the data to log:
    String dataString = "";
    dataString += "Dst" + String(avgDust / avgDustCnt) + ",";
    dataString += "Tmp" + String(dht.readTemperature()) + ",";
    dataString += "Hum" + String(dht.readHumidity()) + ",";
    dataString += String(now.year()) + "/" + String(now.month()) + "/" + String( + " ";
    dataString += String(now.hour()) + ":" + String(now.minute()) + ":" + String(now.second());
    File dataFile ="airlog.txt", FILE_WRITE);
    lcd.print(dht.readTemperature(), 0);
    lcd.print("C ");
    lcd.print(dht.readHumidity(), 0);
    lcd.print(" ");
    if (now.hour() < 10)
    lcd.print(now.hour(), DEC);
    lcd.setCursor(0, 1);
    lcd.print("Dust: ");
    lcd.print(avgDust / avgDustCnt, 1);
    lcd.print(" ");
    // if the file is available, write to it:
    if (dataFile) {
      // print to the serial port too:
    } else {
      Serial.println("error opening datalog.txt");
    avgDust = 0;
    avgDustCnt = 0;
Next step to this will be working on the Air-purifier. Even in itself its a very good gadget  to monitor your  home environment.
You can go ahead and try it in-case you are not able to locate any of the parts online feel free to contact me and I can guide you to the sites  from where I purchased these.

Share on Google Plus

About apoorv chaudhary

    Blogger Comment


  1. Hi there, just came across your site. A dreaming DIY here planning to start soon. I have to say you remind me of Matthias Wandel, i think you know who he is. Great work and contribution from you. Please keep it going, there are a lot of people out there who appreciate you. Thanks for sharing your enlightening works...

    1. Thanks Aditya,
      It is always good to know that there are people who read my posts. Matthias Wandel is a DIY guru my table saw project was inspired by one of his table saw projects.

  2. Just stumbled across your very well made and interesting site. Am a beginning DIY'er and am looking to build a AQM like you have done here. Have you seen Chris Nafis' site at where he tries out both this Sharp and Shinyei sensors?

    So my question is; what is the total cost for your project and where can i get the parts in Bangalore? Am looking at the Shinyei one from Appreciate your response.

    1. Hi ram,
      Yes i have seen that site before i had started working on the project.
      Both the sharp and Shinyei work on same principal and there should not be much difference in sensitivity between them. I dont think you will be able to source the Shinyei sensor easily. Other stuff is easily available on . If you are really on tight budget and not in any hurry then order from as the order can take 2 months.

  3. Hi apoorv! Your work is a masterpiece! Could you help me with the sketch and the circuit of my air quality sensor? Some of my components are different. Have a great day

    1. Hi Mario,
      You can send me the details of your design @

    2. Hi Apoorv, many thanks for the detailed walk through of this project. Though I am an electronic enthusiastic, decade ago, stopped for some time until I saw this project. I am very new to Arduino based project and this is going to be my first. I am very very new to coding, though I am an IT professional. Hence might require your guidance, if i face any challenges in making this project successful. I am in the process of making Air Purifier for my home - currently identifying the suitable blower fan and other components. Pre filter, Active carbon filter and HEPA are available in which is economic and standard in size compared to other filters and widely available. The design is not yet finalized...waiting for the fan post which the dimension and design will be concluded. I am planning to use the air quality monitor in it. Will reach out to you for any assistance and hoping that your would be able to space your time to assist. Thanks in anticipation.

    3. thanks Raja,

      mentioned site looks good will also try to order the filters and test them. Sourcing filters in India is the most difficult part in my opinion. You can also check my post on fans that might help you in selecting the right blower for air purifier.
      I would suggest using a laser dust sensor as they are more accurate and can differentiate between particle sizes.

  4. Hi Apoorv, thanks for your swift reply. I just ordered the parts on Amazon and started getting one by one and anticipate the complete kit will be with me by this weekend. One small query - can i just copy the entire code from your post and use it? Will it require any modifications? Since i am very new to coding, required your assistance. Thanks

    1. it will not work just by copy past. There are external library (LiquidCrystal_I2C.h) for LCD that has to be downloaded. There are many versions available online so you have to experiment with them.

  5. thanks, Apoorv. This input helps. In addition to LiquidCrystal_I2C.h, i think DHT.h and RTClib.h will needs to be downloaded. Let me get into it and reach out to you for any assistance. Please pardon for all silly questions. Thanks again.

    1. I think the link 4 this library is

    2. I will also resume work on my air purifier.
      How are you planning to use the sensors are you trying to make a smart air purifier or will use the device just 4 monitoring.

  6. Thanks for sharing the link. I am planning to make this device just for monitoring initially and later will work on smart air purifier.

  7. Good morning, Apoorv. I have got the air quality monitor working well. But the time shows 00:63 (constantly). What could be the reason?

    1. have you tried this
      //Uncomment this line and upload the sketch to arduino after uploading
      //again comment it and upload the sketch again this will set the date and time
      //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

  8. Thanks, Apoorv. Got it. Time issue fixed. But facing challenge in getting the SD card initialisation - error showing "Card failed, or not present". trying various options.

    1. Check the format of the card
      use SD Card Formatter to format it

  9. Thanks. The problem was with Arduino. SD is working well with another board. BTW, what could be the problem with earlier board? Everything else working fine, except the SD.
    Thanks again for a wonderful useful project. The time format in the display is HH:M when the minute is from 0 to 9. Only single digit appears in the LCD. eg. 22:9 for 22:09. Is it correct or correction in the code is required?