Skip to content

Instantly share code, notes, and snippets.

@RedTahr
Forked from waveform80/security_light.py
Created July 31, 2018 08:50
Show Gist options
  • Save RedTahr/5d3c31c7b8f45cb0215ea64ad161342b to your computer and use it in GitHub Desktop.
Save RedTahr/5d3c31c7b8f45cb0215ea64ad161342b to your computer and use it in GitHub Desktop.
from gpiozero import LED, MotionSensor, LightSensor
from signal import pause
pir = MotionSensor(21)
ldr = LightSensor(26)
light = LED(25)
def daytime():
pir.when_motion = None
pir.when_no_motion = None
light.off()
def nighttime():
pir.when_motion = light.on
pir.when_no_motion = light.off
ldr.when_light = daytime
ldr.when_dark = nighttime
pause()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment