Bird Photo Booth
I've had this planned for a couple of weeks now but wanted to get this pushed out for the contest. Forgive the jankyness but a more complete project will come soon.
Supplies
1x Raspberry Pi
1x Micro SD Card
1x PIR Sensor
1x External Power Bank
1x Camera Module (I used the Raspberry Pi HQ Camera with the telephoto lens)
3x Ribbon Cables
Setup the Raspberry Pi
First we will need to set up the micro sd card to install our OS. Then we will set up the Raspberry Pi for headless use of the camera.
1. Prep Micro SD Card and install OS
- For a headless setup follow the document below.
- Setup WiFi/SSH without need for monitor and Keyboard (highly recommend)
2.Set up Raspberry Pi for headless camera use
- This is a crucial step and will give you the ability to use VNC to connect to the pi later.
- Follow steps 2 through 4.
Copy Code
You must create a folder in your home directory called 'Cam'.
- ssh into pi or vnc into pi and open terminal
- type 'pwd' to ensure you are in the Pi home directory...you should see /home/pi
- once confirmed type 'mkdir Cam'
Copy the below code into a file.
- ssh into pi or vnc into pi and open terminal
- type nano filename.py
- copy and paste
- control + x to save
- press y
--------------------------------------------------------------------------------------------------------------
from gpiozero import MotionSensor #import motion sensor library
from datetime import datetime #import datetime for file naming
from picamera import PiCamera #import camera library
import time #import time for sleep
pir = MotionSensor(4) #define pir gpio pin
camera = PiCamera() #define PiCamera
camera.rotation = 180 #set camera rotation if needed to adjust camera/set to 0 or comment out if not needed
camera.resolution = (4056,3040) #set max camera resolution for your camera
try:
time.sleep(30) #sleep 30 seconds before entering while loop for pir to adjust? Idk read this online lol
while True: #infenite while loop
if pir.wait_for_motion() == True: #if motion is detected enter if statement
now = datetime.now() current_time = now.strftime("%H:%M:%S") #setup datetime string to append to filename
camera.capture('/home/pi/Cam/image_' + str(current_time) + '.jpg') #take picture and name file
except Keyboard Interrupt:
pass
-------------------------------------------------------------------------------------------------------------
Start the Program
Run for testing
Start: python3 filename.py
Stop: control + c
Running in the background
Start in the background: nohup python3 filename.py &
Stop: pkill python
Start on boot
Instructions to start on boot (Method 4 is what I recommend)
(Special Case Scenario) Out of Memory Error
If you are getting an out of memory error on the start of the python program you must increase the memory in the boot/config.txt file. This is due to the camera resolution being to high.
- ssh into pi or vnc into pi and open up the terminal
- nano /boot/config.txt
- scroll down and look for gpu_mem
- increase the value there(I increased mine to 200)
- control + x after you have made the edit
- press y
- reboot
Finished Product
Hello keep in mind this is a first draft of this project. I want to highlight some tips when adapting this into your own project. I would also like to say the core principals of this project could be adapted to fit your specific scenario.
PIR Sensor
The PIR is extremely sensitive had to point the sensor downwards towards the bird food to ensure less false positives occur and the camera is not taking pictures of nothing. I even used a permanent market to limit the sensors view.
Positioning
If you are using the Raspberry Pi HQ Camera you must set up to feed at the right length. To do this I placed a figure to set my focus then placed the bird feed where I had my figurine.
Photos
The two odd photos of the bunch were grabbed in testing, just thought i'd share.