Give your next Arduino project a nose for gasses with the MQ2 Gas Sensor Module. This is a robust Gas sensor suitable for sensing LPG, Smoke, Alcohol, Propane, Hydrogen, Methane and Carbon Monoxide concentrations in the air. If you are planning on creating an indoor air quality monitoring system; breath checker or early fire detection system, MQ2 Gas Sensor Module is a great choice.

What is MQ2 Gas Sensor?

MQ2 is one of the commonly used gas sensors in MQ sensor series. It is a Metal Oxide Semiconductor (MOS) type Gas Sensor also known as Chemiresistors as the detection is based upon change of resistance of the sensing material when the Gas comes in contact with the material. Using a simple voltage divider network, concentrations of gas can be detected.

MQ2 Gas Sensor

MQ2 Gas sensor works on 5V DC and draws around 800mW. It can detect LPG, Smoke, Alcohol, Propane, Hydrogen, Methane and Carbon Monoxide concentrations anywhere from 200 to 10000ppm.

What is 1 ppm equal to?

When measuring gases like carbon dioxide, oxygen, or methane, the term concentration is used to describe the amount of gas by volume in the air. The 2 most common units of measurement are parts-per-million, and percent concentration.

Parts-per-million (abbreviated ppm) is the ratio of one gas to another. For example, 1,000ppm of CO means that if you could count a million gas molecules, 1,000 of them would be of carbon monoxide and 999,000 molecules would be some other gases.

Here are the complete specifications

MQ2 Gas sensor specifications
Operating voltage 5V
Load resistance 20 KΩ
Heater resistance 33Ω ± 5%
Heating consumption <800mw
Sensing Resistance 10 KΩ – 60 KΩ
Concentration Scope 200 – 10000ppm
Preheat Time Over 24 hour

For more details, please refer this Datasheet.

TIP

The sensor is sensitive to multiple gasses – but cannot tell which it is! That’s normal; most gas sensors are like that. So, it is best for measuring changes in a known gas density, not detecting which is changing.

Internal structure of MQ2 Gas Sensor

The sensor is actually enclosed in two layers of fine stainless steel mesh called Anti-explosion network. It ensures that heater element inside the sensor will not cause an explosion, as we are sensing flammable gases.

MQ2 Gas Sensor Parts Hardware Overview

It also provides protection for the sensor and filters out suspended particles so that only gaseous elements are able to pass inside the chamber. The mesh is bound to rest of the body via a copper plated clamping ring.

Inside Gas Sensor Internal Structure with Sensing Element & Connecting Legs

This is how the sensor looks like when outer mesh is removed. The star-shaped structure is formed by the sensing element and six connecting legs that extend beyond the Bakelite base. Out of six, two leads (H) are responsible for heating the sensing element and are connected through Nickel-Chromium coil, well known conductive alloy.

The remaining four leads (A & B) responsible for output signals are connected using Platinum Wires. These wires are connected to the body of the sensing element and convey small changes in the current that passes through the sensing element.

Sensing Element - Aluminium Oxide Ceramic with Tin Dioxide Coating

The tubular sensing element is made up of Aluminum Oxide (AL2O3) based ceramic and has a coating of Tin Dioxide (SnO2). The Tin Dioxide is the most important material being sensitive towards combustible gases. However, the ceramic substrate merely increases heating efficiency and ensures the sensor area is heated to a working temperature constantly.

MQ2 Gas Sensor Internal Structure Sensing Element

So, the Nickel-Chromium coil and Aluminum Oxide based ceramic forms a Heating System; while Platinum wires and coating of Tin Dioxide forms a Sensing System.

How does a gas sensor work?

When tin dioxide (semiconductor particles) is heated in air at high temperature, oxygen is adsorbed on the surface. In clean air, donor electrons in tin dioxide are attracted toward oxygen which is adsorbed on the surface of the sensing material. This prevents electric current flow.

In the presence of reducing gases, the surface density of adsorbed oxygen decreases as it reacts with the reducing gases. Electrons are then released into the tin dioxide, allowing current to flow freely through the sensor.

MQ2 Gas Sensor Working

Hardware Overview – MQ2 Gas Sensor Module

Since MQ2 Gas Sensor is not breadboard compatible, we do recommend this handy little breakout board. It’s very easy to use and comes with two different outputs. It not only provides a binary indication of the presence of combustible gases but also an analog representation of their concentration in air.

MQ2 Gas Sensor Module

The analog output voltage provided by the sensor changes in proportional to the concentration of smoke/gas. The greater the gas concentration, the higher is the output voltage; while lesser gas concentration results in low output voltage. The following animation illustrates the relationship between gas concentration and output voltage.

MQ2 Gas Sensor Module Output

The analog signal from MQ2 Gas sensor is further fed to LM393 High Precision Comparator (soldered on the bottom of the module), of course to digitize the signal. Along with the comparator is a little potentiometer you can turn to adjust the sensitivity of the sensor. You can use it to adjust the concentration of gas at which the sensor detects it.

Calibrate MQ2 Gas Sensor Module

To calibrate the gas sensor you can hold the gas sensor near smoke/gas you want to detect and keep turning the potentiometer until the Red LED on the module starts glowing. Turn the screw clockwise to increase sensitivity or anticlockwise to decrease sensitivity.

MQ2 Gas Sensor Module Sensitivity Adjustment Potentiometer

The comparator on the module continuously checks if the analog pin (A0) has hit the threshold value set by potentiometer. When it crosses the threshold, the digital pin (D0) will go HIGH and signal LED turns on. This setup is very useful when you need to trigger an action when certain threshold is reached. For example, when the smoke crosses a threshold, you can turn on or off a relay or instruct your robot to blow air/sprinkle water. You got the idea!

MQ2 Gas Sensor Module Pinout

Now let’s have a look at the pinout.

MQ2 Gas Sensor Module Pinout

VCC supplies power for the module. You can connect it to 5V output from your Arduino.

GND is the Ground Pin and needs to be connected to GND pin on the Arduino.

D0 provides a digital representation of the presence of combustible gases.

A0 provides analog output voltage in proportional to the concentration of smoke/gas.

Wiring – Connecting MQ2 Gas Sensor Module to Arduino UNO

Now that we have a complete understanding of how MQ2 Gas sensor works, we can begin hooking it up to our Arduino!

Connecting the MQ2 Gas sensor module to the Arduino is pretty easy. Start by placing the sensor on to your breadboard. Connect VCC pin to the 5V pin on the Arduino and connect GND pin to the Ground pin on the Arduino.

Connect D0 output pin on the module to Digital pin#8 on the Arduino and A0 output pin on the module to Analog pin#0 on the Arduino.

When you’re done you should have something that looks similar to the illustration shown below.

Arduino Wiring Fritzing Connections with MQ2 Gas Sensor
Wiring MQ2 Gas Sensor Module with Arduino UNO

So now that we’ve hooked up our gas sensor it’s time to write some code and test it out.

Arduino Code

The code is very simple & basically just keeps reading analog voltage on A0 pin. It also prints a message on serial monitor when smoke is detected. Try the sketch out, before we begin its detailed breakdown.

#define MQ2pin (0)

float sensorValue;  //variable to store sensor value

void setup()
{
  Serial.begin(9600); // sets the serial port to 9600
  Serial.println("Gas sensor warming up!");
  delay(20000); // allow the MQ-6 to warm up
}

void loop()
{
  sensorValue = analogRead(MQ2pin); // read analog input pin 0
  
  Serial.print("Sensor Value: ");
  Serial.print(sensorValue);
  
  if(sensorValue > 300)
  {
    Serial.print(" | Smoke detected!");
  }
  
  Serial.println("");
  delay(2000); // wait 2s for next reading
}

The sketch starts by defining Arduino pin to which analog pin of MQ2 gas sensor is connected. A variable called sensorValue is also defined to store sensor value.

#define MQ2pin (0)
float sensorValue;  //variable to store sensor value

In setup function: we initialize serial communications with the PC and wait for 20 seconds to allow sensor to warm up.

Serial.begin(9600); // sets the serial port to 9600
Serial.println("Gas sensor warming up!");
delay(20000); // allow the MQ-6 to warm up

In loop function: the sensor value is read by analogRead() function and displayed on serial monitor.

sensorValue = analogRead(MQ2pin); // read analog input pin 0  
Serial.print("Sensor Value: ");
Serial.print(sensorValue);

When the gas concentration is high enough, the sensor usually outputs value greater than 300. We can monitor this value using if statement. And when the sensor value exceeds 300, we will display ‘Smoke Detected!’ message.

  if(sensorValue > 300)
  {
    Serial.print(" | Smoke detected!");
  }

The output on the serial monitor looks like:

MQ2 Gas Sensor Module Arduino Sketch Output on serial window