Example of the MQ2 MQ-2 Smoke / Gas Sensor Program with Arduino

Spread the love

Description of MQ2 / MQ-2 Sensor Module

In this article we will give an example of the MQ2 / MQ-2 smoke / gas sensor program using Arduino UNO. Previously, we discussed a little about what is the MQ2 / MQ-2 smoke / gas sensor.

MQ2 or MQ-2 is a sensor module that can be used to detect smoke or flammable gases at concentrations between 200 ppm – 10,000 ppm.

Any gas that can be detected by MQ2 includes LPG, Hydrogen (H2), Methane (CH4), Carbon Monoxide (CO), Alcohol, Smoke (Smoke) and Propane. This sensor is designed for indoor use at room temperature. Usually applied to the combustible gas leak detection equipment in a house, agency, warehouse or industrial factory.

This is a precautionary measure because if there is a gas that has been leaked it has been detected from the beginning and action can be taken immediately so that it can prevent fires. In addition to Fire Prevention Tools, MQ2 can also be used as a tool for Air Quality Monitoring.

Modul Sensor MQ2 / MQ-2

How Does MQ2 / MQ-2 Work?

MQ2 or MQ-2 is a Metal Oxide Semiconductor (MOS) type gas sensor or also known as Chemiresistors because the detection is based on changing the resistance value of the material / material from the sensor when the material / material is in contact with the gas detected.

By using a voltage divider circuit construction, the content of a gas can be measured / obtained. The resistance value of the MQ2 sensor is directly proportional to the level or concentration of a gas detected.


  • Power indicator LED
  • TTL output signal LED
  • Digital output DO
  • Analog output AO
  • TTL output (DO) active Low
  • The more gas concentrations detected, the higher AO voltage
  • dimension : 32 (L) * 20 (W) * 22 (H)
  • Input voltage : DC5V 
  • Power consumption ( current ) : 150mA
  • DO output : TTL digital 0 and 1 (0.1 and 5V)
  • AO output : 0.1 – 4 V

Hardware Required

  • Arduino Uno or Others
  • MQ-2 sensor modul
  • LED
  • Buzzer
  • Some of jumper cabel Dupont M-F or F-F



Basic Program

The following is an example of a simple program to read the output of the MQ2 sensor (A0), then turn on the LED and sound the buzzer if the readout from the MQ2 sensor exceeds the Threshold limit value that we set.

const int mqxPin = A0;  // pin A0 MQ2 connected to pin analog A0 Arduino
int redLed = 12;  // LED connected to pin 12 Arduino
int buzzer = 10;  // Buzzer connected to pin 10 Arduino 
int sensorThres = 400; // Threshold value of pin A0 that we desired which indicate concentration of gas detected by Sensor

void setup()
    pinMode(mqxPin, INPUT);
    pinMode(redLed, OUTPUT);
    pinMode(buzzer, OUTPUT);
    Serial.begin(9600); // Initialization Serial Monitor at Baudrate = 9600 

void loop()
    int analogSensor = analogRead(mqxPin);
    Serial.print("Output MQ-2 : ");
// Check whether it is greater than the threshold value 
   if (analogSensor > sensorThres)
     digitalWrite(redLed, HIGH);
     tone(buzzer, 1000, 200);
     digitalWrite(redLed, LOW);
   delay(1000);  // Delay 1 second for next reading

This is an example of a simple MQ2 / MQ-2 sensor program using Arduino to detect smoke or flammable gas at a certain level that will trigger or sound the buzzer and turn on the LED as an alarm.

For a more detailed example of the MQ2 program that is measuring the concentration of various gases in the air, please study the following article :

Interfacing MQ-MQ-2 Smoke / Gas Sensor Module Using Arduino To Measure Combustible Gas Concentration

In the article link above, MQ2 is used to measure the content or concentration of gases: LPG, Hydrogen (H2), Methane (CH4), Carbon Monoxide (CO), Alcohol, Smoke (Smoke) and Propane in ppm units.

++++++++ Hope This Useful ++++++++

Be the first to comment

Leave a Reply

Your email address will not be published.