User Tools

Site Tools


amc2021:groupl:code:carbon_dioxide_measuring

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
amc2021:groupl:code:carbon_dioxide_measuring [2021/09/05 02:57] kabir001amc2021:groupl:code:carbon_dioxide_measuring [2023/01/05 14:38] (current) – external edit 127.0.0.1
Line 3: Line 3:
 This code communicates with the MQ135 air quality sensor with the help of the [[amc2021:groupl:extras:mq-135:start|MQ135.h library]]. The sensor is supposed to preheat for 24 hours before taking readings. This code communicates with the MQ135 air quality sensor with the help of the [[amc2021:groupl:extras:mq-135:start|MQ135.h library]]. The sensor is supposed to preheat for 24 hours before taking readings.
 Once the code runs, it prints out the concentration of detected gases in ppm on a serial monitor, and the results are displayed on an LCD screen. Once the code runs, it prints out the concentration of detected gases in ppm on a serial monitor, and the results are displayed on an LCD screen.
-An alarm system (LED light) is also set to glow if the CO<sub>2<\sub> values cross a threshold value of 1000ppm. +An alarm system (LED light) is also set to glow if the CO<sub>2</sub> values cross a threshold value of 1000ppm. 
  
 Detailed explanation is given in the [[amc2021:groupl:video:start|video tutorial]]  Detailed explanation is given in the [[amc2021:groupl:video:start|video tutorial]] 
Line 9: Line 9:
 <file c++ CO2Sensor.ino> <file c++ CO2Sensor.ino>
                                                              
-#include "MQ135.h"+#include "MQ135.h" //Main library that contains functions to get the ppm values
 #include <Wire.h>  #include <Wire.h> 
 #include <LiquidCrystal_I2C.h>  //Header file for LCD #include <LiquidCrystal_I2C.h>  //Header file for LCD
Line 15: Line 15:
 LiquidCrystal_I2C lcd(0x27,16,2);//set the LCD address to x27 for a 16 chars and 2 line display LiquidCrystal_I2C lcd(0x27,16,2);//set the LCD address to x27 for a 16 chars and 2 line display
  
-#define led          9                       //led on pin 9 +#define led          9                  //led on pin 9 
-const int gas_pin = A0;                      //analog feed from MQ135 +const int gas_pin = A0;                 //analog feed from MQ135 
-MQ135 gasSensor = MQ135(gas_pin);+MQ135 gasSensor = MQ135(gas_pin);       //Define the gas pin in the function mq135 gas sensor as per the mq135 library 
  
 void setup(){ void setup(){
  
   lcd.init();                      // initialize the lcd    lcd.init();                      // initialize the lcd 
-  lcd.begin(16,2);                  // consider 16 chars + 2 lines lcd+  lcd.begin(16,2);                 // consider 16 chars + 2 lines lcd
   lcd.backlight();                 // illuminate to produce visible reading   lcd.backlight();                 // illuminate to produce visible reading
   lcd.clear();                     // clear lcd   lcd.clear();                     // clear lcd
   lcd.setCursor(4,0);              //set cursor of lcd to 1st row and 5th column   lcd.setCursor(4,0);              //set cursor of lcd to 1st row and 5th column
-  lcd.print("Group L");          // print as a sentence on lcd+  lcd.print("Group L");            // print as a sentence on lcd
  
   pinMode(gas_pin,INPUT);     //MQ135 analog feed set for input   pinMode(gas_pin,INPUT);     //MQ135 analog feed set for input
Line 35: Line 35:
  
 void loop(){ void loop(){
- float ppm = gasSensor.getPPM();+ float ppm = gasSensor.getPPM(); //function to get ppm value based on the MQ135.h library
  Serial.println(ppm);            // print ppm on serial monitor  Serial.println(ppm);            // print ppm on serial monitor
  delay(1000);                      delay(1000);                    
    lcd.clear();                  // clear lcd    lcd.clear();                  // clear lcd
-   lcd.setCursor(0,0);          // set cursor of lcd to 1st row and 1st column +   lcd.setCursor(0,0);           // set cursor of lcd to 1st row and 1st column 
-   lcd.print("Air Quality: ");  // print as a sentence on lcd +   lcd.print("Air Quality: ");   // print as a sentence on lcd 
-   lcd.print(ppm);             // print value of MQ135 +   lcd.print(ppm);               // print value of MQ135 
- if(ppm>999){                  //if co2 ppm > 1000 + if(ppm>999){                    //if co2 ppm > 1000 
-    digitalWrite(led,HIGH);    //turn on led +    digitalWrite(led,HIGH);      //turn on led 
-    lcd.setCursor(2,1);        // set cursor of lcd to 2nd row and 3rd column +    lcd.setCursor(2,1);          // set cursor of lcd to 2nd row and 3rd column 
-    lcd.print("AQ Level BAD");  //print as a sentence on lcd+    lcd.print("AQ Level BAD");   //print as a sentence on lcd
    }    }
  else{                else{              
-    digitalWrite(led,LOW);         //turn off led +    digitalWrite(led,LOW);       //turn off led 
-    lcd.setCursor(1,1);            // set cursor of lcd to 2nd row and 2nd column +    lcd.setCursor(1,1);          // set cursor of lcd to 2nd row and 2nd column 
-    lcd.print ("AQ Level Good");   // print as a sentence on lcd+    lcd.print ("AQ Level Good"); // print as a sentence on lcd
   }   }
  
Line 56: Line 56:
  
 </file> </file>
 +[[amc2021:groupl:report:start|Back to report]]
  
  
  
amc2021/groupl/code/carbon_dioxide_measuring.1630803433.txt.gz · Last modified: 2023/01/05 14:38 (external edit)