Interfacing MQ-2 Smoke LPG Butane Hydrogen Gas Sensor Detector Module with Arduino

MQ-2 Gas Sensor Module
The MQ-2 Gas Sensor detects the presence of gases like LPG, butane, methane, alcohol, hydrogen, and smoke in the air. It is commonly used in safety systems, gas leak detectors, and air quality monitoring.
Working Principle of MQ-2 Gas Sensor
The MQ-2 sensor uses a chemical sensing element made of SnO2 (tin dioxide) which has lower conductivity in clean air. When target gases are present, the sensor’s conductivity increases, allowing Arduino to detect gas concentrations through analog output.
Types of Gas Sensors
MQ-2
- Heats up the sensing element.
- Gas molecules interact with SnO2, changing resistance.
- Outputs analog signal relative to gas concentration.
MQ-3
- Similar working principle using SnO2 sensing layer.
- Outputs analog signal depending on alcohol levels.
- Useful in automotive and personal safety devices.
Requirements
1. Arduino
2. MQ-2 Gas Sensor Module
3. Jumper wires
4. Breadboard
Pin Configuration of MQ-2 Gas Sensor
MQ-2 Module
- VCC: Connect to +5V on Arduino.
- GND: Connect to GND on Arduino.
- DO: Digital Output - HIGH when gas concentration exceeds threshold.
- AO: Analog Output - proportional to gas concentration.
Wiring the MQ-2 Gas Sensor to Arduino
Connect the MQ-2 sensor's VCC and GND to the Arduino's +5V and GND. Connect the AO pin to an analog input on Arduino (e.g., A0). You can also use the DO pin for threshold-based digital detection.
Algorithm
Initialize Components
- Connect VCC to 5V and GND to GND on Arduino.
- Connect AO pin to A0 analog pin.
Write the Code
- Set the A0 pin as INPUT in setup().
- Read analog values from A0 in the loop().
- Print gas levels to the serial monitor.
Display Values or Control Devices
- Show gas concentration on serial monitor or LCD.
- Activate buzzer or LED if levels exceed threshold.
Test the Project
- Upload code to Arduino.
- Expose the sensor to smoke or gas and observe values.
Arduino Code
1// Pin Definitions
2const int analogPin = A0; // Analog output from MQ-2
3const int digitalPin = 2; // Digital output from MQ-2 (optional)
4int gasLevel = 0; // To store analog gas value
5
6void setup() {
7 Serial.begin(9600); // Start serial communication
8 pinMode(digitalPin, INPUT); // Set digital pin as input
9 Serial.println("MQ-2 Gas Sensor Initialized");
10}
11
12void loop() {
13 gasLevel = analogRead(analogPin); // Read analog gas level
14 int thresholdReached = digitalRead(digitalPin); // Optional digital output
15
16 Serial.print("Analog Gas Value: ");
17 Serial.println(gasLevel); // Print analog value
18
19 if (thresholdReached == LOW) {
20 Serial.println(" Dangerous Gas Level Detected!");
21 } else {
22 Serial.println(" Air is Safe.");
23 }
24
25 delay(1000); // Wait 1 second
26}
27
Applications of MQ-2 Gas Sensor
- Home safety systems
- Gas leak detectors
- Industrial safety devices
- Air quality monitors
- Fire detection systems
- Automotive safety systems
Conclusion
Interfacing the MQ-2 Gas Sensor with Arduino enables you to detect dangerous gas leaks and smoke for safety and monitoring applications. With a simple setup and real-time feedback, it’s an essential tool for safety-conscious projects.