Hello,
I am trying to simulate an alarm system on a raspberry pi. I would like Led2 to blink when intruder is detected.
I would like also to add an email alert when intruder is detected. I have no idea how to send an email using pi.
For now i reshaped a code i have found on the net.
I can activate the system by pushing button 1 and Led2 will light if intruder is detected. If i click a second time alarm is off.
Any idea how it could be fix?
Thank you
I am trying to simulate an alarm system on a raspberry pi. I would like Led2 to blink when intruder is detected.
I would like also to add an email alert when intruder is detected. I have no idea how to send an email using pi.
For now i reshaped a code i have found on the net.
I can activate the system by pushing button 1 and Led2 will light if intruder is detected. If i click a second time alarm is off.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
from time import sleep import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) button1 = 16 button2 = 12 LED1 = 22 LED2 = 18 GPIO.setup(button1,GPIO.IN,pull_up_down = GPIO.PUD_UP) GPIO.setup(button2,GPIO.IN,pull_up_down = GPIO.PUD_UP) GPIO.setup(LED1,GPIO.OUT,) GPIO.setup(LED2,GPIO.OUT) BS1 = False BS2 = False while ( 1 ): if GPIO. input (button1) = = 0 : if BS1 = = False : print ( "Alarm on" ) GPIO.output(LED1, True ) BS1 = True sleep(. 5 ) else : print ( "Alarm off" ) GPIO.output(LED1, False ) GPIO.output(LED2, False ) BS1 = False sleep(. 5 ) if GPIO. input (button2) = = 0 and GPIO. input (button1) = = 1 : print ( "There is an intruder" ) if BS1 = = True : GPIO.output(LED2, True ) BS2 = True sleep(. 5 ) else : GPIO.output(LED2, False ) BS2 = True sleep(. 5 ) |
Thank you