Gas Sensor

In this project, you'll learn how to connect and control the MQ-2 gas sensor.

The gas sensor can detect any combustible gases such as LPG, i-butane, propane, methane, alcohol, hydrogen, and smoke.

Specification of the MQ-2 gas sensor:

Parts needed:
  • Arduino
  • Gas sensor MQ-2
  • Wires
  • Breadboard
Gas sensor
1 Making the connections
  • Connect the D0 pin on the sensor to pin 8 on the Arduino.
  • Connect Vcc to 5V.
  • Connect GND to GND.
The module will get slightly hot to the touch.
2 Adjustment

In the absense of all flammable gases, turn the potentiometer until the D0-led just turns off.
3 Create a new BareMinimum program and type in this code.
// MQ-2 Gas Sensor Module
// The D0 digital output pin is active low
// i.e., it outputs a low signal when it detects gas

#define gasPin 8
#define led 13

void setup() {
  pinMode(led, OUTPUT);
  pinMode(gasPin, INPUT);

void loop() {
  // turn on led when it detects gas
  digitalWrite(led, !digitalRead(gasPin));
4 Run the program and test the sensor.