Learn ESP32, ESP8266, Arduino, and Raspberry Pi

Arduino Guide for MQ2 Gas and Smoke Sensor

We will learn about the MQ2 Gas Sensor Module and how to use it with Arduino board. 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.

Tag: Project 121a MQ2 Gas/Smoke Sensor.

Project resources

  • Sketch: sketch
  • Libraries: None;
  • Other attachements: None.

Parts required

In this project, you needed these parts (Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you):

1. MQ2 Gas/Smoke sensor 1 pc

MQ2 sensor

2. Jumper cables  F-M 7 pcs, jumper cables M-M 5 pcs

jumper cables

3. Arduino Nano and Mini-B USB cable 1 pc


4. Resistor 220 Ohm 3 pcs

resistor 220 ohm

5. Piezo (buzzer) 1 pc

piezo buzzer

6. LED (green and red) 2 pcs


7. Breadboard 1 pc


Understanding the MQ2 Gas sensor module

The MQ-2 Gas sensor can detect or measure gasses like LPG, Smoke, Alcohol, Propane, Hydrogen, Carbon Monoxide (CO) and even Methane concentrations anywhere from 200 to 10000ppm. The module version of this sensor comes with a Digital Pin which makes this sensor to operate even without a microcontroller and that comes in handy when you are only trying to detect one particular gas. When it comes to measuring the gas in ppm the analog pin has to be used, the analog pin also TTL driven and works on 5V and hence can be used with most common microcontrollers.

So if you are looking for a sensor to detect or measure gasses like LPG, Alcohol, Propane, Hydrogen, CO and even methane with or without a microcontroller then this sensor might be the right choice for you.

The major downside of this sensor is that it only senses the concentration of gases in the air, but it can not distiguish among them. For that you may need other types of gas sensors like MQ-6, M-306A and AQ-3 which detect specific type of gases.

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.

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.

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

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.

MQ2 sensor head

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.

MQ2 sensing element

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.

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.

mq2 sensing element


  • Detects or measure Gases like LPG, Alcohol, Propane, Hydrogen, CO and even methane
  • Air quality monitor
  • Gas leak alarm
  • Safety standard maintenance
  • Maintaining environment standards  in hospitals 


Operating voltage5V
Load resistance20 KΩ
Heater resistance33Ω ± 5%
Heating consumption<800mw
Sensing Resistance10 KΩ – 60 KΩ
Concentration Scope200 – 10000ppm
Preheat TimeOver 24 hour

You can find the datasheet here.

MQ2 Equivalent sensors:

MQ-6, AQ-2, MQ-306A, AQ-3

Selecting between Sensor type and module type

When it comes to measuring or detecting a particular Gas the MQ series Gas sensors are the most commonly used ones. These sensors can either be purchased as a module or as just the sensor alone. If you are trying to only detect (not measuring ppm) the presence of a gas then you can buy it as a module since it comes with an op-amp comparator and a digital out pin. But if you planning to measure the ppm of a gas it is recommended to buy the sensor alone (without module).

Alternative MQ Gas sensors:

Sensor NameGas to measure
MQ-2Methane, Butane, LPG, Smoke
MQ-3Alcohol, Ethanol, Smoke
MQ-4Methane, CNG Gas
MQ-5Natural gas, LPG
MQ-6LPG, butane
MQ-7Carbon Monoxide
MQ-8Hydrogen Gas
MQ-9Carbon Monoxide, flammable gasses
MQ135Air Quality
MQ136Hydrogen Sulphide gas
MQ138Benzene, Toluene, Alcohol, Propane, Formaldehyde gas, Hydrogen
MQ214Methane, Natural Gas
MQ216Natural gas, Coal Gas
MQ303AAlcohol, Ethanol, smoke
MQ306ALPG, butane
MQ307ACarbon Monoxide
MQ309ACarbon Monoxide, flammable gas

How does it 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 module provides a binary indication of the presence of combustible gases but also an analog representation of their concentration in air.

MQ2 gas sensor working principle

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 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.

Calibration of MQ2 Gas Sensor

The resistance of the sensor is different depending on the type of the gas.

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.

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, you can turn on or off a relay or start the pump to blow air/sprinkle water.

How to use the MQ2 gas sensor module to measure PPM

If you are looking for some accuracy with your readings then measuring the PPM would be the best way to go with it. It can also help you to distinguish one gas from another. So to measure PPM you can directly use a module. A basic wiring for the sensor from datasheet is shown below.

datasheet MQ2 gas sensor

The procedure to measure PPM using MQ sensor is the same but few constant values will vary based on the type of MQ sensor used. Basically, we need to look into the (Rs/Ro) VS PPM graph given in the datasheet (also shown below).

datasheet MQ2 gas sensor graph

The value of Ro is the value of resistance in fresh air and the value of Rs is the value of resistance in Gas concentration. First, you should calibrate the sensor by finding the values of Ro in fresh air and then use that value to find Rs using the formulae:


Once we calculate Rs and Ro we can find the ratio and then use the graph shown above we can calculate the equivalent value of PPM for that particular gas.

Understanding the Arduino Nano

You can read more about it here.

Signals and connections of the MQ2 gas sensor

Signals and connections of the MQ2 gas sensor
  • VCC – supply pin. Supplies power for the module. Connect it to 5V pin of your Arduino board.
  • GND – ground pin. Connected to GND pin on Arduino board.
  • DO – digital output pin. Provides a digital representation (0 or 1) of the presence of combustible gases.
  • AO – analog output pin. Provides analog output voltage 0-5V in proportional to the concentration of smoke/gas.

Sensor pins:

1H -PinsOut of the two H pins, one pin is connected to supply and the other to ground
2A-PinsThe A pins and B pins are interchangeable. These pins will be tied to the Supply voltage.
3B-PinsThe A pins and B pins are interchangeable.   One pin will act as output while the other will be pulled to ground.

Signals and connections of the Arduino Nano

You can read more about it here.


Wiring MQ2 sensor
Wiring MQ2 sensor

Step by Step instruction

  1. First mount the sensor to a breadboard.
  2. Do wiring.
  3. Open Arduino IDE.
  4. Plug your Arduino Nano board into your PC and select the correct board and com port
  5. Verify and upload sketch to your Arduino Nano.
  6. Open up Arduino IDE Serial monitor and set your baud to 9600 baud and select Both NL&CR.
  7. You can see the analog and digital readings. If If the analog reading is more then threshold value then the red LED will be on and green LED – off , otherwise the green LED will be on and red LED – off.


You can adjust the variable sensorLimit with a different threshold value.

Wrapping up

We have learnt about the MQ2 gas sensor module and how to use it with Arduino Nano.

Check for more DIY projects here.

Thank you for reading and supporting us.

Check for more DIY projects on and!

If you are looking for high quality PCBs PCBWay is the best choice: