Skip to content

Instantly share code, notes, and snippets.

@suadanwar
Last active 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/47c64949113f1d0577fe2b032789bd6e to your computer and use it in GitHub Desktop.
Save suadanwar/47c64949113f1d0577fe2b032789bd6e to your computer and use it in GitHub Desktop.
This sample code is for Raspberry Pi Security Camera with Motion Detector tutorial.
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")) + ".h264"
camera.start_recording(filename)
pir.wait_for_no_motion()
camera.stop_recording()
camera.stop_preview()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment