Interfacing MQ-5 Gas Sensor Module with Arduino
MQ-5 Methane LPG Liquid Propane Gas Sensor Module
The MQ-5 Gas Sensor Module is designed to detect gases like LPG, methane, and propane. It’s widely used in gas leakage detection systems, safety alarms, and smart home environments for monitoring air quality.
Working Principle of MQ-5 Gas Sensor
The MQ-5 sensor detects gas concentration by measuring the change in resistance of its internal sensing element. When exposed to combustible gases, the sensor's resistance changes, which is then processed and interpreted as a gas level by the Arduino.
Types of Gas Sensors
MQ-5 Gas Sensor
- Gas enters the sensor housing.
- The internal sensing material reacts and changes its resistance based on gas concentration.
- The analog output reflects the gas concentration level.
MQ-2 Gas Sensor
- Gas exposure alters the sensor’s internal resistance.
- Output voltage changes accordingly.
- Arduino reads this voltage to determine gas presence.
Requirements
1. Arduino
2. MQ-5 Gas Sensor Module
3. 100 ohm resistor (optional for testing)
4. Jumper wires
Pin Configuration of MQ-5 Gas Sensor Module
MQ-5 Sensor Module
- VCC: Connect to +5V on Arduino.
- GND: Connect to GND on Arduino.
- AO: Analog output representing gas concentration.
- DO: Digital output set by onboard potentiometer threshold.
Wiring the MQ-5 Gas Sensor to Arduino
To connect the MQ-5 sensor to Arduino, connect VCC to +5V, GND to GND, AO to an analog input pin, and DO (optional) to a digital input if you want threshold-based alerts. The analog signal helps in measuring exact gas concentration levels.
Algorithm
Initialize Components
- Connect the VCC and GND pins of the MQ-5 Sensor to +5V and GND on the Arduino.
- Connect the AO to an analog input pin for reading gas levels.
Write the Code
- Set the analog pin as INPUT in the setup() function.
- Read the analog value continuously in the loop() function.
- Use this value to determine the concentration of gas in the air.
Display Values or Trigger Alerts
- Print the gas level to the serial monitor.
- Use thresholds to trigger buzzers, LEDs, or alarms when gas levels rise.
Test the Project
- Upload the code to the Arduino.
- Expose the sensor to controlled amounts of gas (safely) and observe the output.
Arduino Code
1// Arduino Code to Interface MQ-5 Gas Sensor (LPG, Methane, Propane)
2
3const int analogPin = A0; // Analog output pin of MQ-5 connected to Arduino A0
4const int digitalPin = 2; // Digital output pin (optional) connected to D2
5const int ledPin = 13; // Built-in LED to indicate gas presence via digital output
6
7void setup() {
8 Serial.begin(9600); // Start serial communication at 9600 bps
9 pinMode(digitalPin, INPUT); // Set digital pin as input (optional)
10 pinMode(ledPin, OUTPUT); // Set LED pin as output
11 Serial.println("MQ-5 Gas Sensor Initialized...");
12}
13
14void loop() {
15 // Read analog output (returns value between 0 and 1023)
16 int analogValue = analogRead(analogPin);
17
18 // Convert analog value to voltage (0 to 5V)
19 float voltage = analogValue * (5.0 / 1023.0);
20
21 // Print analog and voltage reading to Serial Monitor
22 Serial.print("Analog Value: ");
23 Serial.print(analogValue);
24 Serial.print(" | Voltage: ");
25 Serial.print(voltage);
26 Serial.println(" V");
27
28 // Optionally read the digital output from DOUT pin
29 int gasDetected = digitalRead(digitalPin);
30
31 if (gasDetected == LOW) {
32 // Gas is detected (DOUT goes LOW when threshold exceeded)
33 digitalWrite(ledPin, HIGH); // Turn ON LED
34 Serial.println(" Gas Detected!");
35 } else {
36 digitalWrite(ledPin, LOW); // Turn OFF LED
37 }
38
39 delay(1000); // Wait 1 second before next reading
40}
41
Applications of MQ-5 Gas Sensor Modules
- Gas leakage detection systems
- Smart kitchen alarms
- Industrial safety monitoring
- Home automation safety units
- IoT-based air quality systems
- Fire prevention and detection modules
Conclusion
Integrating the MQ-5 Gas Sensor Module with Arduino offers a reliable way to monitor LPG, methane, and propane gases. Whether for home safety, industrial monitoring, or IoT solutions, this setup provides essential functionality with simple wiring and coding.