Table of Contents

Play Video

AIR POLLUTING MONITORING SYSTEM

An Air Pollution Monitoring Project by Using Arduino to Checks the Air Quality Around us, Helping to Keep Our Environment Clean and Healthy.

Software Used

Platform Used

Discription:

In this project, we will create a simple device to monitor air pollution using an Arduino, a DHT11 sensor, an MQ135 sensor, and an I2C display. This device helps us understand the quality of the air around us and shows us if it’s safe to breathe. Air pollution can make us sick, so it’s important to know when the air is bad. With this project, we can see real-time data about the air we are breathing. If the display shows high levels of pollution, we know to stay indoors or wear a mask. This project is fun and educational, teaching us about sensors, programming, and the importance of clean air. Let’s start building and make sure the air we breathe is safe! 

Components Required:

  1. Arduino Uno
  2. I2C LCD
  3. DHT 11
  4. MQ 135
  5. Resistor (330 ohm)
  6. Wire [Male to Male X8, Male to Female X4]

Source code:

// Include Libraries 

#include "Arduino.h" 

#include "DHT.h" 

#include "LiquidCrystal_PCF8574.h" 

// Pin Definitions 

#define DHT_PIN_DATA 2 

#define MQ135_5V_PIN_AOUT A3 

// Global variables and defines 

// There are several different versions of the LCD I2C adapter, each might have a different address. 

// Try the given addresses by Un/commenting the following rows until LCD works follow the serial monitor prints.  

// To find your LCD address go to: http://playground.arduino.cc/Main/I2cScanner and run example. 

#define LCD_ADDRESS 0x3F 

//#define LCD_ADDRESS 0x27 

// Define LCD characteristics 

#define LCD_ROWS 2 

#define LCD_COLUMNS 16 

#define SCROLL_DELAY 150 

#define BACKLIGHT 255 

// object initialization 

DHT dht(DHT_PIN_DATA); 

LiquidCrystal_PCF8574 lcdI2C; 

// define vars for testing menu 

const int timeout = 10000;       //define timeout of 10 sec 

char menuOption = 0; 

long time0; 

// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity. 

void setup()  

{ 

    // Setup Serial which is useful for debugging 

    // Use the Serial Monitor to view printed messages 

    Serial.begin(9600); 

    while (!Serial) ; // wait for serial port to connect. Needed for native USB 

    Serial.println("start"); 

    dht.begin(); 

    // initialize the lcd 

    lcdI2C.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, BACKLIGHT);  

    menuOption = menu(); 

} 

// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop. 

void loop()  

{ 

    if(menuOption == '1') { 

    // DHT22/11 Humidity and Temperature Sensor - Test Code 

    // Reading humidity in % 

    float dhtHumidity = dht.readHumidity(); 

    // Read temperature in Celsius, for Fahrenheit use .readTempF() 

    float dhtTempC = dht.readTempC(); 

    Serial.print(F("Humidity: ")); Serial.print(dhtHumidity); Serial.print(F(" [%]\t")); 

    Serial.print(F("Temp: ")); Serial.print(dhtTempC); Serial.println(F(" [C]")); 

    } 

    else if(menuOption == '2') { 

    // LCD 16x2 I2C - Test Code 

    // The LCD Screen will display the text of your choice. 

    lcdI2C.clear();                          // Clear LCD screen. 

    lcdI2C.print("  Circuito.io  ");                   // Print print String to LCD on first line 

    lcdI2C.selectLine(2);                    // Set cursor at the begining of line 2 

    lcdI2C.print("     Rocks!  ");                   // Print print String to LCD on second line 

    delay(1000); 

    } 

    else if(menuOption == '3') 

    { 

    // Disclaimer: The Hazardous Gas  Sensor - MQ-135 is in testing and/or doesn't have code, therefore it may be buggy. Please be kind and report any bugs you may find. 

    } 

    if (millis() - time0 > timeout) 

    { 

        menuOption = menu(); 

    } 

} 

// Menu function for selecting the components to be tested 

// Follow serial monitor for instrcutions 

char menu() 

{ 

    Serial.println(F("\nWhich component would you like to test?")); 

    Serial.println(F("(1) DHT22/11 Humidity and Temperature Sensor")); 

    Serial.println(F("(2) LCD 16x2 I2C")); 

    Serial.println(F("(3) Hazardous Gas  Sensor - MQ-135")); 

    Serial.println(F("(menu) send anything else or press on board reset button\n")); 

    while (!Serial.available()); 

    // Read data from serial monitor if received 

    while (Serial.available())  

    { 

        char c = Serial.read(); 

        if (isAlphaNumeric(c))  

        {    

            if(c == '1')  

    Serial.println(F("Now Testing DHT22/11 Humidity and Temperature Sensor")); 

    else if(c == '2')  

    Serial.println(F("Now Testing LCD 16x2 I2C")); 

    else if(c == '3')  

    Serial.println(F("Now Testing Hazardous Gas  Sensor - MQ-135 - note that this component doesn't have a test code")); 

            else 

            { 

                Serial.println(F("illegal input!")); 

                return 0; 

            } 

            time0 = millis(); 

            return c; 

        } 

    } 

}
Scroll to Top