The circuit is designed to detect fire using a KY-026 Flame Sensor and respond by activating a buzzer and a sprinkler system controlled by a 1 Channel 5V Relay Module. The system is powered by a 12V battery and uses an Arduino UNO as the central microcontroller to process sensor data and control the peripherals. The Arduino also interfaces with a Sim800l module to send SMS alerts and make calls in case of fire detection. The circuit includes resistors for voltage regulation and a fan for cooling purposes.
#include <SoftwareSerial.h>
// Alarm receiver's phone numbers with country code
const String PHONE_1 = "+9187774 98297";
const String PHONE_2 = "+9187774 98297"; // Optional
const String PHONE_3 = "+9187774 98297"; // Optional
#define rxPin 2
#define txPin 3
SoftwareSerial sim800L(rxPin, txPin);
#define flame_sensor_pin 5
#define buzzer_pin 4
#define RELAY_PIN 6
#define SPRINKLER_START_DELAY 5000 // 5 seconds
#define SPRINKLER_ON_TIME 3000 // 3 seconds sprinkler on time
boolean fire_flag = 0; // fire_flag = 0 means no fire detected
unsigned long previousTime = 0; // Initialize to 0 at the start
void setup()
{
Serial.begin(115200); // Begin serial communication: Arduino IDE (Serial Monitor)
sim800L.begin(9600); // Begin serial communication: SIM800L
pinMode(flame_sensor_pin, INPUT);
pinMode(buzzer_pin, OUTPUT);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(buzzer_pin, LOW);
digitalWrite(RELAY_PIN, HIGH); // Relay is off initially (HIGH for low-level trigger)
Serial.println("Initializing...");
// Initialize SIM800L Module
sim800L.println("AT"); // Send AT command to check communication
delay(2000); // Wait for response
Serial.println("AT command sent");
sim800L.println("AT+CMGF=1"); // Set SMS to Text Mode
delay(1000); // Wait for response
Serial.println("Set SMS to Text Mode");
}
void loop()
{
// Read and print any available data from SIM800L
while (sim800L.available()) {
Serial.println(sim800L.readString());
}
int flame_value = digitalRead(flame_sensor_pin);
Serial.println("Flame Sensor Value: " + String(flame_value)); // Debugging output
// Fire detected, trigger alarm, send SMS, make calls, and control sprinkler
if (flame_value == LOW) // Check sensor logic (LOW means fire detected)
{
digitalWrite(buzzer_pin, HIGH); // Turn ON buzzer
Serial.println("Fire detected. Activating buzzer.");
if (fire_flag == 0) // Check if this is the first fire detection
{
fire_flag = 1; // Set fire flag to prevent multiple alerts
send_multi_sms(); // Send SMS to all numbers
make_multi_call(); // Call all numbers
}
// Delay before activating the sprinkler
if (millis() - previousTime > SPRINKLER_START_DELAY)
{
digitalWrite(RELAY_PIN, LOW); // Turn ON sprinkler (low-level triggered)
delay(SPRINKLER_ON_TIME); // Keep sprinkler on for the specified time
digitalWrite(RELAY_PIN, HIGH); // Turn OFF sprinkler
previousTime = millis(); // Reset timer for next fire detection
}
}
else
{
digitalWrite(buzzer_pin, LOW); // Turn OFF buzzer
Serial.println("No fire detected, resetting system.");
fire_flag = 0; // Reset fire flag
previousTime = millis(); // Reset previous time
}
}
void send_multi_sms()
{
if (PHONE_1 != "") {
Serial.print("Phone 1: ");
send_sms("Fire is Detected", PHONE_1);
}
if (PHONE_2 != "") {
Serial.print("Phone 2: ");
send_sms("Fire is Detected", PHONE_2);
}
if (PHONE_3 != "") {
Serial.print("Phone 3: ");
send_sms("Fire is Detected", PHONE_3);
}
}
void make_multi_call()
{
if (PHONE_1 != "") {
Serial.print("Phone 1: ");
make_call(PHONE_1);
}
if (PHONE_2 != "") {
Serial.print("Phone 2: ");
make_call(PHONE_2);
}
if (PHONE_3 != "") {
Serial.print("Phone 3: ");
make_call(PHONE_3);
}
}
void send_sms(String text, String phone)
{
Serial.println("Sending SMS...");
delay(50);
// Initialize SMS text mode
sim800L.println("AT+CMGF=1");
delay(1000);
// Create SMS command with phone number
String command = "AT+CMGS=\"" + phone + "\"";
sim800L.println(command);
delay(1000);
// Send SMS text
sim800L.println(text);
delay(100);
// End SMS command with Ctrl+Z
sim800L.write(0x1A); // ASCII code for Ctrl+Z
delay(5000);
}
void make_call(String phone)
{
Serial.println("Calling...");
// Create call command
String command = "ATD" + phone + ";