Interfacing MQ-9 Gas Sensor Module with Arduino

MQ-9 Gas Sensor Module

The MQ-9 Gas Sensor is designed to detect Carbon Monoxide (CO), Methane (CH4), and Liquefied Petroleum Gas (LPG). It is commonly used in safety systems, gas leak detection, and environmental monitoring where reliable detection of combustible gases is crucial.

Working Principle of MQ-9 Gas Sensor

The MQ-9 sensor operates by sensing the concentration of gases through a sensitive material that changes resistance when exposed to gases like CO and CH4. The sensor outputs an analog signal proportional to the gas concentration.

Types of Gas Sensors

Semiconductor Gas Sensor

  • Heats up a sensing element.
  • Gas molecules interact with the element and change its resistance.
  • The resistance change is measured to estimate gas concentration.

Electrochemical Gas Sensor

  • Gas diffuses through a membrane.
  • Reacts electrochemically at the electrode.
  • Current generated is proportional to gas concentration.

Requirements

1. Arduino

2. MQ-9 Gas Sensor Module

3. 100 ohm resistor (optional)

4. Jumper wires

Pin Configuration of MQ-9 Gas Sensor

MQ-9 Sensor Module

  • VCC: Connect to +5V on Arduino.
  • GND: Connect to GND on Arduino.
  • DO: Digital output - goes HIGH when gas threshold is reached.
  • AO: Analog output - proportional to gas concentration.

Wiring the MQ-9 Gas Sensor to Arduino

To wire the MQ-9 Sensor to Arduino, connect VCC to 5V, GND to GND, AO to an analog input pin, and optionally DO to a digital input for threshold detection. This setup allows you to monitor gas concentration in real-time.

Algorithm

  1. Initialize Components

    • Connect the VCC and GND pins of the MQ-9 sensor to +5V and GND on the Arduino.
    • Connect AO to an analog pin (e.g., A0) and optionally DO to a digital input.
  2. Write the Code

    • Set the sensor pins as INPUT in the setup() function.
    • Read analog values from AO in the loop() function.
    • Convert readings to estimate gas concentration.
  3. Display Values or Control Devices

    • Print gas readings to the serial monitor.
    • Trigger a buzzer, LED, or relay when the gas level exceeds a threshold.
  4. Test the Project

    • Upload the code to the Arduino.
    • Expose the sensor to small amounts of gas and observe the readings.
1const int analogPin = A0;     // AOUT connected to A0 for analog gas readings
2const int digitalPin = 2;     // DOUT connected to D2 for threshold-based detection
3const int ledPin = 13;        // Onboard LED for alert indication
4
5void setup() {
6  Serial.begin(9600);              // Start serial communication for debugging
7  pinMode(digitalPin, INPUT);      // Set DOUT pin as input (for digital HIGH/LOW gas detection)
8  pinMode(ledPin, OUTPUT);         // Set LED pin as output (to indicate gas detection)
9  Serial.println("MQ-9 Gas Sensor Initialized...");
10}
11
12void loop() {
13  // Step 1: Read analog value from MQ-9
14  int analogValue = analogRead(analogPin);  // Returns a value from 0 to 1023
15  float voltage = analogValue * (5.0 / 1023.0); // Convert analog value to voltage
16
17  // Step 2: Print analog reading and voltage to Serial Monitor
18  Serial.print("Analog Value: ");
19  Serial.print(analogValue);
20  Serial.print(" | Voltage: ");
21  Serial.print(voltage);
22  Serial.println(" V");
23
24  // Step 3: Read digital output for threshold alert
25  int gasDetected = digitalRead(digitalPin);  // LOW means gas level is above threshold
26
27  // Step 4: Trigger alert if gas is detected
28  if (gasDetected == LOW) {
29    digitalWrite(ledPin, HIGH);  // Turn on LED if gas is detected
30    Serial.println(" Gas Detected (CO / Methane / LPG)");
31  } else {
32    digitalWrite(ledPin, LOW);   // Turn off LED if no gas detected
33  }
34
35  delay(1000); // Wait 1 second before next reading
36}
37

Applications of MQ-9 Gas Sensors

  • Gas leakage detection systems
  • Industrial safety monitoring
  • Smart kitchen safety devices
  • Home and office air quality monitoring
  • Smart agriculture and greenhouse gas sensing
  • Vehicle emission detection

Conclusion

Integrating the MQ-9 Gas Sensor with Arduino enables real-time gas detection for safety and monitoring applications. With straightforward wiring and simple coding, it's easy to add gas sensing capability to your smart systems.