# Fire and Smoke Detection System
Welcome to the Fire and Smoke Detection System project! This project demonstrates how to create a basic detection system for both fire and smoke using the Wokwi Arduino Simulator. The system detects smoke and flames using virtual sensors and triggers an alarm when either is detected.
## Components Used
- **Arduino UNO**: The central control unit.
- **MQ-2 Smoke Sensor**: Detects smoke levels.
- **Flame Sensor**: Detects the presence of flames.
- **1602 LCD Display**: Shows status messages.
- **Buzzer**: Sounds an alarm when fire or smoke is detected.
## Circuit Diagram

## Wiring Connections
- **MQ-2 Smoke Sensor**:
- VCC to 5V on Arduino
- GND to GND on Arduino
- AOUT to A0 on Arduino
- **Flame Sensor**:
- VCC to 5V on Arduino
- GND to GND on Arduino
- DOUT to Pin 2 on Arduino
- **LCD Display**:
- RS to Pin 8 on Arduino
- E to Pin 9 on Arduino
- D4 to Pin 4 on Arduino
- D5 to Pin 5 on Arduino
- D6 to Pin 6 on Arduino
- D7 to Pin 7 on Arduino
- **Buzzer**:
- Positive to Pin 10 on Arduino
- Negative to GND on Arduino
## Arduino Code
Upload the following code to your Arduino UNO:
```cpp
#include <LiquidCrystal.h>
// Pin configuration for the MQ-2 smoke sensor
const int mq2Pin = A0; // Analog pin for MQ-2 sensor
// Pin configuration for the Flame sensor
const int flamePin = 2; // Digital pin for Flame sensor
// Pin configuration for the LCD
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // RS, EN, D4, D5, D6, D7
// Pin for the speaker or piezo element
const int speakerPin = 10; // Connect the speaker or piezo to digital pin 10
// Threshold values
const int smokeThreshold = 300; // Adjust this threshold for your smoke sensor
const int flameThreshold = LOW; // Adjust this if necessary for your flame sensor
void setup() {
// Initialize the LCD
lcd.begin(16, 2);
// Initialize the MQ-2 sensor pin
pinMode(mq2Pin, INPUT);
// Initialize the Flame sensor pin
pinMode(flamePin, INPUT);
// Set up the speaker pin
pinMode(speakerPin, OUTPUT);
// Set up the initial display message
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Fire & Smoke");
lcd.setCursor(0, 1);
lcd.print("Detection");
}
void loop() {
// Read the value from the MQ-2 smoke sensor
int smokeValue = analogRead(mq2Pin);
// Read the value from the Flame sensor
int flameValue = digitalRead(flamePin);
// Check if the smoke or flame sensor readings are above the threshold
if (smokeValue > smokeThreshold || flameValue == flameThreshold) {
// Clear the LCD and print the "Fire or Smoke Detected" message
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Fire or Smoke");
lcd.setCursor(0, 1);
lcd.print("Detected");
// Generate a tone to create a sound
tone(speakerPin, 1000); // You can adjust the frequency as needed
// You can add additional actions here, like sending a notification.
} else {
// Clear the LCD and display a standby message
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("System Standby");
// Turn off the tone
noTone(speakerPin);
}
// Delay for a moment to avoid rapid display updates
delay(1000);
}