INTRODUCTION
In this project we are going to make an IOT Based Air Pollution Monitoring System in which we will monitor the Air Quality over a webserver using internet and will trigger an alarm when the air quality goes down beyond a certain level, means when there are sufficient amount of harmful gases are present in the air like CO2, smoke, alcohol, benzene and NH3. It will show the air quality in PPM on the LCD as well as on the webpage, so that we can monitor it very easily.
HARDWARE REQUIRED
- MQ135 Gas Sensor - 1pc
- Arduino Uno - 1pc
- USB Cable -1pc
- Wi-Fi Module ESP8266 – 01 - 1pc
- 16x2 LCD - 1pc
- Breadboard 400 points - 1pc
- 10K potentiometer - 1pc
- 1K Ohm Resistors - 2pcs
- 220 ohm resistor - 2pcs
- Buzzer B-10 – 1pc
- Jumper wire male to female – 40 pieces
- Jumper wire male to male – 40 pieces
- Wire - 1mtr
- Buzzer - 1pc
- Adapter
SOFTWARE REQUIRED
Arduino IDE 1.8.10 (programmable platform for Arduino)
Click here to download the software

SPECIFICATIONS
ESP8266 Wi-fi Module:
The ESP8266 Wi-Fi Module is a self-contained SOC with an integrated TCP/IP protocol stack that can give any microcontroller access to your Wi-Fi network. The ESP8266 is capable of either hosting an application or offloading all Wi-Fi networking functions from another application processor.

16*2 LCD Display:
Symbol |
External Connection |
Function |
VSS |
Power Supply |
Signal GROUND for LCM |
VDD |
POWER SUPPLY for logic LCM |
|
V0 |
Contrast Adjust |
|
RS |
MPU |
Register Select Signal |
RW |
MPU |
Read/Write Select Signal |
E |
MPU |
Operation Enable Signal |
DB0~DB3 |
MPU |
Four low-order bidirectional three-state bus lines. Used for data transfer between the MPU and LCM. These four are not used in 4-bit operations. |
DB4~DB7 |
MPU |
Four high-order bidirectional three-state bus lines are used for data transfer between the MPU |
A |
LED BKL Power Supply |
Power Supply for BKL |
K |

MQ135 Gas Sensor:
Pin |
Description |
A0 |
Analog output |
D0 |
Digital Output |
GND |
Ground |
VCC |
5v Voltage Input from Arduino |

CIRCUIT CONNECTION
First of all, we will connect the ESP8266 with the Arduino. ESP8266 runs on 3.3v, and if you give it 5v from the Arduino, then it won’t work properly and it may get damaged. Connect the VCC and the CH_PD to the 3.3v pin of Arduino. The RX pin of ESP8266 works on 3.3v, and it will not communicate with the Arduino when we connect it directly to the Arduino. So, we will have to make a voltage divider for it, which will convert the 5v into 3.3v. This can be done by connecting three resistors in series, like we did in the circuit. Connect the TX pin of the ESP8266 to pin 10 of the Arduino and the RX pin of the ESP8266 to pin 9 of the Arduino through the resistors.
ESP8266 Wi-Fi module gives your projects access to Wi-Fi or the internet.
Then we will connect the MQ135 sensor with the Arduino. Connect the VCC and the ground pin of the sensor to the 5v and ground of the Arduino, and the Analog pin of the sensor to the A0 of the Arduino.
Connect a buzzer to pin 8 of the Arduino, which will start to beep when the condition becomes true.
The connections of the LCD are as follows
- Connect pin 1 (VEE) to the ground.
- Connect pin 2 (VDD or VCC) to the 5v.
- Connect pin 3 (V0) to the middle pin of the 10K potentiometer, and connect the other two ends of the potentiometer to the VCC and the GND. The potentiometer is used to control the screen contrast of the LCD. Potentiometers with values other than 10K will work too.
- Connect pin 4 (RS) to pin 12 of the Arduino.
- Connect pin 5 (Read/Write) to the ground of Arduino. This pin is not often used, so we will connect it to the ground.
- Connect pin 6 (E) to pin 11 of the Arduino. The RS and E pins are the control pins that are used to send data and characters.
The following four pins are data pins that are used to communicate with the Arduino.
- Connect pin 11 (D4) to pin 5 of the Arduino.
- Connect pin 12 (D5) to pin 4 of the Arduino.
- Connect pin 13 (D6) to pin 3 of the Arduino.
- Connect pin 14 (D7) to pin 2 of the Arduino.
- Connect pin 15 to the VCC through the 220-ohm resistor. The resistor will be used to set the back light brightness. Larger values will make the back light much darker.
- Connect pin 16 to the Ground.

CODE
TESTING AND OUTPUT
Before uploading the code, make sure that you are connected to the Wi-Fi of your ESP8266 device. After uploading, open the serial monitor, and it will show the IP address as shown below.

Type this IP address in your browser, it will show you the output as shown below. You will have to refresh the page again if you want to see the current Air Quality Value in PPM.

We have set up a local server to demonstrate its working, You can check the Video below. But to monitor the air quality from anywhere in the world, you need to forward port 80 (used for HTTP or internet) to your local or private IP address (192.168*) of your device. After port forwarding, all the incoming connections will be forwarded to this local address, and you can open the above shown webpage by just entering the public IP address of your internet from anywhere. You can forward the port by logging into your router (192.168.1.1) and finding the option to set up the port forwarding.
WORKING
In this project we are going to make an IOT Based Air Pollution Monitoring System in which we will monitor the Air Quality over a webserver using internet and will trigger a alarm when the air quality goes down beyond a certain level, means when there are sufficient amount of harmful gases are present in the air like CO2, smoke, alcohol, benzene and NH3. It will show the air quality in PPM on the LCD as well as on the webpage, so that we can monitor it very easily.
The MQ135 sensor can sense NH3, NOx, alcohol, Benzene, smoke, CO2 and some other gases, so it is the perfect gas sensor for our Air Quality Monitoring Project. When we connect it to Arduino, then it will sense the gases, and we will get the Pollution level in PPM (parts per million). The MQ135 gas sensor gives the output in the form of voltage levels, and we need to convert it into PPM. So, for converting the output in PPM, here we have used a library for the MQ135 sensor, which is explained in detail in the “Code Explanation” section below.
The sensor was giving us a value of 90 when there was no gas near it, and the safe level of air quality is 350 PPM, and it should not exceed 1000 PPM. When it exceeds the limit of 1000 PPM, then it starts causing Headaches, sleepiness and stagnant, stale, stuffy air, and if it exceeds 2000 PPM, then it can cause increased heart rate and many other diseases.
When the value is less than 1000 PPM, then the LCD and webpage will display “Fresh Air”. Whenever the value increases 1000 PPM, then the buzzer will start beeping and the LCD and webpage will display “Poor Air, Open Windows”. If it increases to 2000, then the buzzer will keep beeping and the LCD and webpage will display “Danger! Move to fresh Air”.