EXPERIMENT: 7
Aim: Design and Implementation of Smoke detector using Arduino Uno.
Appartus Required:
1. Arduino Uno
2. MQ2 Gas Sensor
3. Jumper Wire
4. Buzzer
5. Potentiometer
6. Power Supply / Battery
Theory: In this circuit, the MQ2 gas sensor continuously monitors the smoke level in the
environment by sending analog values to the Arduino. The Arduino processes this data and
compares it to a predefined threshold. If the smoke level exceeds the threshold, the Arduino
activates a red LED to signal danger and triggers a buzzer for an audible alarm. If the smoke
level is below the threshold, the Arduino illuminates a green LED to indicate a safe
environment. This setup provides a simple yet effective smoke detection system, alerting users
to potential hazards with both visual and auditory signals.
Schematic Diagram:
Program used:
#include <Servo.h>
// Pin definitions
const int trigPin = 9;
const int echoPin = 10;
const int smokeSensorPin = A0;
const int buzzerPin = 8;
const int ledPin = 7;
// Smoke detection threshold
const int smokeThreshold = 300; // Adjust based on calibration
void setup() {
Serial.begin(9600); // Start serial communication
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
void loop() {
long duration, distance;
// Ultrasonic sensor
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
// Read smoke level
int smokeLevel = analogRead(smokeSensorPin);
// Print values to Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.print(" cm | Smoke Level: ");
Serial.println(smokeLevel);
// Check for smoke
if (smokeLevel > smokeThreshold) {
digitalWrite(buzzerPin, HIGH); // Turn on buzzer
digitalWrite(ledPin, HIGH); // Turn on LED
} else {
digitalWrite(buzzerPin, LOW); // Turn off buzzer
digitalWrite(ledPin, LOW); // Turn off LED
delay(500); // Delay before the next reading
Procedure:
1. Arduino Digital pin 0 is connected with the (+ve) pin of the buzzer.
2. Arduino Digital pin 1 is connected with the (+ve) pin of LED1 (green).
3. Arduino Digital pin 2 is connected with the (+ve) pin of LED2 (red).
4. Arduino Analog pin A0 is connected with A0 Pin of the MQ2 Gas sensor.
Circuit:
Precautions:
1. All the connections should be tight.
2. Handle the equipment carefully.
3. Compile and upload the correct program.
4. While making connections, take care of the pins of jumper wires as they are very thin and can
break easily.
Result:
Smoke detector has been successfully designed and implemented in the lab.