You are on page 1of 8

IoT Based Air Pollution Monitor

ing using Node MCU and MQ13


5 Gas Sensor
COMPONENTS REQUIRED 
1.MQ135 gas sensor
2.NodeMCU
3.LCD (16X2)
4.10K Ohm Potentiometer 
5.Breadboard
6.Connecting Wires
 
 
The internal circuit of the MQ135 gas sensor is shown below.
IOT AIR POLLUTION MONITORING CIRCUIT
DIAGRAM 
S.No LCD pins Description
1 DB4 Connected to the D4 pin of the nodeMCU

2 DB5 Connected to the D5 pin of the nodeMCU

3 DB6 Connected to the D6 pin of the nodeMCU

4 DB7 Connected to the D7 pin of the nodeMCU

5 LED+ Connected to the positive supply terminal


of the power rail

6 LED- Connected to the Ground supply terminal


of the power rail

7 VSS Connected to the ground terminal of the


power rail.

8 VCC Connected to the positive supply of the


power rail
9 VEE Check the above note
10 RS Connected to the D0 terminal of the
nodeMCU
11 R/W Connected to the ground of the power rail

12 E Connected to the D1 pin of the nodeMCU


IOT AIR POLLUTION
MONITORING SYSTEM:
NODEMCU - ARDUINO CODE
EXPLANATION 
Here we are using the Arduino IDE to write the code. To write the code for this IoT
pollution monitoring project we are keeping in mind that first, our code has to connect the
local area network by using the credentials provided in the code. After that, our code has to
work on getting the input from the sensor, and then it must display the data on the webpage,
which is created using node MCU. Please note that we are not dealing directly with the ppm.
We are calculating the voltage variations with respect to the pollution content in the air. If the
output voltage of the MQ sensor is less than 20% of the max voltage value, we considered it
a normal amount of pollution content present in the air. If the output voltage is increased and
stabilizes in the range of more than 20% to less than 70%, then it is considered as a medium
amount of pollution content present in the surrounding air. If the output voltage increases
more than 70% of the maximum value, then it is considered as dangerous level. These values
are transmitted and shown at the webpage.
COMPLETE ARDUINO CODE FOR // Web Page Heading

NODEMCU ESP8266
void loop() {
client.println("<body><h1
delay(500);
lcd.clear(); style=\"color:orange;\"> Air Quality Measurement
lcd.setCursor(0, 0); </h1>");
#include <ESP8266WiFi.h>
#include <LiquidCrystal.h> lcd.print("Pollution=");
const int rs = D0, en = D1, d4 = D4, d5 = D5, d6 = D6, d7 = D7; air_quality = ((analogRead(A0)/1024.0)*100.0); client.println("<body><p style=\"color:blue;\">
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); lcd.print(air_quality); Pollution Content(in percentage) = " +
lcd.print("%"); String(air_quality) +" %"+ " </p>");
const char *ssid = "Mamameya"; // Enter your WiFi Name Serial.println(air_quality); if(air_quality <= 20.0 ){
const char *pass = "244466666"; // Enter your WiFi Password client.println("<body><p style=\"color:green;\">
//// put your main code here, to run repeatedly: Normal </p>");
WiFiServer server(80); } else if (air_quality > 20.0 && air_quality <
WiFiClient client = server.available();
70.0){
double air_quality; if ( client.connected()) { // loop while the client's connected
// HTTP headers always start with a response code (e.g. client.println("<body><p style=\"color:purple;\">
void setup() {
HTTP/1.1 200 OK) Medium </p>");
Serial.begin(115200);
lcd.begin(16, 2); client.println("HTTP/1.1 200 OK"); } else {
delay(10); client.println("Content-type:text/html"); client.println("<body><p style=\"font-size:200%;
Serial.println("Connecting to "); client.println("Connection: close"); color:red\"> Danger!!! </p>");
lcd.print("Connecting.... "); client.println("Refresh: 3"); // update the page after 4 sec }
Serial.println(ssid); client.println();
WiFi.begin(ssid, pass); client.println("</body></html>");
while (WiFi.status() != WL_CONNECTED) // turns the GPIOs on and off delay(1000);
{ lcd.setCursor(0,1);
delay(550); lcd.print("Sending Data" );
lcd.clear();
Serial.print("."); lcd.setCursor(0, 0);
lcd.print("."); // Display the HTML web page
client.println("<!DOCTYPE html><html>"); lcd.print("Pollution=");
}
Serial.println(""); client.println("<head><meta name=\"viewport\" lcd.print(air_quality);
Serial.println("WiFi connected"); content=\"width=device-width, initial-scale=1\">"); lcd.print("%");
Serial.print("IP Address: "); client.println("<link rel=\"icon\" href=\"data:,\">"); }
Serial.println(WiFi.localIP()); }
server.begin();
}
WORKING
In the beginning, the nodeMCU is operated in station mode and waits for an active LAN to connect. After connecting to a LAN, it
will display the IP address by which we can visit the webpage and monitor the data. We display the IP address over the serial
monitor. Note down the IP address and enter this IP address in your web browse to monitor the pollution content on the
webpage. To check the working of the MQ sensor, you can just test it by providing any gas near to it. As shown in the video below,
I just used a lighter to test the working of the MQ sensor. If the pollution content is more than 20% of the maximum value, then I
considered it as normal. If the value is more than 20% and less than 70% of the maximum value, then it is medium, and if the
value is more than 70% of the maximum value, then it is considered as dangerous level.

IoT Air Pollution Monitoring over Webpage

You might also like