Skip to content

Instantly share code, notes, and snippets.

@jezman
Created September 8, 2016 11:10
Show Gist options
  • Save jezman/4083ffcf05235be41ae6269efa9e569d to your computer and use it in GitHub Desktop.
Save jezman/4083ffcf05235be41ae6269efa9e569d to your computer and use it in GitHub Desktop.
The script for motion app. Executed when a motion frame is detected. Writes the sensor status.
#!/usr/bin/env python
import RPi.GPIO as GPIO
from time import sleep
pir_sensor = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(pir_sensor, GPIO.IN)
fl = open('/home/user/sensor_status', 'w')
i = 0
current_state = 0
while i < 6:
current_state = GPIO.input(pir_sensor)
fl.write('%s' % (current_state))
sleep(1)
i += 1
GPIO.cleanup(18)
fl.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment