Air Quality Monitoring System Using NodeMCU With I
Air Quality Monitoring System Using NodeMCU With I
by Group_7_iot
IoT is the technology of the future that is impacting industrial growth in the most signi cant way possible. Any industry
that integrates cutting-edge Internet of Things features and improves their overall work ow, including the eet, supply
chain, chemical, oil and gas, and other sectors, bene ts hugely.
Real-time monitoring of the environment is made possible by IoT-based solutions when combined with environmental
assets. This, one of the main advantages of IoT integration with the environment, guarantees a more e ective strategy
for enhancing the environmental conditions.
The implementation of this device helps in solving this kind of problem by showing the results of air quality level not just
on LCD screen but also on a web server. Thus, an air quality monitoring system using IoT has been developed to share the
air quality level to the public continuously in order to be aware of the unhealthy environment.
Features:
E ective air quality monitoring
Temperature and humidity measurement
Built-in Wi-Fi connectivity
Suitable for indoor or outdoor area
In this tutorial we will learn how to use the DHT22 sensor for measuring temperature and humidity and MQ 135 air
quality sensor on Thinger.io using NodeMCU. In this program, the NodeMCU to read and store the data into a variable
and then upload it to Thinger.io using its channel name and API key.
Additionally, both the serial monitor and the LCD display will display the value output by the DHT sensor and air quality
sensor. The LCD display element is optional. You may print on a serial monitor using this instruction as well. Within
sensors, code and circuit diagram are compatible.
Supplies:
DHT22
LCD 1602A
MQ135
Jumper Wires
Hardware Required:
1. DHT 22 (Humidity and Temperature Sensors)
2. MQ 135 (Air Quality Sensor)
3. NodeMCU
4. LCD 1602A (Optional)
5. Jumper Wires
6. Breadboard
DHT22 : The DHT22 is the more expensive version which obviously has better speci cations. Its temperature measuring
range is from -40 to +125 degrees Celsius with +-0.5 degrees accuracy.
MQ 135 : An air quality sensor for detecting a wide range of gases, including NH3, NOx, alcohol, benzene, smoke and
CO2. Ideal for use in o ce or factory. MQ135 gas sensor has high sensitivity to Ammonia, Sul de and Benzene steam.
NodeMCU Internet ESP8266 : The NodeMCU (Node MicroController Unit) is an open-source software and hardware
development environment built around an inexpensive System-on-a-Chip (SoC) called the ESP8266. The ESP8266,
designed and manufactured by Espressif Systems, contains the crucial elements of a computer: CPU, RAM, networking
Although DHT 22 (temperature and humidity) sensors are quite sluggish and simple, they are perfect for hobbyists who
want to log some simple data. The capacitive humidity and temperature sensors are the two components that make up
the DHT sensors.
The DHT sensor have four pins, VCC, GND, data pin and a not connected pin which has no usage.
From left to right
VCC
Air Quality Monitoring System Using NodeMCU With IoT: Page 3
Signal
NC Not connected
GND
The VCC pin of the MQ135 Gas Sensor is connected to the 3.3 volts pin of the NodeMCU Module.
A0 pin of the NodeMCU Module is connected to AOUT pin.
The ground of the Gas Sensor is connected to the ground of the NodeMCU ESP8266 Wi Module.
Step 1: Go to thinger.io and create your Thinger.io account if you don’t have. Login to Your Account.
Step 2: Device setup to de ne username, device id and device credential in Thinger.io account and project declaration in
Arduino IDE.
Step 3: Dashboard setup to add and set widgets in Thinger.io account. You may add as many widgets depending on your
project on Thinger.io platform.
Step 4: Open Arduino IDE to setup Thinger.io library .To do this go to Sketch>Include Library>Manage Libraries. Search
for thinger.io and install the latest in the library.
Step 5: Mobile application setup in Thinger.io, scan QR code generated from Device Token and the device to checked
our 'Air Status' can be view or control.
// Include Libraries
#de ne THINGER_SERIAL_DEBUG
Air Quality Monitoring System Using NodeMCU With IoT: Page 10
#include<LiquidCrystal.h>
#include<DHT.h>
#include<ThingerESP8266.h>
// Pin De nitions
#de ne sensor A0
#de ne DHTPIN 4
#de ne DHTTYPE DHT22
// MCU Internet Connection
#de ne USERNAME "AlishaNajwa"
#de ne DEVICE_ID "Group7"
#de ne DEVICE_CREDENTIAL "nodemcuGroup7_credentials"
#de ne SSID "UniSZA-WiFi"
#de ne SSID_PASSWORD "unisza2016"
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
// De ne vars for testing menu
int gasLevel = 0;
String quality ="";
// Object initialization
DHT dht(DHTPIN, DHTTYPE);
const int RS = 5, EN = 2, d4 = 14, d5 = 12, d6 = 13, d7 = 15;
LiquidCrystal lcd(RS, EN, d4, d5, d6, d7);
void setup() {
thing.add_wi (SSID, SSID_PASSWORD);
thing["dht22"] >> [] (pson & out){
out["humidity"] = dht.readHumidity();
out["temperature"] = dht.readTemperature();
};
thing["Air_Quality"] >> outputValue(analogRead(A0));
pinMode(sensor,INPUT); dht.begin();
lcd.begin(16, 2); Serial.begin(115200);
}
void sendSensor(){
//Temperature and Humidity Sensors
// Reading humidity in %
oat h = dht.readHumidity();
// Read temperature in Celsius, for Fahrenheit use .readTempF()
oat t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity:");
Serial.println(h);
Serial.print("Temperature:");
Serial.println(t);
delay(2000);
Air Quality Monitoring System Using NodeMCU With IoT: Page 11
lcd.setCursor(0,2);
lcd.print("Temp:");
lcd.print(t);
lcd.setCursor(7,2);
lcd.print("Hum:");
lcd.print(h);
}
void air_sensor(){
//Air Quality Sensor
// Read data from serial monitor if received
gasLevel = analogRead(sensor);
if(gasLevel<181){
quality = "GOOD!";
thing["Status"] >> outputValue(quality);
}
else if (gasLevel >181 && gasLevel <225){
quality = "POOR!";
thing["Status"] >> outputValue(quality);
}
else if (gasLevel >225 && gasLevel <300){
quality = "BAD AIR!";
thing["Status"] >> outputValue(quality);
}
else if (gasLevel >300 && gasLevel <350){
quality = "WARNING!";
thing["Status"] >> outputValue(quality);
}
else{
quality = "TOXIC";
thing["Status"] >> outputValue(quality);
}
Serial.println(quality);
lcd.setCursor(0,1);
lcd.print("Air:");
lcd.print(quality);
}
// Main logic of your circuit
void loop() {
sendSensor();
air_sensor();
thing.handle();
}
As a conclusion, the Air Quality Monitoring System with IoT has achieved the objective that able to detect air quality and
pollution or harmful gases by using MQ135 gas sensor. It is also capable of spreading awareness of how important to
know the e ects of air quality that we breathe towards health and environment. The following objective which is to
Air Quality Monitoring System Using NodeMCU With IoT: Page 14
develop the monitoring system of air pollution for environmental sensing application using Internet of Things (IoT), has
also been ful lled. The entire system includes the hardware components such as the NodeMCU (ESP8266) , MQ135
sensor, DHT 22 sensor, and LCD. These features are designed in order to work hand-in-hand in order to provide an ideal
system for user. The last objective is to verify the function of the system in a di erent level of air quality level which also
been accomplished. Thus, this ensures that the system is capable of performing the required safety and monitoring
purposes using Thinger.io.
Hope this made it easier for you. Be sure to subscribe if you like this article and found it useful, and if you have any
questions or need help with anything, just leave a comment below. Thank you.