Table of Contents

Play Video

GAS DETECTION – VENTILATION AND ALARM

Gas Detection – Alarm and Ventilation is a project consisting of Gas sensor which detects the gas and automatically switch the fan on and opens the door the allow the gas to flow out of the area.

The “Gas Detection – Alarm and Ventilation” project uses an Arduino and an MQ2 gas sensor to detect harmful gases around us. When gas is detected, a servo motor opens a door automatically, and a fan turns on to push the air out of the room. This project is a great and enjoyable way to learn about electronics and how sensors can be used in different applications.

Components used in this project are:

  1. Arduino UNO with cable
  2. Servo Motor SG-90
  3. MQ2 gas sensor
  4. 12 V DC fan
  5. Red LED
  6. Male to Male Jumper Wires x 15
  7. Male to Female Jumper Wires x 3
  8. Resistors  (10k ohm and 220 ohm)
  9. N-Channel MOSFET 60V 30A

Featured Image:

Connection Pins with Arduino:

  • Servo (Red -> 5V, Black ->GND , Orange -> 2)
  • MQ2 (VCC -> 5V, GND ->GND, A0 -> A3)
  • DC fan (Red -> Vin, Black -> Mosfet pin2)
  • Mosfet (1st pin -> 10k resistor, 2nd pin -> DC fan black wire, 3rd pin -> GND)
  • LED ( Anode -> 6, Cathode -> GND)

Circuit Diagram:

Code:

#include <Servo.h>
Servo myservo;
int pos = 0;

#define ledR 6
#define fan 5
#define sensor A3
#define servoPin 2

void setup() {
  Serial.begin(9600);
  myservo.attach(servoPin);
  pinMode(fan, OUTPUT);
  pinMode(ledR, OUTPUT);
  digitalWrite(sensor, LOW);
  myservo.write(0); // initially setting the servo posstion to 0, you can set according to your requirement.
}

void loop() {
  int value = analogRead(sensor);

  if (value > 380) {    //380 is the threshold, change according to your sensor
    digitalWrite(ledR, HIGH);
    digitalWrite(fan, HIGH);
    myservo.write(90);
    Serial.println(value);
    delay(500);

  }
  else {
    digitalWrite(fan, LOW);
    digitalWrite(ledR, LOW);
    myservo.write(0);
    Serial.println(value);
    delay(500);
  }
}
Scroll to Top