Interfacing Winsen MQ-5 LPG Detection Sensor Module with Arduino
Winsen MQ-5 LPG Detection Sensor Module
The Winsen MQ-5 is a versatile gas sensor capable of detecting LPG, natural gas, and coal gas in the air. It's commonly used in safety systems, smart home devices, and industrial applications to monitor gas leakage.
Working Principle of MQ-5 LPG Sensor
The MQ-5 sensor uses a sensitive material (SnO2) whose conductivity changes in the presence of combustible gases. When the gas concentration increases, the sensor’s resistance decreases, which can be measured by the Arduino to determine gas levels.
Types of Gas Sensors
MQ-5 Gas Sensor
- Heats the sensor element to activate its sensitivity.
- Gas presence alters the sensor's resistance.
- Outputs an analog signal corresponding to gas concentration.
MQ-2 Gas Sensor
- Heats internal sensing material.
- Detects variations in gas levels via resistance changes.
- Outputs analog signal to the microcontroller.
Requirements
1. Arduino
2. MQ-5 LPG Detection Sensor Module
3. 10K ohm resistor (optional, for analog signal conditioning)
4. Jumper wires
Pin Configuration of MQ-5 Sensor
MQ-5 LPG Sensor Module
- VCC: Connect to +5V on Arduino.
- GND: Connect to GND on Arduino.
- DO: Digital output signal (HIGH/LOW based on threshold).
- AO: Analog output signal representing gas concentration.
Wiring the MQ-5 Gas Sensor to Arduino
To wire the MQ-5 to the Arduino, connect VCC and GND to +5V and GND respectively. Use the AO pin to read analog gas concentration values and the DO pin for digital threshold alerts.
Algorithm
Initialize Components
- Connect VCC and GND of the MQ-5 sensor to +5V and GND on Arduino.
- Connect AO to an analog pin and DO to a digital input pin if threshold detection is required.
Write the Code
- Set the sensor pins in the setup() function.
- Read analog values from AO in the loop() function.
- Optionally use DO for gas level threshold alerts.
Display Values or Control Devices
- Print the gas concentration readings to the serial monitor.
- Trigger an alert or activate devices if gas levels exceed safety limits.
Test the Project
- Upload the code to Arduino.
- Expose the sensor to gas sources like LPG and monitor the response.
Arduino Code
1// Arduino Code to Interface Winsen MQ-5 LPG Gas Sensor Module
2
3const int analogPin = A0; // AOUT connected to A0 for analog gas concentration
4const int digitalPin = 2; // DOUT connected to D2 for digital threshold detection
5const int ledPin = 13; // Onboard LED to indicate gas detection
6
7void setup() {
8 Serial.begin(9600); // Initialize Serial Monitor
9 pinMode(digitalPin, INPUT); // Set DOUT pin as input
10 pinMode(ledPin, OUTPUT); // Set LED pin as output
11 Serial.println("MQ-5 LPG Gas Sensor Initialized...");
12}
13
14void loop() {
15 // Read analog value for LPG concentration
16 int analogValue = analogRead(analogPin); // Range: 0 to 1023
17 float voltage = analogValue * (5.0 / 1023.0); // Convert to voltage
18
19 // Print sensor readings to Serial Monitor
20 Serial.print("Analog Value: ");
21 Serial.print(analogValue);
22 Serial.print(" | Voltage: ");
23 Serial.print(voltage);
24 Serial.println(" V");
25
26 // Read digital pin to detect if gas level crossed threshold
27 int gasDetected = digitalRead(digitalPin); // LOW means gas is detected
28
29 if (gasDetected == LOW) {
30 // Gas concentration is above preset threshold
31 digitalWrite(ledPin, HIGH); // Turn on LED
32 Serial.println("⚠️ Gas Detected: LPG / Methane / Natural Gas");
33 } else {
34 digitalWrite(ledPin, LOW); // No significant gas detected
35 }
36
37 delay(1000); // Delay for next reading
38}
39
Applications of MQ-5 Gas Sensors
- Home gas leakage detection systems
- Industrial safety monitoring
- Smart kitchen and HVAC systems
- Gas leak alarms
- Air quality monitoring
- Smart agriculture ventilation control
Conclusion
Interfacing the MQ-5 LPG Gas Sensor Module with Arduino enables you to build reliable gas detection systems for safety and automation. With easy wiring and simple code, it’s ideal for creating smart and responsive environments.