Skip to content

Instantly share code, notes, and snippets.

@nkenna
Created June 21, 2018 10:06
Show Gist options
  • Save nkenna/9c71c0a9dc2d22821cc43908ceee90af to your computer and use it in GitHub Desktop.
Save nkenna/9c71c0a9dc2d22821cc43908ceee90af to your computer and use it in GitHub Desktop.
motion sensors events
def garageMotion(pinPIR_garage):
if sm.securityStatus:
if GPIO.input(pinPIR_garage):
print('pinPIR_garage motion detected')
GPIO.output(pinAlarm , GPIO.HIGH)
GPIO.output(pinGarageLight, GPIO.HIGH)
sleep(1)
CServo.set_servo(pinCServo, 1500)
pubnub.publish().channel(SENSORS).message(MOTION_PIR2).async(my_publish_callback)
else:
print('pinPIR_garage detection ends')
GPIO.output(pinAlarm, GPIO.LOW)
GPIO.output(pinGarageLight, GPIO.LOW)
sleep(1)
GPIO.output(pinSecurityLight, GPIO.LOW)
CServo.set_servo(pinCServo, 1500)
def bedroomMotion(pinPIR_bedroom):
if sm.securityStatus:
if GPIO.input(pinPIR_bedroom):
print('pinPIR_bedroom motion detected')
GPIO.output(pinAlarm, GPIO.HIGH)
GPIO.output(pinBedroomLight, GPIO.HIGH)
sleep(5)
CServo.set_servo(pinCServo, 2200)
pubnub.publish().channel(SENSORS).message(MOTION_PIR1).async(my_publish_callback)
else:
print('pinPIR_bedroom motion detection ends')
GPIO.output(pinAlarm, GPIO.LOW)
GPIO.output(pinBedroomLight, GPIO.LOW)
sleep(5)
CServo.set_servo(pinCServo, 1500)
def sittingroomMotion(pinPIR_sittingroom):
if sm.securityStatus:
if GPIO.input(pinPIR_sittingroom):
print('pinPIR_sittingroom motion detected')
GPIO.output(pinAlarm, GPIO.HIGH)
GPIO.output(pinSittingRoomLight, GPIO.HIGH)
sleep(1)
CServo.set_servo(pinCServo, 1200)
pubnub.publish().channel(SENSORS).message(MOTION_PIR3).async(my_publish_callback)
else:
print('pinPIR_sittingroom motion detection ends')
GPIO.output(pinAlarm, GPIO.LOW)
GPIO.output(pinSittingRoomLight, GPIO.LOW)
sleep(5)
CServo.set_servo(pinCServo, 1500)
#sleep(2)
GPIO.add_event_detect(pinPIR_sittingroom, GPIO.BOTH, callback=sittingroomMotion)
GPIO.add_event_detect(pinPIR_bedroom, GPIO.BOTH, callback=bedroomMotion)
GPIO.add_event_detect(pinPIR_garage, GPIO.BOTH, callback=garageMotion)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment