Devices & Components
16x2 LCD display with I²C interface
Arduino Nano
MQ8 Gas sensor
MQ7 Gas sensor
MQ4 Gas sensor
MQ9 Gas sensor
MQ135 Gas sensor
MQ3 Gas sensor
Hardware & Tools
Breadboard, 830 Tie Points
Software & Tools
Arduino IDE
Project description
Code
air_analyser code
arduino
1#include <Wire.h> 2#include <LiquidCrystal_I2C.h> 3 4 5#define LCD_I2C_ADDRESS 0x3f 6#define LCD_DISP_COLS 16 7#define LCD_DISP_ROWS 2 8 9#include <MQUnifiedsensor.h> 10 11#define Board ("Arduino NANO") 12#define Pin3 (A0) //Analog input 0 of your arduino 13#define Pin4 (A1) //Analog input 1 of your arduino 14#define Pin135 (A2) //Analog input 2 of your arduino 15#define Pin7 (A3) //Analog input 3 of your arduino 16#define Pin8 (A6) //Analog input 6 of your arduino 17#define Pin9 (A7) //Analog input 7 of your arduino 18 19LiquidCrystal_I2C lcd( LCD_I2C_ADDRESS, LCD_DISP_COLS, LCD_DISP_ROWS ); 20 21 22#define RatioMQ3CleanAir (60) //RS / R0 = 60 ppm 23#define RatioMQ4CleanAir (4.4) //RS / R0 = 4.4 ppm 24#define RatioMQ135CleanAir (3.6) //RS / R0 = 10 ppm 25#define RatioMQ7CleanAir (27.5) //RS / R0 = 27.5 ppm 26#define RatioMQ8CleanAir (70) //RS / R0 = 70 ppm 27#define RatioMQ9CleanAir (9.6) //RS / R0 = 9.6 ppm 28#define ADC_Bit_Resolution (10) // 10 bit ADC 29#define Voltage_Resolution (5) // Volt resolution to calc the voltage 30#define Type ("Arduino NANO") //Board used 31//Declare Sensor 32MQUnifiedsensor MQ3(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin3, Type); 33MQUnifiedsensor MQ4(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin4, Type); 34MQUnifiedsensor MQ135(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin135, Type); 35MQUnifiedsensor MQ7(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin7, Type); 36MQUnifiedsensor MQ8(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin8, Type); 37MQUnifiedsensor MQ9(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin9, Type); 38 39 40void setup() { 41 Serial.begin(9600); 42 lcd.begin(); 43 44 lcd.backlight(); 45 46 lcd.setCursor (0,0); 47 lcd.print(" "); 48 lcd.setCursor (0,1); 49 lcd.print(" "); 50 lcd.setCursor (0,0); 51 lcd.print(" Air"); 52 lcd.setCursor (0,1); 53 lcd.print(" Analyzer"); 54 delay(1000); 55 lcd.setCursor (12,1); 56 lcd.print("."); 57 delay(1000); 58 lcd.setCursor (13,1); 59 lcd.print("."); 60 delay(1000); 61 lcd.setCursor (14,1); 62 lcd.print("."); 63 delay(1000); 64 lcd.setCursor (15,1); 65 lcd.print("."); 66 delay(1000); 67 68 MQ3.init(); 69 MQ3.setRegressionMethod(1); //_PPM = a*ratio^b 70 MQ3.setR0(0.45); 71 MQ4.init(); 72 MQ4.setRegressionMethod(1); //_PPM = a*ratio^b 73 MQ4.setR0(14.23); 74 MQ135.init(); 75 MQ135.setRegressionMethod(1); //_PPM = a*ratio^b 76 MQ135.setR0(9.03); 77 MQ7.init(); 78 MQ7.setRegressionMethod(1); //_PPM = a*ratio^b 79 MQ7.setR0(5.90); 80 MQ8.init(); 81 MQ8.setRegressionMethod(1); //_PPM = a*ratio^b 82 MQ8.setR0(0.91); 83 MQ9.init(); 84 MQ9.setRegressionMethod(1); //_PPM = a*ratio^b 85 MQ9.setR0(13.93); 86 87 88 89//While calibrating Your sensor Uncomment this calibration portion and calibrate for R0. 90 /***************************** MQ CAlibration ******************************************** 91 Serial.print("Calibrating please wait."); 92 float MQ3calcR0 = 0, 93 MQ4calcR0 = 0, 94 MQ135calcR0 = 0, 95 MQ7calcR0 = 0, 96 MQ8calcR0 = 0, 97 MQ9calcR0 = 0; 98 for (int i = 1; i <= 10; i ++) 99 { 100 //Update the voltage lectures 101 MQ3.update(); 102 MQ4.update(); 103 MQ135.update(); 104 MQ7.update(); 105 MQ8.update(); 106 MQ9.update(); 107 108 MQ3calcR0 += MQ3.calibrate(RatioMQ3CleanAir); 109 MQ4calcR0 += MQ4.calibrate(RatioMQ4CleanAir); 110 MQ135calcR0 += MQ135.calibrate(RatioMQ135CleanAir); 111 MQ7calcR0 += MQ7.calibrate(RatioMQ7CleanAir); 112 MQ8calcR0 += MQ8.calibrate(RatioMQ8CleanAir); 113 MQ9calcR0 += MQ9.calibrate(RatioMQ9CleanAir); 114 115 Serial.print("."); 116 } 117 MQ3.setR0(MQ3calcR0 / 10); 118 MQ4.setR0(MQ4calcR0 / 10); 119 MQ135.setR0(MQ135calcR0 / 10); 120 MQ7.setR0(MQ7calcR0 / 10); 121 MQ8.setR0(MQ8calcR0 / 10); 122 MQ9.setR0(MQ9calcR0 / 10); 123 Serial.println(" done!."); 124 125 Serial.print("(MQ3 - MQ9):"); 126 Serial.print(MQ3calcR0 / 10); Serial.print(" | "); 127 Serial.print(MQ4calcR0 / 10); Serial.print(" | "); 128 Serial.print(MQ135calcR0 / 10); Serial.print(" | "); 129 Serial.print(MQ7calcR0 / 10); Serial.print(" | "); 130 Serial.print(MQ8calcR0 / 10); Serial.print(" | "); 131 Serial.print(MQ9calcR0 / 10); Serial.println(" |"); 132 133 /***************************** MQ CAlibration ********************************************/ 134} 135 136void loop() { 137 //Update the voltage lectures 138 MQ3.update(); 139 MQ4.update(); 140 MQ135.update(); 141 MQ7.update(); 142 MQ8.update(); 143 MQ9.update(); 144 145 146 MQ3.setA(0.3934); MQ3.setB(-1.504); //Alcohol 147float Alcohol = MQ3.readSensor(); 148 149 MQ3.setA(4.8387); MQ3.setB(-2.68); //Benzene 150float Benzene = MQ3.readSensor(); 151 152 MQ3.setA(7585.3); MQ3.setB(-2.849); //Hexane 153float Hexane = MQ3.readSensor(); 154 155 MQ4.setA(1012.7); MQ4.setB(-2.786); //CH4 156float CH4 = MQ4.readSensor(); 157 158 MQ4.setA(30000000); MQ4.setB(-8.308); //smoke 159float smoke = MQ4.readSensor(); 160 161 MQ135.setA(110.47); MQ135.setB(-2.862); //CO2 162float CO2 = MQ135.readSensor(); 163 164 MQ135.setA(44.947); MQ135.setB(-3.445); // Toluene 165float Toluene = MQ135.readSensor(); 166 167 MQ135.setA(102.2 ); MQ135.setB(-2.473); //NH4 168float NH4 = MQ135.readSensor(); 169 170 MQ135.setA(34.668); MQ135.setB(-3.369); //Acetone 171float Acetone = MQ135.readSensor(); 172 173 MQ7.setA(99.042); MQ7.setB(-1.518); //CO 174float CO = MQ7.readSensor(); 175 176 MQ8.setA(976.97); MQ8.setB(-0.688); // H2 177float H2 = MQ8.readSensor(); 178 179 MQ9.setA(1000.5); MQ9.setB(-2.186); //flamable gas 180float FG = MQ9.readSensor(); 181 182 183 184 Serial.print("Alcohol: "); Serial.println(Alcohol); 185 Serial.print("Benzene: "); Serial.println(Benzene); 186 Serial.print("Hexane: "); Serial.println(Hexane); 187 Serial.print("Methane: "); Serial.println(CH4); 188 Serial.print("Smoke: "); Serial.println(smoke); 189 Serial.print("CO2: "); Serial.println(CO2); 190 Serial.print("Toluene: "); Serial.println(Toluene); 191 Serial.print("NH4: "); Serial.println(NH4); 192 Serial.print("Acetone: "); Serial.println(Acetone); 193 Serial.print("CO: "); Serial.println(CO); 194 Serial.print("H2: "); Serial.println(H2); 195 Serial.print("FG: "); Serial.println(FG); 196 Serial.println("--------------------------------------------------------"); 197 198lcd.clear(); 199delay(70); 200lcd.setCursor (0,0); 201lcd.print("Alcohol "); 202lcd.print(Alcohol); 203lcd.setCursor (13,0); 204lcd.print("ppm"); 205lcd.setCursor (0,1); 206lcd.print("Benzene "); 207lcd.print(Benzene); 208lcd.setCursor (13,1); 209lcd.print("ppm"); 210delay(3000); 211 212lcd.clear(); 213delay(70); 214lcd.setCursor (0,0); 215lcd.print("Hexane "); 216lcd.print(Hexane); 217lcd.setCursor (13,0); 218lcd.print("ppm"); 219lcd.setCursor (0,1); 220lcd.print("CH4 "); 221lcd.print(CH4); 222lcd.setCursor (13,1); 223lcd.print("ppm"); 224delay(3000); 225 226 227lcd.clear(); 228delay(70); 229lcd.setCursor (0,0); 230lcd.print("Smoke "); 231lcd.print(smoke); 232lcd.setCursor (13,0); 233lcd.print("ppm"); 234lcd.setCursor (0,1); 235lcd.print("CO2 "); 236lcd.print(CO2); 237lcd.setCursor (13,1); 238lcd.print("ppm"); 239delay(3000); 240 241 242lcd.clear(); 243delay(70); 244lcd.setCursor (0,0); 245lcd.print("Toluene "); 246lcd.print(Toluene); 247lcd.setCursor (13,0); 248lcd.print("ppm"); 249lcd.setCursor (0,1); 250lcd.print("NH4 "); 251lcd.print(NH4); 252lcd.setCursor (13,1); 253lcd.print("ppm"); 254delay(3000); 255 256 257lcd.clear(); 258delay(70); 259lcd.setCursor (0,0); 260lcd.print("Acetone "); 261lcd.print(Acetone); 262lcd.setCursor (13,0); 263lcd.print("ppm"); 264lcd.setCursor (0,1); 265lcd.print("CO "); 266lcd.print(CO); 267lcd.setCursor (13,1); 268lcd.print("ppm"); 269delay(3000); 270 271 272lcd.clear(); 273delay(70); 274lcd.setCursor (0,0); 275lcd.print("H2 "); 276lcd.print(H2); 277lcd.setCursor (13,0); 278lcd.print("ppm"); 279lcd.setCursor (0,1); 280lcd.print("FG "); 281lcd.print(FG); 282lcd.setCursor (13,1); 283lcd.print("ppm"); 284delay(3000); 285 286} 287
Downloadable files
air analyser_scm
air analyser_scm

air analyser_scm
air analyser_scm

Comments
Only logged in users can leave comments