Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO Based Fire Detection and SMS Alert System with Relay-Controlled Sprinkler

Image of Arduino UNO Based Fire Detection and SMS Alert System with Relay-Controlled Sprinkler

Circuit Documentation

Summary

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.

Component List

Arduino UNO

  • Microcontroller board based on the ATmega328P.
  • It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.

1 Channel 5V Relay Module

  • A module that allows for the control of high power devices, such as the sprinkler system, using low-level signals from a microcontroller.

Sim800l

  • A GSM/GPRS module that can make calls, send texts, and connect to the internet over a mobile network.

KY-026 Flame Sensor

  • A sensor module designed to detect fire or other wavelengths of light at 760 nm - 1100 nm.

Buzzer

  • An electronic component that produces sound. Used here as an alarm to indicate fire detection.

12V Battery

  • Provides power to the circuit.

5V Mini Water Pump

  • A small pump that is activated to sprinkle water when a fire is detected.

Fan

  • An electronic fan used for cooling purposes.

Resistors (1k Ohm)

  • Two resistors used for voltage regulation and current limiting within the circuit.

Wiring Details

Arduino UNO

  • D2 connected to Sim800l RXD
  • D3 connected to Sim800l TXD
  • D4 connected to Buzzer PIN
  • D5 connected to KY-026 Flame Sensor DO
  • D6 connected to 1 Channel 5V Relay Module IN
  • 5V connected to 1 Channel 5V Relay Module VCC+, KY-026 Flame Sensor VCC, and Fan 5V
  • GND connected to Sim800l GND, Buzzer GND, KY-026 Flame Sensor GND, 1 Channel 5V Relay Module VCC- (GND), 5V Mini Water Pump negative pin, and Fan GND
  • Vin connected to 12V Battery +

1 Channel 5V Relay Module

  • VCC+ and COM connected to Arduino UNO 5V
  • VCC- (GND) connected to Arduino UNO GND
  • IN connected to Arduino UNO D6
  • N.O. connected to 5V Mini Water Pump positive pin

Sim800l

  • RXD connected to Arduino UNO D2
  • TXD connected to Arduino UNO D3
  • VCC connected to Arduino UNO 5V
  • GND connected to Arduino UNO GND

KY-026 Flame Sensor

  • AO (Not connected in this circuit)
  • DO connected to Arduino UNO D5
  • VCC connected to Arduino UNO 5V
  • GND connected to Arduino UNO GND

Buzzer

  • PIN connected to Arduino UNO D4
  • GND connected to Arduino UNO GND

12V Battery

  • + connected to Arduino UNO Vin
  • - connected to Arduino UNO GND

5V Mini Water Pump

  • Positive pin connected to 1 Channel 5V Relay Module N.O.
  • Negative pin connected to Arduino UNO GND

Fan

  • 5V connected to Arduino UNO 5V
  • GND connected to Arduino UNO GND

Resistors (1k Ohm)

  • Both resistors are connected in parallel between Arduino UNO 5V and the VCC+ of the 1 Channel 5V Relay Module.

Documented Code

#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 + ";