How MQ2 Gas/Smoke Sensor Works? & Interface It With Arduino
Maybe your like
Ever wondered how to make your Arduino smell what’s in the air? With the MQ2 Gas Sensor Module, you can give your project a virtual nose—capable of detecting a wide range of gases including LPG, smoke, alcohol, propane, hydrogen, methane, and even carbon monoxide.
Think of all the cool projects you could create with this sensor. Want to build an indoor air quality monitor that can detect dangerous gases? Interested in making a breathalyzer for a science project? Or perhaps you’d like to design an early warning system that can sense smoke before a fire starts? The MQ2 sensor makes all of these ideas possible!
In this tutorial, we’ll explore how this amazing sensor works, how to hook it up to your Arduino, and how to start experimenting with real-time gas detection.
Let’s dive in and make your next project a bit more nose-smart!
MQ2 Gas Sensor
The MQ2 sensor is one of the most popular sensors in the MQ family. It is a type of MOS (Metal Oxide Semiconductor) sensor. These kinds of sensors are also called chemiresistors because they work by changing their electrical resistance when they come into contact with certain gases.

The MQ2 gas sensor runs on 5 volts of DC power and uses about 800 milliwatts of energy. It can detect several types of gases, including LPG (liquefied petroleum gas), smoke, alcohol, propane, hydrogen, methane, and carbon monoxide. This sensor can detect these gases when their concentrations are between 200 and 10,000 parts per million (ppm).
What does PPM mean?
PPM stands for parts per million, and it’s a common unit used to measure the concentration of a specific gas in the air. It simply represents the ratio of how many gas molecules of one type exist among a million total gas molecules in the air. For example, if the air has 500 ppm of carbon monoxide, that means out of every 1,000,000 gas molecules, 500 are carbon monoxide, and the other 999,500 molecules are different gases.
It’s important to know that while the MQ2 sensor can detect many different gases, it can’t tell you exactly which gas it’s sensing. This might sound strange, but it’s actually how most gas sensors work. Because of this limitation, the MQ2 works best when you’re tracking changes in the amount of a gas you already know is present, rather than trying to figure out what type of gas is changing.
Internal structure of MQ2 Gas Sensor
The MQ2 is a heater-driven sensor, which means it uses heat to detect gases. Because it deals with flammable gases, safety is very important. That’s why the sensor has two layers of very fine stainless steel mesh wrapped around it, known as an “anti-explosion network.” This mesh prevents the heater inside the sensor from causing a fire or explosion if flammable gases are present.

Besides providing safety, this mesh also acts as a protective filter. It blocks dust and solid particles from entering, allowing only gases to pass through to the sensing area. The mesh is held firmly in place by a copper-plated ring that clamps around it and connects to the rest of the sensor body.

If you carefully remove the outer mesh, you can see the inside of the sensor. At its heart is a sensing element attached to six metal legs that stick out from a round base made of Bakelite (a type of hard plastic). These legs are arranged in a star pattern.
Out of the six legs, two of them (labeled H) are used to heat up the sensing element. These two legs are connected by a coil made of Nickel-Chromium alloy. This special metal mixture is good at conducting electricity and can withstand very high temperatures without melting or breaking down.
The other four legs (labeled A and B) are responsible for carrying electrical signals from the sensing element to external electronics. These connect to the sensing element using platinum wires. Platinum is used due to its excellent electrical conductivity and sensitivity to small electrical changes that happen when gas levels change around the sensor.

The sensing element itself looks like a small tube. It’s made from Aluminum Oxide (Al₂O₃) ceramic with a thin coating of Tin Dioxide (SnO₂) on it.
Tin Dioxide is the key material here because it reacts chemically with flammable (combustible) gases, causing changes in resistance that the sensor can measure.
The ceramic base serves an important purpose too. It ensures even distribution of heat and maintains the sensor at the proper operating temperature.
To summarize:
- Outer Mesh (Anti-explosion network): Stainless steel mesh layers for safety and filtering.
- Heating System: Nickel-Chromium coil and Aluminum Oxide ceramic tube for heat generation and distribution.
- Sensing System: Platinum wires and Tin Dioxide coating for detecting gases and measuring resistance changes.
How Does a Gas Sensor Work?
When you turn on an MQ2 gas sensor, it starts heating up its internal Tin Dioxide (SnO₂) semiconductor layer to a high temperature. At this high temperature, oxygen molecules from the air stick (or adsorb, if you prefer the technical term) to the surface of the Tin Dioxide. These adsorbed oxygen molecules pull free electrons away from the Tin Dioxide, which creates an “electron depletion region” near the surface. This makes the Tin Dioxide highly resistant to electrical flow, so only a small amount of electric current can pass through it.
When combustible gases enter the sensor, they react with the oxygen molecules that are stuck to the Tin Dioxide surface. This chemical reaction releases the electrons that were being held by the oxygen. As these electrons return to the Tin Dioxide, the electron depletion region gets smaller. This reduces the resistance, allowing electricity to flow much more easily through the sensor.

The MQ2 sensor works by detecting these changes in electrical resistance. The more flammable gas there is, the more oxygen molecules react, and the more the resistance decreases. This makes it easier for microcontrollers connected to the sensor to detect both the presence and the concentration of gas in the air.
MQ2 Gas Sensor Module Hardware Overview
The MQ2 gas sensor is easy to use and provides both digital output (which indicates whether gases are present) and analog output (which shows the concentration of gas in the air).

The analog output (from the AO pin) changes based on the concentration of gas. When there’s more gas in the air, the output voltage increases. When there’s less gas, the output voltage decreases. The animation below demonstrates this relationship between gas concentration and output voltage.

This analog signal also goes to the LM393 comparator, which compares it to a reference voltage set by a potentiometer on the module.
- When the gas concentration rises above your set level, the comparator outputs a LOW digital signal at the digital pin (DO).
- When the gas concentration stays below your set level, it outputs a HIGH digital signal instead.
You can use this digital output to trigger actions—like sounding an alarm, or sending an alert to your phone.

To adjust how sensitive the sensor is, simply turn the potentiometer. Turning it clockwise increases the threshold (meaning more gas is needed to trigger the alarm), while turning it counterclockwise decreases the threshold (so it will trigger with less gas present).

The module also has two indicator LEDs:
- The Power LED lights up when the module receives power
- The Status LED lights up when the gas concentration exceeds the threshold you’ve set
Technical Specifications
Here are the specifications:
| Operating voltage | 5V |
| Load resistance | 20 KΩ |
| Heater resistance | 33Ω ± 5% |
| Heating consumption | <800mw |
| Sensing Resistance | 10 KΩ – 60 KΩ |
| Concentration Range | 200 – 10000ppm |
| Preheat Time | Over 24 hour |
MQ2 Gas Sensor Module Pinout
The MQ2 gas sensor is extremely simple to use and only requires four pins to connect.

VCC provides power to the sensor. Connect it to the 5V output on your Arduino.
GND is the ground pin.
AO (Analog Output) gives a variable voltage that corresponds to the concentration of gas. The more gas in the air, the higher the output voltage, and the less gas, the lower the voltage. You connect this pin to an analog input on your Arduino (like A0).
DO (Digital Output) outputs a LOW signal when the gas concentration is above the threshold set by the potentiometer and a HIGH signal when it’s below. You connect this to a digital input pin on the Arduino.
Calibrating the MQ2 Gas Sensor
Since the MQ2 sensor is a heater-driven sensor, it needs special preparation before it can work correctly.
If you haven’t used your MQ2 sensor for more than a month, you’ll need to warm it up for 24 to 48 hours. This long warm-up period is necessary because the sensor needs time to reach its normal working condition after sitting unused for so long.
However, if you’ve used your sensor recently, you only need to warm it up for 5 to 10 minutes before using it again.
When you first turn on the sensor during the warm-up time, it might give you wrong readings. Don’t worry! As the sensor heats up and becomes stable, the readings will become more accurate.
Experiment 1 – Measuring Gas Concentration using Analog Output (AO)
In this first experiment, we’ll learn how to measure the concentration of gas in the air using the analog output from the MQ2 gas sensor.
Wiring
Let’s begin by connecting the MQ2 gas sensor module to your Arduino.
Connect the VCC pin on the sensor to the 5V pin on the Arduino, and connect the GND pin on the sensor to one of the GND pins on the Arduino. Finally, connect the AO (Analog Output) pin on the sensor to the A0 analog input pin on the Arduino.
Here’s a quick reference table for the pin connections:
| MQ2 Sensor | Arduino |
| VCC | 5V |
| GND | GND |
| AO | A0 |
Please refer to the image below to see the proper wiring setup.

Finding the threshold value
Before we can determine if gas is present or not, we need to find the typical sensor readings for two conditions:
- When the sensor is exposed to the gas we want to detect.
- When the sensor is in clean air (no gas).
To do this, you’ll need to upload a simple code to the Arduino that reads the analog values from the sensor.
#define MQ2pin 0 float sensorValue; //variable to store sensor value void setup() { Serial.begin(9600); // sets the serial port to 9600 Serial.println("MQ2 warming up!"); delay(20000); // allow the MQ2 to warm up } void loop() { sensorValue = analogRead(MQ2pin); // read analog input pin 0 Serial.print("Sensor Value: "); Serial.println(sensorValue); delay(2000); // wait 2s for next reading }Once the code is running, open the Serial Monitor in the Arduino IDE. Expose the sensor to gas and note the number displayed in the Serial Monitor. Then, remove the gas or let the sensor sit in clean air, and record that number too.
You might see values around:
- 100 when no gas is present
- 400 when gas is present

These values give us a rough idea of how the sensor behaves.
Keep in mind that this part of the experiment may require a few trials. It’s a good idea to repeat the gas and clean air tests several times to make sure your readings are consistent. Once you’re confident in your results, you can use these values to set your threshold in the next part of the experiment.
Arduino Code
The sketch below checks whether the sensor reading goes above the threshold. If it does, that means gas has been detected, and the Arduino will display a message on the Serial Monitor.
/* Change the threshold value with your own reading */ #define Threshold 400 #define MQ2pin 0 float sensorValue; //variable to store sensor value void setup() { Serial.begin(9600); // sets the serial port to 9600 Serial.println("MQ2 warming up!"); delay(20000); // allow the MQ2 to warm up } void loop() { sensorValue = analogRead(MQ2pin); // read analog input pin 0 Serial.print("Sensor Value: "); Serial.print(sensorValue); if (sensorValue > Threshold) { Serial.print(" | Gas detected!"); } Serial.println(""); delay(2000); // wait 2s for next reading }After uploading and running that code, you should see a clear message from your Arduino when gas is present.

Experiment 2 – Detecting the Presence of Gas using Digital Output (DO)
In this second experiment, we’re going to use the digital output from the MQ2 gas sensor to detect whether gas is present in the air.
Wiring
We’ll use the same circuit setup from the first experiment, with just one small change. You’ll need to disconnect the wire that was connected to the A0 analog input pin on the Arduino. Then, connect the DO (digital output) pin of the MQ2 sensor module to digital pin 8 on the Arduino.
Here’s a quick reference table for the pin connections:
| MQ2 Sensor | Arduino |
| VCC | 5V |
| GND | GND |
| DO | 8 |
Please refer to the image below to see the proper wiring setup.

Setting the threshold
The MQ2 sensor has a small potentiometer. This lets you set the gas concentration threshold—the point at which the sensor switches its digital output. When the gas concentration goes above this point, the sensor will turn on the Status LED, and set the digital output (DO pin) to LOW.

To adjust this threshold, first expose the sensor to the gas you want to detect. Slowly turn the potentiometer clockwise until the status LED turns on, then carefully turn it back counterclockwise just until the LED turns off.
That’s it! You’ve now set the threshold level.
Arduino Code
Now, upload the sketch below to your Arduino.
#define MQ2pin 8 int sensorValue; //variable to store sensor value void setup() { Serial.begin(9600); // sets the serial port to 9600 Serial.println("MQ2 warming up!"); delay(20000); // allow the MQ2 to warm up } void loop() { sensorValue = digitalRead(MQ2pin); // read digital output pin Serial.print("Digital Output: "); Serial.print(sensorValue); // Determine the status if (sensorValue) { Serial.println(" | Gas: -"); } else { Serial.println(" | Gas: Detected!"); } delay(2000); // wait 2s for next reading }Once the sketch is running, the Arduino will read the digital signal from the sensor and print the result to the Serial Monitor.

Tag » Arduino Mq2 Sketch
-
Smoke Detection Using MQ-2 Gas Sensor - Arduino Project Hub
-
How To Connect MQ2 Gas Sensor To Arduino
-
MQ-2 Gas Sensor Arduino - Arduino Project Hub
-
Arduino MQ-2 Gas Sensor Tutorial - Circuit Digest
-
MQ2 Sensor Interfacing With Arduino - Gas And Smoke Detection
-
Guide For MQ-2 Gas Sensor With Arduino - Random Nerd Tutorials
-
How To Use MQ2 Gas Sensor - Arduino Tutorial - Instructables
-
[arduino-tutorial] MQ-2 GAS Sensor By silakis - Codebender
-
Arduino Gas Sensor MQ2, Smoke Detector, Programming & Circuit
-
Interfacing MQ2 To Arduino- Gas Sensor For Smoke-Butane-CH4 And ...
-
Interfacing MQ2 To Arduino-MQ2 Gas And Smoke Sensor
-
How To Connect MQ2 Gas Sensor To Arduino - YouTube
-
Arduino Mq2 Sketch Archives - Electronic Clinic