Skip to content
Home » Arduino » Arduino Projects » How to Connect MQ2 Gas Sensor to Arduino

How to Connect MQ2 Gas Sensor to Arduino

    MQ2 Gas Sensor to Arduino

    MQ2  Sensor is a gas module and it is suitable to detect Hydrogen, LPG, Smoke, CO, and Alcohol. It has high sensitivity and fast response time to measure and take the data. Sensitivity can be adjusted by potentiometer behind it

    MQ2 Sensor Pin Configuration

    Circuit

    MQ2 Connections with Arduino

    MQ2 Connections with Arduino and IIC LCD Display

    Connections

    Arduino              MQ2

    AO                       A0

    5V                     VCC

    GND                   GND

    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();
      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);
      lcd.print(" PPM");
      delay(1000);
    }
    

    Download MQ2 Library

    Download I2C LCD Display Library

    Watch Video

    Considerations for the detection of hydrocarbon gases for risk control

    1. Methane is lighter than air (possibility of accumulation under roofs)
    2. Ethane is slightly heavier than air (possibility of pooling at ground levels/pits)
    3. Propane is heavier than air (possibility of pooling at ground levels/pits)
    4. Butane is heavier than air (possibility of pooling at ground levels/pits)

    If you have any queries feel free to connect us on social handles Facebook

    Leave a Reply

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

    Exit mobile version