31. Fire Detection System with Raspberry Pi and Flame Sensor

    In this project, we'll be using a Raspberry Pi along with a Flame Sensor to create an end node for fire detection. The Flame Sensor will be able to detect the presence of fire, and the Raspberry Pi will process this information and provide an output.


Components Needed
  • Raspberry Pi (any model with GPIO pins)
  • Flame Sensor module
  • Jumper wires
Setting Up the Circuit

    1. Connect the VCC pin of the Flame Sensor to the 3.3V pin on the Raspberry Pi.
    2. Connect the GND pin of the Flame Sensor to any GND pin on the Raspberry Pi.
    3. Connect the DO (digital output) pin of the Flame Sensor to GPIO pin 17 (or any other GPIO pin you choose).

Writing the Code

    We'll use Python for programming the Raspberry Pi. Ensure you have the RPi.GPIO library installed on your Raspberry Pi.

Python
import RPi.GPIO as GPIO
import time

# Set the GPIO pin numbers for the fire sensor digital output and the buzzer
fire_pin = 28
buzzer_pin = 17

# Set up the GPIO pins for input and output
GPIO.setmode(GPIO.BCM)
GPIO.setup(fire_pin, GPIO.IN)
GPIO.setup(buzzer_pin, GPIO.OUT)
 
while True:
    # Read the digital output of the fire sensor
    fire_detected = GPIO.input(fire_pin)

    # If a fire is detected, activate the alarm
    if fire_detected:
        print("Fire detected!")
        GPIO.output(buzzer_pin, GPIO.HIGH)
        time.sleep(0.3)
        GPIO.output(buzzer_pin, GPIO.LOW)
        time.sleep(0.3)
        GPIO.output(buzzer_pin, GPIO.HIGH)
        time.sleep(0.3)
        GPIO.output(buzzer_pin, GPIO.LOW)

    # Wait for a short time before reading the sensor again
    time. Sleep(0.1)
    
    This code continuously reads the state of the Flame Sensor connected to GPIO pin 17 of the Raspberry Pi. If the sensor detects a flame, it prints "Fire detected!" to the console; otherwise, it prints "No fire detected". Adjust the GPIO pin number in the code if you connect the sensor to a different pin.

Conclusion

    With this setup, you can create an end node for forest fire detection. You can further enhance this project by integrating it with a wireless communication module to send alerts to a central monitoring system.
Post a Comment (0)
Previous Post Next Post