Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Raspberry Pi Zero W Fire Detection System with SIM900A and Buzzer Alert

View and Edit Project In Cirkit DesignerImage of Raspberry Pi Zero W Fire Detection System with SIM900A and Buzzer Alert

Circuit Documentation

Summary

This circuit is designed to detect fire using a flame sensor and a gas sensor. When a fire is detected, the system activates a buzzer and sends an SMS alert using the SIM900A GSM module. The entire system is controlled by a Raspberry Pi Zero W.

Component List

  1. SIM900A

    • Description: GSM/GPRS module used for sending SMS and making calls.
    • Pins: GND, DB9-3 (RXD), DB9-2 (TXD), 5V, 3VR, 5VR, 3VT, 5VT, VCC, Ring, RESTART, RESET, STATUS
  2. Buzzer

    • Description: An audio signaling device used to alert when a fire is detected.
    • Pins: PIN, GND
  3. MQ2

    • Description: Gas sensor used to detect the presence of gas.
    • Pins: VCC, GND, AOUT, DOUT
  4. KY-026 Flame Sensor

    • Description: Sensor used to detect the presence of fire.
    • Pins: A0, GND, VCC, D0
  5. Raspberry Pi Zero W

    • Description: A small, affordable computer used to control the entire system.
    • Pins: 5V, 3V3, GPIO2 (SDA), GPIO 3, GROUND, GPIO 14, GPIO15, GPIO 18, GND, GPIO 23, GPIO24, GPIO 25, GPIO 8, GPIO 7, GPIO 1, GPIO 12, GPIO 16, GPIO 20, GPIO 21, GPIO 04, GPIO 17, GPIO 27, GPIO 22, GPIO 10, GPIO 9, GPIO 11, GPIO 0, GPIO 5, GPIO 6, GPIO 13, GPIO 19, GPIO 26, CSI (CAMERA)

Wiring Details

SIM900A

Buzzer

MQ2

KY-026 Flame Sensor

Raspberry Pi Zero W

Code Documentation

import RPi.GPIO as GPIO
import serial
import time

# Phone numbers
PHONE_1 = "+9647704215880"
PHONE_2 = ""  # optional
PHONE_3 = ""  # optional

# GPIO pin definitions
FLAME_SENSOR_PIN = 17
BUZZER_PIN = 18

# Setup GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(FLAME_SENSOR_PIN, GPIO.IN)
GPIO.setup(BUZZER_PIN, GPIO.OUT)
GPIO.output(BUZZER_PIN, GPIO.LOW)

# Setup serial communication with SIM800C
sim800L = serial.Serial('/dev/serial0', baudrate=9600, timeout=1)

def send_sms(text, phone):
    print("Sending SMS...")
    sim800L.write(b'AT+CMGF=1\r')
    time.sleep(1)
    sim800L.write(b'AT+CMGS="' + phone.encode() + b'"\r')
    time.sleep(1)
    sim800L.write(text.encode() + b'\r')
    time.sleep(1)
    sim800L.write(bytes([26]))  # ASCII code for Ctrl+Z
    time.sleep(5)

def make_call(phone):
    print("Calling...")
    sim800L.write(b'ATD' + phone.encode() + b';\r')
    time.sleep(20)
    sim800L.write(b'ATH\r')
    time.sleep(1)

def send_multi_sms():
    if PHONE_1:
        print("Phone 1: ")
        send_sms("Fire is Detected", PHONE_1)
    if PHONE_2:
        print("Phone 2: ")
        send_sms("Fire is Detected", PHONE_2)
    if PHONE_3:
        print("Phone 3: ")
        send_sms("Fire is Detected", PHONE_3)

def make_multi_call():
    if PHONE_1:
        print("Phone 1: ")
        make_call(PHONE_1)
    if PHONE_2:
        print("Phone 2: ")
        make_call(PHONE_2)
    if PHONE_3:
        print("Phone 3: ")
        make_call(PHONE_3)

def main():
    fire_flag = False
    print("Initializing...")
    sim800L.write(b'AT\r')
    time.sleep(1)
    sim800L.write(b'AT+CMGF=1\r')
    time.sleep(1)

    while True:
        flame_value = GPIO.input(FLAME_SENSOR_PIN)
        if flame_value == GPIO.LOW:
            GPIO.output(BUZZER_PIN, GPIO.HIGH)
            if not fire_flag:
                print("Fire Detected.")
                fire_flag = True
                send_multi_sms()
                make_multi_call()
        else:
            GPIO.output(BUZZER_PIN, GPIO.LOW)
            fire_flag = False
        time.sleep(1)

if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        GPIO.cleanup()

This code initializes the GPIO pins and sets up serial communication with the SIM900A module. It continuously monitors the flame sensor, and if a fire is detected, it activates the buzzer, sends SMS alerts, and makes phone calls to predefined numbers.