### README for Fire and Smoke Detection System
# Fire and Smoke Detection System
Welcome to the Fire and Smoke Detection System project! This project demonstrates how to create a basic fire detection system using the Wokwi Arduino Simulator. The system detects smoke and flames using virtual sensors and triggers an alarm when a fire is detected. This project is a great way to learn about fire detection systems and how they work.
## Components Used
- **Arduino UNO**: The brain of our system.
- **MQ-2 Smoke Sensor**: Detects smoke levels.
- **Flame Sensor**: Detects the presence of flames.
- **1602 LCD Display**: Displays status messages.
- **Buzzer**: Sounds an alarm when fire 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;
const int flameThreshold = LOW;
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 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 detected" message
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Fire 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("Standby");
// Turn off the tone
noTone(speakerPin);
}
// Delay for a moment to avoid rapid display updates
delay(1000);
}
```
## Steps to Simulate
1. **Go to the Wokwi Simulator**: Open the [Wokwi Arduino Simulator](https://wokwi.com/).
2. **Create a New Project**: Click on "New Project".
3. **Import the Diagram**:
- Click on "Import from JSON".
- Paste the JSON code provided below into the editor.
- Click "Create Circuit" to generate the setup.
4. **Upload the Arduino Code**:
- Copy and paste the Arduino code into the code editor.
5. **Run the Simulation**: Start the simulation and observe the fire detection system in action.
## JSON Code
```json
{
"version": 1,
"author": "ChatGPT",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-uno", "id": "uno", "top": -57, "left": -0.6, "attrs": {} },
{ "type": "wokwi-mq2", "id": "mq2", "top": 17.85, "left": -97.78, "attrs": {} },
{ "type": "wokwi-flame-sensor", "id": "flame", "top": 50, "left": 250, "attrs": {} },
{ "type": "wokwi-lcd1602", "id": "lcd1", "top": 164.9, "left": 6.53, "attrs": {} },
{ "type": "wokwi-buzzer", "id": "bz1", "top": -151.2, "left": 309, "attrs": { "volume": "0.1" } }
],
"connections": [
[ "mq2:VCC", "uno:5V", "red", [ "v0" ] ],
[ "mq2:GND", "uno:GND.2", "black", [ "v0" ] ],
[ "mq2:AOUT", "uno:A0", "green", [ "v0" ] ],
[ "flame:VCC", "uno:5V", "red", [ "v0" ] ],
[ "flame:GND", "uno:GND", "black", [ "v0" ] ],
[ "flame:DOUT", "uno:2", "green", [ "v0" ] ],
[ "lcd1:RS", "uno:8", "green", [ "v0" ] ],
[ "lcd1:E", "uno:9", "green", [ "v0" ] ],
[ "lcd1:D4", "uno:4", "green", [ "v0" ] ],
[ "lcd1:D5", "uno:5", "green", [ "v0" ] ],
[ "lcd1:D6", "uno:6", "green", [ "v0" ] ],
[ "lcd1:D7", "uno:7", "green", [ "v0" ] ],
[ "bz1:1", "uno:GND.3", "green", [ "v0" ] ],
[ "bz1:2", "uno:10", "green", [ "v-21.03", "h-175.53" ] ]
],
"dependencies": {}
}
```
## Conclusion
This Fire and Smoke Detection System is a simple yet effective way to understand how such systems work. By following the instructions and using the provided code, you can simulate a fire detection system that detects smoke and flames, displaying messages on an LCD and sounding an alarm when fire is detected. Enjoy experimenting with and learning from this project!
Feel free to reach out if you have any questions or need further assistance. Happy simulating!