The Official Raspberry Pi Projects Book - Projects_Book_v4

(singke) #1

Tutorial


raspberrypi.org/magpi The Official Raspberry Pi Projects Book 97


PISPY CAM


the little orange screws on the side of the PIR board.
Once that’s done, it’s best to make it so that when the
Raspberry Pi boots up, it logs directly into command-
line mode. This means it will use up a little less power
so your battery lasts longer. It’s then a good idea to
open up the terminal and edit the profile config file
with sudo nano /etc/profile. To the bottom of the
file, add this line:


sudo python spy.py



STEP-05
Hide your camera
Now you need to find a good place to hide your
camera. The cable for the camera is limited by length,
while the PIR can have its wires lengthened, so keep
that in mind when building your system. Hiding the
Pi and battery behind a plush toy or photo frame can
work well; you could even put a dummy photo up and
cut a hole in it for the camera to look through. The PIR
has quite a wide range, so put it up high where people
are unlikely to look.



>STEP-06
Check for intruders
All you need to do now is plug in the battery and the Pi
Zero will turn on and run the script. Do some tests to
make sure the camera is facing the right way. Leave it
running during the day and then when you get back,
plug it into a monitor, stop the script, and run startx
to get the GUI up. From here you can see the pictures
it has taken – crucial evidence to catch your dog or
sibling red-handed.

spy.py


#!/usr/bin/env python

from gpiozero import MotionSensor
from picamera import PiCamera
from datetime import datetime
from time import sleep

sensor = MotionSensor( 14 )
camera = PiCamera()

while True:
sensor.wait_for_motion()
filename = datetime.now().strftime("%H. %M. %S_ %Y- %m- %d.jpg")
camera.capture(filename)
sleep( 5 )

Language
>PYTHON 3

DOWNLOAD:
magpi.cc/PiSpy

Now you need to


find a good place to


hide your camera


You should probably hide yours
somewhere slightly better – its
range is far, though

Camouflaged against Yoshi,
the camera will take candid
snaps of anyone who comes
close to your game collection
Free download pdf