Skip to content

Instantly share code, notes, and snippets.

@suadanwar
Created October 6, 2020 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suadanwar/5438c89eeff86e7a7d193788b58c960b to your computer and use it in GitHub Desktop.
Save suadanwar/5438c89eeff86e7a7d193788b58c960b to your computer and use it in GitHub Desktop.
This sample code is for Raspberry Pi Security Camera with Motion Detector tutorial(image).
from gpiozero import MotionSensor
from picamera import PiCamera
import time
from time import sleep
pir = MotionSensor(4)
camera = PiCamera()
camera.rotation = 180
while True:
pir.wait_for_motion()
print("Motion detected!")
camera.start_preview(fullscreen=False, window = (1250,10,640,480))
filename = "/home/pi/Desktop/" + (time.strftime("%y%b%d_%H:%M:%S")) + ".jpg"
camera.capture(filename)
pir.wait_for_no_motion()
camera.stop_preview()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment