Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino-Based Gas Detection System with Servo, Siren, and Fan

View and Edit Project In Cirkit DesignerImage of Arduino-Based Gas Detection System with Servo, Siren, and Fan

Circuit Documentation

Summary

This circuit is designed to detect gas using an MQ2 gas sensor and respond by activating a siren, a fan, and a servo motor. The circuit is controlled by an Arduino UNO microcontroller. When gas is detected, the servo motor moves to 90 degrees, and both the siren and the fan are turned on. If no gas is detected, the servo motor returns to 0 degrees, and both the siren and the fan are turned off.

Component List

  1. MQ2 Gas Sensor

    • Pins: VCC, GND, AOUT, DOUT
    • Description: Detects the presence of gas in the environment.
    • Purpose in Circuit: Provides a digital output signal when gas is detected.
  2. Arduino UNO

    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
    • Description: Microcontroller board based on the ATmega328P.
    • Purpose in Circuit: Controls the entire circuit, reads the gas sensor, and drives the servo, siren, and fan.
  3. Micro Servo 9G

    • Pins: GND, +5V, PWM
    • Description: Small servo motor.
    • Purpose in Circuit: Moves to indicate gas detection.
  4. Siren

    • Pins: Positive, Ground
    • Description: Emits a loud sound when activated.
    • Purpose in Circuit: Alerts when gas is detected.
  5. Fan

    • Pins: GND, 5V
    • Description: Small fan.
    • Purpose in Circuit: Activates to ventilate the area when gas is detected.

Wiring Details

MQ2 Gas Sensor

Arduino UNO

Micro Servo 9G

Siren

Fan

Code Documentation

#include <Servo.h>

// Pin definitions
const int gasSensorPin = 8; // Digital pin connected to MQ2 DOUT
const int servoPin = 11;    // PWM pin connected to servo motor
const int sirenPin = 13;    // Digital pin connected to siren
const int fanPin = 13;      // Digital pin connected to fan (same as siren)

Servo myServo; // Create a servo object

void setup() {
  // Initialize the gas sensor pin as an input
  pinMode(gasSensorPin, INPUT);
  // Initialize the siren and fan pins as outputs
  pinMode(sirenPin, OUTPUT);
  pinMode(fanPin, OUTPUT);
  // Attach the servo object to the servo pin
  myServo.attach(servoPin);
  // Initialize the servo to 0 degrees
  myServo.write(0);
  // Ensure siren and fan are off initially
  digitalWrite(sirenPin, LOW);
  digitalWrite(fanPin, LOW);
}

void loop() {
  // Read the gas sensor value
  int gasSensorValue = digitalRead(gasSensorPin);
  // If gas is detected, move the servo to 90 degrees and turn on siren and fan
  if (gasSensorValue == HIGH) {
    myServo.write(90);
    digitalWrite(sirenPin, HIGH);
    digitalWrite(fanPin, HIGH);
  } else {
    // Otherwise, move the servo back to 0 degrees and turn off siren and fan
    myServo.write(0);
    digitalWrite(sirenPin, LOW);
    digitalWrite(fanPin, LOW);
  }
  // Small delay to avoid rapid switching
  delay(100);
}

This code initializes the gas sensor, servo motor, siren, and fan. In the loop function, it continuously checks the gas sensor's digital output. If gas is detected, the servo motor moves to 90 degrees, and both the siren and the fan are turned on. If no gas is detected, the servo motor returns to 0 degrees, and both the siren and the fan are turned off.