MQ-2 Gas Sensor for H2, LPG, CH4, CO, Smoke or Propane Detector
MQ-2 Gas Sensor for H2, LPG, CH4, CO, Smoke or Propane Detector
The MQ-2 gas sensor is a highly sensitive and reliable device designed to detect the presence of various combustible gases, including H2, LPG, CH4, CO, smoke, and propane. This sensor is widely used in various applications, such as industrial automation, home security systems, and air quality monitoring devices.
The MQ-2 gas sensor detects the concentration of target gases in the surrounding air and outputs an analog signal corresponding to the gas concentration. The sensor uses a sensitive material that changes its resistance when exposed to the target gases, which is then converted into an electrical signal.
| The MQ-2 gas sensor is suitable for a wide range of applications, including |
5V
150mA
100 ppm to 10,000 ppm (depending on the gas type)
10-30 seconds
Analog signal (0-5V)
High sensitivity to target gases
-20C to 50C
5-90% RH
20mm x 15mm x 10mm
10g
The technical specifications may vary depending on the specific vendor and version of the MQ-2 gas sensor. Always refer to the datasheet provided by the manufacturer for specific details.
MQ-2 Gas Sensor Module DocumentationOverviewThe MQ-2 Gas Sensor is a widely used module for detecting various types of gases, including H2, LPG, CH4, CO, smoke, and propane. This module is sensitive to a wide range of gases and is often used in applications such as gas leakage detection, industrial automation, and home safety systems.Pinout and WiringThe MQ-2 Gas Sensor module has a total of 5 pins:VCC: Power supply pin (typically 5V)
GND: Ground pin
DOUT: Digital output pin
AOUT: Analog output pin
Heating Pin: Used to heat the sensor element (typically connected to a digital pin)Operating PrincipleThe MQ-2 Gas Sensor works on the principle of catalytic combustion, where the gas molecules react with the sensor material to produce a varying resistance. The sensor element is heated to increase its sensitivity and accuracy.Code Examples### Example 1: Basic Gas Detection using Digital OutputIn this example, we will connect the MQ-2 Gas Sensor to an Arduino board and use the digital output to detect the presence of gas.```c
const int gasSensorPin = 2; // Connect DOUT to digital pin 2void setup() {
pinMode(gasSensorPin, INPUT);
Serial.begin(9600);
}void loop() {
int gasValue = digitalRead(gasSensorPin);
if (gasValue == HIGH) {
Serial.println("Gas detected!");
} else {
Serial.println("No gas detected.");
}
delay(1000);
}
```### Example 2: Gas Concentration Measurement using Analog OutputIn this example, we will connect the MQ-2 Gas Sensor to an ESP32 board and use the analog output to measure the concentration of gas.```c
const int gasSensorPin = 32; // Connect AOUT to analog pin 32void setup() {
Serial.begin(9600);
}void loop() {
int gasValue = analogRead(gasSensorPin);
float voltage = gasValue (5.0 / 4095.0);
float Rs = 10000 (5.0 / voltage - 1);
float ratio = Rs / 2200.0;
Serial.print("Gas concentration: ");
Serial.print(ratio);
Serial.println(" ppm");
delay(1000);
}
```### Example 3: Gas Detection with Heating Element Control (Advanced)In this example, we will connect the MQ-2 Gas Sensor to a Raspberry Pi board and use the heating pin to control the sensor element temperature.```python
import RPi.GPIO as GPIO
import timeGPIO.setmode(GPIO.BCM)
gasSensorPin = 17
heatingPin = 23GPIO.setup(gasSensorPin, GPIO.IN)
GPIO.setup(heatingPin, GPIO.OUT)while True:
GPIO.output(heatingPin, GPIO.HIGH) # Heat the sensor element
time.sleep(1)
gasValue = GPIO.input(gasSensorPin)
if gasValue == GPIO.HIGH:
print("Gas detected!")
else:
print("No gas detected.")
GPIO.output(heatingPin, GPIO.LOW) # Turn off the heating element
time.sleep(1)
```Note: The above code examples are for illustration purposes only and may require modifications to suit your specific application. Additionally, it is recommended to use the MQ-2 Gas Sensor in a well-ventilated area and follow proper safety precautions when working with gas detection applications.