Description
The MQ-2 sensor is a very popular gas sensor for use with Arduino and other microcontroller boards, and is ideal for home gas or smoke detection projects, such as gas leak alarms.
MQ-2 is
The MQ-2 is a gas sensor that can detect many types of gases such as:
-
LPG (cooking gas)
-
Butane gas
-
Propane gas
-
Methane gas (CH₄)
-
Hydrogen gas (H₂)
-
Smoke
-
alcohol
Inside the sensor is a heating coil and a SnO₂ (tin dioxide) gas detector, whose resistance changes in the presence of gas in the air, allowing it to be converted to an electrical signal.
MQ-2 specifications
list
|
details
|
Supply voltage
|
5V DC
|
Electrical power
|
About 800mW
|
Signal type
|
Analog and digital (depending on module)
|
Warm-up time
|
About 20 seconds to 2 minutes
|
Detectable gases
|
LPG, Methane, Alcohol, Propane, Hydrogen, Smoke
|
Detection range
|
Approximately 300 - 10,000 ppm
|
Number of legs
|
4 legs (VCC, GND, AOUT, DOUT)
|
AOUT (Analog Out) – Analog signal indicating gas level. DOUT (Digital Out) – Digital signal (1 or 0) when gas level exceeds set point.
Using MQ-2 with Arduino
Wiring:
MQ-2 Pin
|
Arduino Pin
|
VCC
|
5V
|
GND
|
GND
|
AOUT
|
A0 (Analog)
|
DOUT
|
D2 (Digital) (if used)
|
Some MQ-2 modules have a potentiometer (adjuster) to set the threshold level on DOUT.
Example code for use in Analog:
int mq2Pin = A0;
void setup() { Serial.begin(9600); }
void loop() { int gasLevel = analogRead(mq2Pin); Serial.print("gasLevel: "); Serial.println(gasLevel); delay(1000); }
Example of code for Digital usage:
int mq2Digital = 2;
void setup() { pinMode(mq2Digital, INPUT); Serial.begin(9600); }
void loop() { int gasDetected = digitalRead(mq2Digital);
if (gasDetected == LOW) { Serial.println("gas detect!"); } else { Serial.println("Safe"); }
delay(1000); }
