Monday, March 16, 2015

Fire Detection using Raspberry Pi

 Here in we are going to see how simple it is to come up with your own Fire detecting device using flame sensor and Raspberry pi . We  can use a buzzer or turn on water sprinklers or even  send an automatic email to fire department.  I'm going to use an LED which blinks on fire detection.

Requirements :


  1.        Raspberry Pi
  2.        Flame detector
  3.        LED 
  4.        330 Ohm resistor


Flame Sensor Interface:


  •  VCC :-  3.3V-5V voltage
  •  GND :- GND
  •  DO :- board digital output interface (0 and 1)
  •  AO :- board analog output interface


Circuit/ Connection Images:



Connection Steps:

1) Connect Ground on sensor to ground on Raspberry Pi.
2) Supply + 3.3V to power( + symbol on sensor).
3)  Connect Digital out pin of sensor to GPIO input using a resistor (256 O).
4) Connect GPIO out to LED .

Demo:




Code :

I'm using GPIO 18 as output which is connected to LED and GPIO pin 25 as Input from Flame Sensor


from time import sleep
import RPi.GPIO as GPIO

#GPIO.setmode(GPIO.BOARD)
GPIO.setmode(GPIO.BCM)

GPIO.setwarnings(False)

LedOut = 18
Flamein = 25

#Switch Pin
GPIO.setup(Flamein, GPIO.IN)

#Switch Led
GPIO.setup(LedOut, GPIO.OUT)
count = 0

while True:
    try:
        if (GPIO.input(25) == True):
            print 'fire in your house'
            GPIO.output(LedOut, 1)
            sleep(0.1)
            GPIO.output(LedOut, 0)
            sleep(0.1)
            GPIO.output(LedOut, 1)
         
        else:
            print 'you are safe'
            GPIO.output(LedOut, 0)
         
    except KeyboardInterrupt:
        exit()
GPIO.cleanup()









12 comments:

  1. Hi : Your script works, but keeps printing "you are safe' until I interrupt with CRTL-C or I light a flame near the sensor when it keeps printing "fire in your house". Can you tell me how to update your script for the sensor to print "you are safe" once and wait for a change in the Flame Sensor state and print "fire in your house" may be just a few times, instead of endless number of times?

    ReplyDelete
    Replies
    1. Thanks for asking. You can use two variables curr_state and prev_state. Something like this

      if (GPIO.input(25) == True):
      curr_state = True

      else:
      curr_state =False

      if (curr_state != prev_state):
      prev_state=curr_state
      perform print

      Delete
  2. please tell me the complete component which you used in the project..
    what type of berry pi you use..?
    how many resistor are required?
    which software is used to run this programe?

    ReplyDelete
    Replies
    1. Hi, Sorry for late reply, I have used 2 resistors and Raspberry pi 2. Its python script

      Delete
  3. Flame Sensor results true if there is no fire while it results to be false if fire is present .The code needs to be bit modified for flame sensors (SR017).

    ReplyDelete
    Replies
    1. Hello,
      What changes did you make?? Is it working for you? Kindly let me know.

      Delete
    2. Hey @Mansi.. I made a Wirelessly Manual controlled Enhanced Fire Extinguishing Robot for my final year B.Tech Project for which i needed my IR flame sensor (SR017) to detect fire. Make the following changes and your code will run fine-:

      from time import sleep
      import RPi.GPIO as GPIO

      #GPIO.setmode(GPIO.BOARD)
      GPIO.setmode(GPIO.BCM)

      GPIO.setwarnings(False)

      LedOut = 18
      Flamein = 25

      #Switch Pin
      GPIO.setup(Flamein, GPIO.IN)

      #Switch Led
      GPIO.setup(LedOut, GPIO.OUT)
      count = 0

      while True:
      try:
      if (GPIO.input(25) == False):
      print 'fire in your house'
      GPIO.output(LedOut, 1)
      sleep(0.1)
      GPIO.output(LedOut, 0)
      sleep(0.1)
      GPIO.output(LedOut, 1)
      else:
      print 'you are safe'
      GPIO.output(LedOut, 0)
      except KeyboardInterrupt:
      exit()
      GPIO.cleanup()




      Let me know if you have any problem. ;)

      Delete
    3. @Yuvraj. Thanks for the reply. Actually I did work with that False statement, but I couldn't get the reason behind making it false and so asked for your solution. Let me know the reason if you have.

      Delete
    4. The flame sensor works in an opposite fashion unlike other sensors,by default it produces high output(True) when there is no fire in its vicinity and produces an low input(False) when it senses fire in its range.So as soon as the pin 25 produces low value by sensing fire,Led blinking starts.

      Raspberry Pi is not capable of doing Analog to Digital Conversion unlike other micro-controller board such as Arduino which has Analog and Digital pins in it implicitly. The lower the value of Analog pin of Arduino connected to the flame sensors (i.e. close to 100), the stronger is the fire,similarly when the Raspberry Pi senses low input i.e.(False) it indicates fire is present.

      Hope it helps.

      Delete
    5. @yuvraj: That really helped.. Thank you.

      Delete
    6. @mansi .. Happy to Help :-)

      Delete
  4. which flame sensor was used for the initial code?

    ReplyDelete