Introduction: The Pi Guardian

Picture of The Pi Guardian

Have you ever wanted to catch that one person who keeps stealing your
Halloween candy? Or what about that annoying roommate who won't leave your fridge alone? By using a Raspberry Pi 3, Pi Camera, and PIR sensor, all of that is now possible. Simply put it in a location you want monitored and get emailed with an attached photo of the perpetrator.

Step 1: Video

Step 2: Setting Up the Pi

Picture of Setting Up the Pi

DFRobot reached out to me and sent their Raspberry Pi 3 and Raspberry Pi Camera Module. So after I opened up the boxes I got right to work by setting up the SD card. First I went to the Raspberry Pi Downloads page and downloaded the most recent version of Raspbian. I then extracted the file and put it into a convenient directory. You can't just copy/paste a .img file to an SD card, you have to "burn it" onto the card. You can download a burning utility like to easily transfer the OS image. After the .img file was on my SD card I inserted it into the Raspberry Pi and gave it power. After about 50 seconds I unplugged the cord and removed the SD card. Next I put the SD card back into my PC and went to the "boot" directory. I opened up notepad and saved it as a blank file named "ssh" with NO extension. There was also a file I added called "wpa_supplicant.conf" and put this text into it: network={ ssid=<"SSID"> psk=<"PASSWD"> } Then I saved and ejected the card and put it back into the Raspberry Pi 3. This should now allow for the usage of SSH and connecting to WiFi.

Step 3: Getting the Camera Ready

Picture of Getting the Camera Ready

By default, the camera is disabled on the Pi, so you must open the terminal type sudo raspi-config
to bring up the menu. Go to "interfacing options" and then enable the camera. Now just select "Finish" and insert the ribbon cable of the camera module into the correct area of the Pi.

Step 4: Wiring the PIR Sensor

Picture of Wiring the PIR Sensor

A PIR sensor stands for Passive InfraRed, which basically means it can
detect heat, and therefor humans moving in front of it. There are only 3 leads to connect: VCC, GND, and OUTPUT. VCC gets connected to 3.3V, GND to GND of course, and OUTPUT to pin 4 (BCM numbering) on the Pi.

Step 5: The Code

I have attached code to this project page, so all you have to
do is copy/paste it, but with one catch. It isn't good practice to store passwords in plain text, let alone a main account password. Therefore, you can go to the Google Accounts page and select security, then app passwords. Add a new one called "Raspberry Pi Email" and copy/paste that 16 character password into the code. This allows you to delete the password after you're done with it, improving security. Also enter the email address for your Google account that you used to setup the app password.

Step 6: Running It

Picture of Running It

Now simply run the code by typing sudo python .py I set my device across from my new stash of Halloween candy to monitor if someone is trying to steal it.


About This Instructable




More by Arduino_having11_Guy:Raspberry SPy RobotThe Pi GuardianWW2 Tank Laser Tag
Add instructable to: