Introduction: Interface MQ2 Gas/Smoke Sensor With Arduino: Step-by-Step Guide

Enhance your future Arduino project’s capability by integrating the MQ2 gas sensor module, enabling it to detect various gases such as LPG, smoke, alcohol, propane, hydrogen, methane, and carbon monoxide concentrations in the surrounding air.

The MQ2 Gas Sensor Module’s versatility makes it an ideal selection for developing applications such as indoor air quality monitoring systems, breathalyzers, or early fire detection systems.

Step 1: MQ2 Gas Sensor

The MQ2 gas sensor is a widely used component in the MQ sensor series. It is classified as a MOS (Metal Oxide Semiconductor) sensor. This type of sensor, also known as a chemiresistor, detects gases by measuring the change in resistance of the sensing material when exposed to them.

Operating on a 5V DC power supply, the MQ2 gas sensor consumes approximately 800mW. It is capable of detecting concentrations of LPG, smoke, alcohol, propane, hydrogen, methane, and carbon monoxide within the range of 200 to 10000 ppm.

It’s important to note that while the MQ2 gas sensor can detect multiple gases, it is unable to identify them individually. This is a common characteristic of most gas sensors. Therefore, its primary use is to measure changes in the density of a known gas rather than providing specific gas identification.

Step 2: Internal Structure of MQ2 Gas Sensor

The MQ2 gas sensor utilizes a heater-driven design. To ensure safety when detecting flammable gases, it is equipped with two layers of fine stainless steel mesh known as an “anti-explosion network.” This protective mesh prevents the heater element inside the sensor from causing explosions.

In addition to safety, the mesh also acts as a filter, allowing only gaseous elements to pass through the sensor chamber while blocking suspended particles. The mesh is securely fastened to the sensor body using a copper-plated clamping ring.

When the outer mesh is removed, the sensor’s internal structure is revealed. It consists of a star-shaped sensing element and six connecting legs extending from a Bakelite base. Two of the leads (H) are responsible for heating the sensing element and are connected by a Nickel-Chromium coil, which is a well-known conductive alloy.

The remaining four leads (A and B) are signal-carrying leads connected to the sensing element with platinum wires. These wires are linked to the body of the sensing element and detect slight variations in the current flowing through the sensing element.

The tubular sensing element is made of Aluminum Oxide (Al2O3) based ceramic and is coated with Tin Dioxide (SnO2). The Tin Dioxide coating is the crucial material as it is highly sensitive to combustible gases. The ceramic substrate enhances heating efficiency and ensures that the sensor area is consistently heated to its operating temperature.

In summary, the MQ2 gas sensor’s internal structure consists of a Heating System comprising a Nickel-Chromium coil and an Aluminum Oxide-based ceramic, and a Sensing System consisting of Platinum wires and a Tin Dioxide coating.

Step 3: How Gas Sensors Work

Gas sensors, such as those utilizing SnO2 semiconductor layers, operate based on a specific principle. When the SnO2 layer is heated to a high temperature, oxygen molecules are adsorbed on its surface. In clean air, the conduction band of tin dioxide releases electrons that are attracted to the adsorbed oxygen molecules. This interaction forms an electron depletion layer just below the surface of the SnO2 particles, creating a potential barrier. Consequently, the SnO2 film exhibits high resistance, blocking the flow of electric current.

However, when the surrounding environment contains reducing gases, the presence of these gases leads to a decrease in the density of adsorbed oxygen. This reduction occurs due to reactions between the oxygen and the reducing gases. As a result, the potential barrier is lowered, and electrons are released into the tin dioxide material. This allows the current to flow freely through the gas sensor, indicating the presence of reducing gases.

Step 4: MQ2 Gas Sensor Module Hardware Overview

The MQ2 gas sensor module is designed for simplicity and offers two different outputs. It provides both a binary indication of the presence of combustible gases and an analog representation of their concentration in the air.

The module’s analog output voltage, accessible at the A0 pin, varies proportionally with the concentration of smoke or gas. As the concentration increases, the output voltage increases, and as the concentration decreases, the output voltage decreases. The animation below illustrates the relationship between gas concentration and output voltage.

To digitize this analog signal, the module utilizes an LM393 High Precision Comparator, which makes the digital output (D0) available.

The module also features a potentiometer for adjusting the sensitivity of the digital output (D0). This allows you to set a threshold value. When the gas concentration exceeds the threshold, the module outputs LOW; otherwise, it outputs HIGH.

Furthermore, the module incorporates two LEDs. The Power LED illuminates when the module is powered on, while the Status LED lights up when the gas concentration surpasses the threshold value.

Step 5: Experiment 1 – Measuring Gas Concentration Using Analog Output (A0)

For our initial experiment, we will utilize the analog output to measure the gas concentration and determine if it falls within acceptable limits.

Wiring

Let’s proceed with connecting the MQ2 gas sensor to the Arduino.

First, link the VCC pin of the sensor to the Arduino’s 5V pin, and then connect the GND pin to the Arduino’s Ground pin. Lastly, establish a connection between the A0 output pin of the module and Analog pin #0 on the Arduino.

Please refer to the following diagram for the wiring setup.

Determining the Threshold Value

Determining the Threshold Value

To assess if the gas concentration is within the acceptable range, you will need to record the sensor’s output values when exposed to different levels of smoke or gas.

Simply execute the provided sketch and make note of the readings.

#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
}

Upon running the sketch, you should observe readings similar to the examples below:

  • In the absence of smoke/gas (around 100)
  • In the presence of smoke/gas (around 400)

This test may require some experimentation and adjustment. Once you have obtained the readings, you can utilize them as a threshold to trigger specific actions.

Arduino Code

The sketch below determines whether the gas concentration is within acceptable limits.

/* 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(" | Smoke detected!");
}

Serial.println("");
delay(2000); // wait 2s for next reading
}

Step 6: See Full Article Here