Reputation:
just need a quick advice if anyone can help. I finished my code for my alarm project using kivy for the gui and python for the script. My issue however is with the motionsensor. I can detect if motion is high or low no problem. Is there a way however to stop the motionsensor from detecting as in a low or false state lets say if i enter a disarm pin. Seems once the alarm is activated it cant be turned off. Code can submitted on request but im hoping theres a simple way to achieve this.
def callback(self):
global Activated, Armed
if GPIO.input(11)==False:
Activated = False
Armed = True
elif GPIO.input(11) == True:
Activated = True
Armed = False
else:
pass
if Activated == True:
self.info.text = '!!Intruder Alert!!'
self.info.background_color = [1, 1, 0, 1]
GPIO.output(16,1)
GPIO.output(22, 1)
GPIO.output(18,0)
#self.txt_display.text = ''
#time.sleep(3)
#disarm = int(input('Enter deactivation code'))
else:
pass
def reset_notice(self):
self.info.text = 'Alarm disarmed'
def armAlarm(self):
global Activated, Armed
if self.txt_display.text == str(pincode):
Clock.schedule_once(lambda dt: self.indicated(), 3)
Armed = True
Activated = False
GPIO.output(22, 0)
GPIO.output(18, 1)
GPIO.output(16,1)
time.sleep(0.5)
GPIO.output(16,0)
elif self.txt_display.text != str(pincode):
Armed = False
Activated = False
self.txt_display.text = ''
self.info.text = '**Incorrect Pin**'
self.info.background_color = [1, 1, 1, 1]
Clock.schedule_once(lambda dt: self.reset_notice(), 3)
self.info.background_color = [0, 1, 0, 1]
if Armed == False:
Clock.schedule_interval(lambda dt: self.callback(), 0.5)
else:
self.reset_alarm()
in kv file when i press a button it runs the armAlarm function, if the alarm is activated the pir is also activated and if an intruder is detected the buzzer goes off, buzzer is 16.
def disarmAlarm(self):
global Activated, Armed
Armed = True
Activated = False
if Armed == True:
if Activated == False:
if self.txt_display.text == str(pincode):
self.info.text = 'Alarm disarmed'
self.info.background_color = [0, 1, 0, 1]
self.txt_display.text = ''
Armed = False
Activated = False
GPIO.output(16,0)
GPIO.output(22, 0)
GPIO.output(18, 0)
GPIO.setup(11, GPIO.IN)
print('Alarm deactivated')
def disarmAlarm(self):
global Activated, Armed
Armed = True
Activated = True
if Armed == True:
if Activated == True:
if self.txt_display.text == str(pincode):
self.info.text = 'Alarm disarmed'
self.info.background_color = [0, 1, 0, 1]
self.txt_display.text = ''
Armed = False
Activated = False
GPIO.output(16,0)
GPIO.output(22, 0)
GPIO.output(18, 0)
print('Alarm deactivated')
def pir_off(self):
GPIO.input(11) == False
def reset_alarm(self):
global Activated, Armed
Armed = False
Activated = False
if Armed == False:
if Activated == False:
Clock.schedule_interval(lambda dt: self.pir_off(), 0.1)
and its supposed to do this when i deactivate the alarm which it does, theoretically, problem is if i put my hand in front of the pir it still detects movement. I want to stop it from detecting or looking for movement altogether.
Upvotes: 0
Views: 419
Reputation: 131
The main issue I'm seeing is you have the PIR sensor unconditionally linked to the Alarm state. You are trying to remedy this by turning off / changing the sensor after the disarm code is entered, or for whatever reason the system goes into Disarmed mode.
def callback(self):
global Activated, Armed
#we dont care if the PIR goes to False. This only matters for lighting systems and
#the like.
if GPIO.input(11) == False:
pass
elif GPIO.input(11) == True and Armed == True:
Activated = True
The above example receives ALL of the PIR data as raw data, and only the PIR==True state in combination with the Armed==True state will cause the alarm to trigger.
def callback(self):
global Activated, Armed, PIRRawState
if GPIO.input(11) == False:
if PIRRawState == True:
PIRRawState = False
elif GPIO.input(11) == True:
if PIRRawState == False:
PIRRawState = True
if Armed == True:
activateAlarm()
def activateAlarm(self):
self.info.text = '!!Intruder Alert!!'
self.info.background_color = [1, 1, 0, 1]
GPIO.output(16,1)
GPIO.output(22, 1)
GPIO.output(18,0)
#self.txt_display.text = ''
#time.sleep(3)
#disarm = int(input('Enter deactivation code'))
There are several other things that I'd recommend you change, but I think that will solve the problem for you. Other suggestions will appear in the comments for this Answer.
Upvotes: 0