The MQ2 is a versatile gas sensor module capable of detecting a wide range of gases, including carbon monoxide (CO), alcohol, methane (CH4), hydrogen (H2), and smoke particles. This sensor is widely used in the field of safety and air quality monitoring, making it an essential component for environmental sensors, home safety devices, and industrial leakage detection.
Pin Number | Pin Name | Description |
---|---|---|
1 | VCC | Power supply (5V DC) |
2 | GND | Ground |
3 | DOUT | Digital output (0V or 5V) |
4 | AOUT | Analog output (0.1-0.3V relative to gas concentration) |
// MQ2 Gas Sensor Example Code for Arduino UNO
int analogPin = A0; // Analog input pin connected to AOUT on the MQ2
int digitalPin = 2; // Digital input pin connected to DOUT on the MQ2
int sensorValue = 0; // Variable to store the sensor value
void setup() {
pinMode(digitalPin, INPUT); // Set the digital pin as input
Serial.begin(9600); // Start serial communication at 9600 baud rate
}
void loop() {
sensorValue = analogRead(analogPin); // Read the analog value from sensor
Serial.print("Gas concentration (analog): ");
Serial.println(sensorValue); // Print the analog reading
if (digitalRead(digitalPin) == HIGH) {
// Check if the digital output is HIGH
Serial.println("Gas detected!");
} else {
Serial.println("No gas detected.");
}
delay(1000); // Wait for 1 second before the next loop
}
Q: How long does the MQ2 sensor last? A: The lifespan of the MQ2 sensor is typically around 2-5 years, depending on usage and environmental conditions.
Q: Can the MQ2 sensor detect natural gas? A: Yes, the MQ2 sensor can detect methane (CH4), which is the primary component of natural gas.
Q: Is the MQ2 sensor sensitive to alcohol? A: Yes, the MQ2 sensor can detect alcohol vapors, making it suitable for breathalyzers and similar applications.
Q: What is the best way to test the MQ2 sensor? A: The best way to test the sensor is by using a known gas concentration and observing the sensor's response while adjusting the onboard potentiometer for calibration.