Interfacing Mq2 Sensor With Arduino Uno

interfacing mq2 sensor with arduino

The MQ2 gas sensor that detect the various type of gases like LPG, propane, methane, carbon monoxide, alcohol and smoke. it is commonly using in the gas leakage detection and air quality monitoring.

Share Button

To connect the MQ2 sensor with Arduino is done by proper wiring. you need to take care of the pinout of the Mq2 gas sensor.

MQ-2 VCC -> Arduino 5V
MQ-2 GND -> Arduino GND
MQ-2 OUT -> Analouge and digital pinout

Programming Code

  #include <MQ2.h>
  #include <Wire.h> 
  #include <LiquidCrystal_I2C.h>
  //I2C pins declaration
  LiquidCrystal_I2C lcd(0x27, 16, 2);
int Analog_Input = A0;
int lpg, co, smoke;

MQ2 mq2(Analog_Input);

void setup(){
  Serial.begin(9600);
  lcd.begin();//Defining 16 columns and 2 rows of lcd display
  lcd.backlight();
  mq2.begin();
}
void loop(){
  float* values= mq2.read(true); //set it false if you don't want to print the values in the Serial
  //lpg = values[0];
  lpg = mq2.readLPG();
  //co = values[1];
  co = mq2.readCO();
  //smoke = values[2];
  smoke = mq2.readSmoke();
  lcd.setCursor(0,0);
  lcd.print("LPG:");
  lcd.print(lpg);
  lcd.print(" CO:");
  lcd.print(co);
  lcd.setCursor(0,1);
  lcd.print("SMOKE:");
  lcd.print((smoke*100)/1000000);
  lcd.print(" %");
  delay(1000);
}

Complete code and library files are Here

Leave a Reply

Your email address will not be published. Required fields are marked *