Devices & Components
16x2 LCD display with I²C interface
Arduino Nano
MQ-135 Air Quality Sensor
5V 2.5A Switching Power Supply
Breadboard (generic)
Grove - Gas Sensor(MQ2)
Gravity: Analog LPG Gas Sensor (MQ5) For Arduino
DHT11 Temperature & Humidity Sensor (4 pins)
Male/Male Jumper Wires
Gravity: Analog CH4 Gas Sensor (MQ4) For Arduino
Male/Female Jumper Wires
Hardware & Tools
Hot glue gun (generic)
Software & Tools
Arduino IDE
Project description
Code
Arduino Code
c_cpp
Atmospheric Gas Analyser Arduino Code
1/*feel free to contact 2 * sreeramaj53@gmail.com 3 * www.youtube.com/ZenoModiff 4 * last updated - time 09:05 PM - date 20 may 2021 5 * Github Link :-- https://github.com/Zenomodiff/Atmospheric-Gas-Ananlyser-With-MQ-Series-Sensors-Dht-11 6 */ 7 8#include <Wire.h> 9#include <LiquidCrystal_I2C.h> 10#include "DHT.h" 11#define DHTPIN 13 12#define DHTTYPE DHT11 13 14DHT dht(DHTPIN, DHTTYPE); 15LiquidCrystal_I2C lcd(0x27, 16, 2); 16 17const int mq2 = A0; 18const int mq4 = A1; 19const int mq5 = A2; 20const int mq135 = A3; 21 22float m = -0.6527; 23float b = 1.30; 24float R0 = 21.91; 25 26void setup() { 27 28 lcd.begin(); 29 lcd.backlight(); 30 lcd.print("Atmosphere"); 31 lcd.setCursor(0,3); 32 lcd.print("Gas Analyser"); 33 delay (3000); 34 lcd.clear(); 35 36 lcd.print("By"); 37 lcd.setCursor(0,3); 38 lcd.print("Zeno Modiff"); 39 delay (3000); 40 lcd.clear(); 41 42 pinMode(mq4, INPUT); 43 pinMode(mq135, INPUT); 44 pinMode(mq5, INPUT); 45 pinMode(mq2, INPUT); 46 47 Serial.begin(9600); 48 dht.begin(); 49} 50 51void loop() { 52 53 float h = dht.readHumidity(); 54 float t = dht.readTemperature(); 55 float f = dht.readTemperature(true); 56 if (isnan(h) || isnan(t) || isnan(f)) { 57 Serial.println(F("Failed to read from DHT sensor!")); 58 return; 59 float hif = dht.computeHeatIndex(f, h); 60 float hic = dht.computeHeatIndex(t, h, false); 61 } 62 double mq4_value = analogToPPM(analogRead(mq4)); 63 double mq135_value = analogToPPM(analogRead(mq135)); 64 double mq5_value = analogToPPM(analogRead(mq5)); 65 double mq2_value = analogToPPM(analogRead(mq2)); 66 67 Serial.println("************************************"); 68 Serial.print("MQ-4 Value: ");Serial.print(mq4_value, DEC);Serial.println(" PPM"); 69 Serial.print("MQ-135 Value: ");Serial.print(mq135_value, DEC);Serial.println(" PPM"); 70 Serial.print("MQ-5 Value: ");Serial.print(mq5_value, DEC);Serial.println(" PPM"); 71 Serial.print("MQ-2 Value: ");Serial.print(mq2_value, DEC);Serial.println(" PPM"); 72 Serial.print("DHT-Temp: ");Serial.print(t);Serial.println(" c"); 73 Serial.print("DHT-Humi: ");Serial.print(h);Serial.println(" %"); 74 Serial.println("************************************\ 75\ 76"); 77 78 lcd.setCursor(0,0); 79 lcd.print("CNG Value"); 80 lcd.setCursor(0,3); 81 lcd.println(mq4_value); 82 lcd.setCursor(7,7); 83 lcd.print("PPM"); 84 delay(3000); 85 lcd.clear(); 86 87 lcd.setCursor(0,0); 88 lcd.print("AQI Value"); 89 lcd.setCursor(0,3); 90 lcd.println(mq135_value); 91 lcd.setCursor(7,7); 92 lcd.print("PPM"); 93 delay(3000); 94 lcd.clear(); 95 96 lcd.setCursor(0,0); 97 lcd.print("LNG"); 98 lcd.setCursor(0,3); 99 lcd.println(mq5_value); 100 lcd.setCursor(7,7); 101 lcd.print("PPM"); 102 delay(3000); 103 lcd.clear(); 104 105 lcd.setCursor(0,0); 106 lcd.print("SMOKE"); 107 lcd.setCursor(0,3); 108 lcd.println(mq2_value); 109 lcd.setCursor(7,7); 110 lcd.print("PPM"); 111 delay(3000); 112 lcd.clear(); 113 114 lcd.setCursor(0,0); 115 lcd.print("DHT-11"); 116 lcd.setCursor(0,3); 117 lcd.print("Temp -"); 118 lcd.setCursor(7,4); 119 lcd.println(t); 120 delay(3000); 121 lcd.clear(); 122 123 lcd.setCursor(0,0); 124 lcd.print("DHT-11"); 125 lcd.setCursor(0,3); 126 lcd.print("Humi -"); 127 lcd.setCursor(7,4); 128 lcd.println(h); 129 delay(3000); 130 lcd.clear(); 131 132} 133 double analogToPPM(int aValue) { 134 float sensor_volt; 135 float RS_gas; 136 float ratio; 137 int sensorValue = aValue; 138 139 sensor_volt = sensorValue*(5.0/1023.0); 140 RS_gas = ((5.0*10.0)/sensor_volt)-10.0; 141 ratio = RS_gas/R0; 142 double ppm_log = (log10(ratio)-b)/m; 143 return ppm_log; 144}
Downloadable files
Schematics
Atmospheric Gas Analyser Circuit
Schematics

Schematics
Atmospheric Gas Analyser Circuit
Schematics

Comments
Only logged in users can leave comments