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

Arduino UNO Controlled Smoke Detection and Motor Activation System

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled Smoke Detection and Motor Activation System

Circuit Documentation

Summary

This circuit is designed to monitor the environment for smoke using an MQ-2 gas sensor and activate a DC motor using an L298N motor driver when smoke is detected. The Arduino UNO serves as the central control unit, reading the sensor data and controlling the motor based on the detected smoke levels. A 9V battery provides power to the motor driver, which in turn drives a hobby gearmotor.

Component List

Arduino UNO

L298N DC Motor Driver

Hobby Gearmotor with 48:1 Gearbox

MQ-2 Gas Sensor

9V Battery

Wiring Details

Arduino UNO

L298N DC Motor Driver

Hobby Gearmotor with 48:1 Gearbox

MQ-2 Gas Sensor

9V Battery

Documented Code

// Define pins
const int mq2Pin = A0;      // Analog pin for MQ2 sensor
const int motorPin1 = 9;    // Motor control pin 1
const int motorPin2 = 10;   // Motor control pin 2
const int enablePin = 11;   // PWM-enabled pin for speed control

// Set threshold for smoke detection
int smokeThreshold = 100;  // Adjust based on sensor calibration

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Set motor pins as output
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(enablePin, OUTPUT);
}

void loop() {
  // Read MQ2 sensor value
  int mq2Value = analogRead(mq2Pin);

  // Print MQ2 sensor value for debugging
  Serial.print("Smoke level: ");
  Serial.println(mq2Value);

  // Check if smoke level exceeds threshold
  if (mq2Value > smokeThreshold) {
    Serial.println("Smoke detected! Activating motor...");

    // Turn on the motor
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
    analogWrite(enablePin, 300);  // Control speed (0-255)

    delay(1000);  // Run motor for 2 seconds
  } else {
    // Stop the motor
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
  }

  // Small delay before next reading
  delay(700);
}

This code is designed to be uploaded to the Arduino UNO. It initializes the motor control pins and the MQ-2 sensor pin. In the main loop, it reads the analog value from the MQ-2 sensor and compares it to a predefined threshold. If the smoke level is above the threshold, it activates the motor for a short period. The motor speed is controlled by a PWM signal on the enable pin.