Gas Detector

by 801010 in Circuits > Arduino

10 Views, 0 Favorites, 0 Comments

Gas Detector

IMG_0134.PNG

This project shows you how to build a gas and smoke detector using an MQ‑2 sensor and an Arduino. The MQ‑2 can identify smoke, LPG, methane, and other gases, making it a useful tool for safety and electronics learning. Follow the steps to wire the components, upload the code, and test your own working detector.

Supplies

This project shows you how to build a gas and smoke detector using an MQ‑2 sensor and an Arduino. The MQ‑2 can identify smoke, LPG, methane, and other gases, making it a useful tool for safety and electronics learning. Follow the steps to wire the components, upload the code, and test your own working detector.

Get the Proper Supplies

  1. Arduino Uno:
  2. The main microcontroller board that reads the sensor and runs your code.
  3. MQ-2 gas sensor module:
  4. A module with pins typically labeled VCC, GND, DO, AO. It outputs both analog and digital signals.
  5. Jumper wires:
  6. To connect the sensor to the Arduino.
  7. (Optional) LED + resistor (220 Ω):
  8. To visually indicate gas detection.
  9. (Optional) Buzzer:
  10. For an audible alarm when gas is detected.



Understand the MQ-2 Pins


  1. VCC: Power input (5 V)
  2. GND: Ground
  3. AO (Analog Out): Gives a variable voltage proportional to gas concentration
  4. DO (Digital Out): Goes HIGH/LOW based on a threshold set by the onboard potentiometer

For this tutorial, we’ll mainly use AO with Arduino’s analog input

Wire the Citcut

Connect everything on a breadboard or directly with jumper wires.

MQ-2 → Arduino:

  1. VCC → 5V on Arduino
  2. GND → GND on Arduino
  3. AO → A0 on Arduino (analog input)

Optional LED (alert indicator):

  1. LED anode (+) → digital pin 8 through a 220 Ω resistor
  2. LED cathode (−) → GND

Optional buzzer:

  1. Buzzer + → digital pin 9
  2. Buzzer − → GND


Write the Code

int Input = A0;

int Buzzer = A1;

int GreenLED = A2;

int RedLED = A3;


int value;

int MAX = 600;


void setup() {

Serial.begin(9600);


pinMode(Input, INPUT);

pinMode(Buzzer, OUTPUT);

pinMode(GreenLED, OUTPUT);

pinMode(RedLED, OUTPUT);

}


void loop() {

value = analogRead(Input);

Serial.println(value);


if (value >= MAX) {

digitalWrite(GreenLED, LOW);

digitalWrite(RedLED, HIGH);

digitalWrite(Buzzer, HIGH);

delay(500);

} else {

digitalWrite(RedLED, LOW);

digitalWrite(Buzzer, LOW);

digitalWrite(GreenLED, HIGH);

}

}


Schematic

Capture.PNG