Logo

Interfacing MQ-6 Gas Sensor with Arduino

MQ-6 LPG Gas Sensor

The MQ-6 Gas Sensor is designed to detect Liquefied Petroleum Gases (LPG) like propane, isobutane, and butane. It is commonly used in gas leak detection systems, safety devices, and automation projects requiring gas concentration monitoring.

Working Principle of MQ-6 Gas Sensor

The MQ-6 Sensor operates by using a sensitive material (tin dioxide) whose conductivity changes in the presence of LPG gases. As gas concentration increases, the sensor's resistance changes, which is then converted to an analog signal readable by the Arduino.

Types of Gas Sensors

MQ-6 LPG Sensor

  • Heats the sensing element to react with gas molecules.
  • Changes resistance based on gas concentration.
  • Outputs an analog voltage signal proportional to gas level.

MQ-135 Air Quality Sensor

  • Monitors air composition for multiple gases.
  • Sensing resistance changes with gas presence.
  • Provides analog voltage for microcontroller processing.

Requirements

1. Arduino

2. MQ-6 Gas Sensor

3. 100 ohm resistor

4. Jumper wires

Pin Configuration of MQ-6 Gas Sensor

MQ-6 Sensor Module

  • VCC: Connect to +5V on Arduino.
  • GND: Connect to GND on Arduino.
  • DO: Digital output pin that goes HIGH when gas is detected above threshold.
  • AO: Analog output pin providing variable voltage based on gas concentration.

Wiring the MQ-6 Gas Sensor to Arduino

To connect the MQ-6 Sensor to Arduino, link the VCC and GND pins to 5V and GND respectively. Use the AO pin for analog readings of gas concentration or DO pin for digital threshold detection. You can calibrate sensitivity using the onboard potentiometer.

Algorithm

  1. Initialize Components

    • Connect VCC and GND of the MQ-6 Sensor to 5V and GND on Arduino.
    • Connect AO pin to an analog input on Arduino (e.g., A0).
  2. Write the Code

    • Set sensor pin as INPUT in the setup() function.
    • Read analog values from AO pin in the loop() function.
    • Map and display the sensor readings to understand gas levels.
  3. Display Values or Trigger Actions

    • Print gas concentration values to the serial monitor.
    • Use conditional statements to trigger alarms or LEDs when dangerous levels are detected.
  4. Test the Project

    • Upload the code to Arduino.
    • Expose the sensor to LPG or propane and observe sensor behavior and output values.

Arduino Code

1// Arduino Code to Interface MQ-6 Gas Sensor (Detects LPG, Butane, Propane)
2
3const int analogPin = A0;     // Connect AOUT from MQ-6 to A0 of Arduino
4const int digitalPin = 2;     // Connect DOUT from MQ-6 to D2 (optional)
5const int ledPin = 13;        // Onboard LED to indicate gas detection via digital output
6
7void setup() {
8  Serial.begin(9600);              // Start serial communication to monitor sensor values
9  pinMode(digitalPin, INPUT);      // Set digital pin as input to receive HIGH/LOW signal
10  pinMode(ledPin, OUTPUT);         // Set built-in LED as output
11  Serial.println("MQ-6 LPG Gas Sensor Initialized...");
12}
13
14void loop() {
15  // Read analog gas concentration
16  int analogValue = analogRead(analogPin);    // Range: 0–1023
17  float voltage = analogValue * (5.0 / 1023.0);  // Convert analog to voltage
18
19  // Display sensor readings on 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  // Optional: Read the digital output (DOUT) to trigger alert
27  int gasDetected = digitalRead(digitalPin);
28
29  if (gasDetected == LOW) {
30    // Gas detected (DOUT goes LOW if gas exceeds preset threshold)
31    digitalWrite(ledPin, HIGH);    // Turn ON LED as warning
32    Serial.println(" LPG or Gas Detected!");
33  } else {
34    digitalWrite(ledPin, LOW);     // Turn OFF LED
35  }
36
37  delay(1000); // Wait 1 second before next reading
38}
39

Applications of MQ-6 Gas Sensors

  • LPG leakage detection
  • Gas leak alarms
  • Home and industrial safety systems
  • Smart kitchen appliances
  • Automated ventilation control
  • Robotic environmental sensing

Conclusion

Interfacing the MQ-6 Gas Sensor with Arduino is a practical way to implement gas leak detection in various applications. Its high sensitivity to propane, isobutane, and LPG makes it ideal for safety and automation systems.