The MQ-4 is a widely used gas sensor module capable of detecting natural gas (methane) concentrations in the air. It is designed for easy interfacing with microcontrollers and is commonly used in applications such as gas leak detection systems in homes, industries, and vehicles.
Pin Number | Pin Name | Description |
---|---|---|
1 | VCC | Power supply (5V) |
2 | GND | Ground |
3 | DO | Digital output (TTL logic level) |
4 | AO | Analog output (Variable voltage) |
// MQ-4 Sensor Example Code
int analogPin = A0; // Analog input pin connected to AO
int digitalPin = 2; // Digital input pin connected to DO
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
}
void loop() {
sensorValue = analogRead(analogPin); // Read the analog value from sensor
Serial.print("Gas concentration: ");
Serial.println(sensorValue); // Print the sensor value to the serial monitor
// Check if the digital pin is HIGH (gas concentration above threshold)
if (digitalRead(digitalPin) == HIGH) {
// Gas level is above the threshold
Serial.println("Gas detected!");
} else {
// Gas level is below the threshold
Serial.println("No gas detected.");
}
delay(1000); // Wait for 1 second before reading again
}
Q: How do I adjust the sensitivity of the sensor? A: Use the onboard potentiometer to adjust the threshold level for the digital output.
Q: Can the MQ-4 sensor detect other gases? A: While the MQ-4 is optimized for methane, it may respond to other gases. However, its selectivity and sensitivity are highest for natural gas.
Q: What is the lifespan of the MQ-4 sensor? A: The lifespan can vary based on usage and environmental conditions, but typically MQ sensors can last for several years with proper maintenance and calibration.