Air Quality Monitoring System Using NodeMCU With IoT

by Group_7_iot in Circuits > Arduino

5572 Views, 4 Favorites, 0 Comments

Air Quality Monitoring System Using NodeMCU With IoT

intro.jpg

IoT is the technology of the future that is impacting industrial growth in the most significant way possible. Any industry that integrates cutting-edge Internet of Things features and improves their overall workflow, including the fleet, supply chain, chemical, oil and gas, and other sectors, benefits 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 effective 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:

  • Effective 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

​Components Required

components.jpg

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 specifications. 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 office or factory. MQ135 gas sensor has high sensitivity to Ammonia, Sulfide 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 (WiFi), and even a modern operating system and SDK. That makes it an excellent choice for Internet of Things (IoT) projects of all kinds.

LCD 1620A : A sort of dot matrix module used to display characters, numerals, and letters is called a character-type liquid crystal display.

Jumper Wires : Jumper wires are wires with connector pins at either end that can be used to connect two places without soldering.

Breadboard : A breadboard is a solderless instrument used to build temporary electrical prototypes and test circuit designs. Most electronic components in electronic circuits can be linked together by inserting their leads or terminals into the proper holes, and then, if necessary, making connections through wires.

Connecting Components (DHT 22)

dht22.jpg
dht.PNG

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
  • Signal
  • NC Not connected
  • GND

Connecting Components (LCD 1602A)

lcd.jpg
photo_2022-06-29_07-05-32.jpg

How to connect LCD Pin to ESP32 Pins:

The LCD has 16 pins :
PIN01-VSS to GND
PIN02-VDD to 5V
PIN03 V0 to 10K Pot (Middle pin)
PIN04 RS to GPIO19
PIN05 RW to GND
PIN06 E to GPIO23
PIN07 D0 to NOT USED
PIN08 D1 to NOT USED
PIN09 D2 to NOT USED
PIN10 D3 to NOT USED
PIN11 D4 to GPIO18
PIN12 D5 to GPIO17
PIN13 D6 to GPIO16
PIN14 D7 to GPIO15
PIN15 A to 5V
PIN16 K to GND

Connecting Components (MQ 135)

photo_2022-06-30_11-26-50.jpg
photo_2022-06-30_11-29-00.jpg
  • 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 Wifi Module.

Procedure With Platform Thinger.io

thinger.io.PNG
procedure.png

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 define 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.

The Source Code in Arduino IDE

code.png
code2.png
code3.png
code4.png

// Include Libraries
#define THINGER_SERIAL_DEBUG

#include<LiquidCrystal.h>
#include<DHT.h>
#include<ThingerESP8266.h>

// Pin Definitions
#define sensor A0
#define DHTPIN 4
#define DHTTYPE DHT22

// MCU Internet Connection
#define USERNAME "AlishaNajwa"
#define DEVICE_ID "Group7"
#define DEVICE_CREDENTIAL "nodemcuGroup7_credentials"
#define SSID "UniSZA-WiFi"
#define SSID_PASSWORD "unisza2016"

ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
// Define 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_wifi(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 %
float h = dht.readHumidity();
// Read temperature in Celsius, for Fahrenheit use .readTempF()
float 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);

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();
}

Output and Summary

bad-air.png
warning.png
toxic.png

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 effects of air quality that we breathe towards health and environment. The following objective which is to develop the monitoring system of air pollution for environmental sensing application using Internet of Things (IoT), has also been fulfilled. 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 different 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.

Video Reference of Project
https://youtu.be/Cz3bB28mES8