Motion detection
This sample about motion detection sensor signal use for some event activation. Sensor take from Arduino sensors collection and install special library RPi.GPIO. Important notice, this library work only on Raspberry Pi. So, if you don't have Raspberry Pi ....
import RPi.GPIO as GPIO
import time
from subprocess import call
def call_camera():
call(['python3','/home/pi/Desktop/camera.py'])
def spyeye():
GPIO.setmode(GPIO.BCM)
SENSOR_PIN = 23
GPIO.setup(SENSOR_PIN,GPIO.IN)
try:
while True:
signal = GPIO.input(SENSOR_PIN)
if signal == 1:
print("Motion Detected")
call_camera()
break
else:
time.sleep(0.1)
print("No Motion")
except:
GPIO.cleanup()
spyeye()
import RPi.GPIO as GPIO
import time
from subprocess import call
def call_camera():
call(['python3','/home/pi/Desktop/camera.py'])
def spyeye():
GPIO.setmode(GPIO.BCM)
SENSOR_PIN = 23
GPIO.setup(SENSOR_PIN,GPIO.IN)
try:
while True:
signal = GPIO.input(SENSOR_PIN)
if signal == 1:
print("Motion Detected")
call_camera()
break
else:
time.sleep(0.1)
print("No Motion")
except:
GPIO.cleanup()
spyeye()
When source work, after detect motion start web camera then can get photo or write video.