Create your own photo camera using Raspberry Pi Zero
This project provides instructions how to create a very simple photo camera using Raspberry Pi Zero.
Required Materials
- Raspberry Pi Zero (you can use also other models, update the case accordingly) https://www.raspberrypi.org/products/pi-zero-w/
- Pi Camera https://www.raspberrypi.org/products/camera-module-v2/
- Raspberry Pi Case https://www.raspberrypi.org/products/raspberry-pi-zero-case/
- Break-away pins (Raspberry Pi Zero does not come with i/o pins) https://www.adafruit.com/product/2822
- Jumper wires https://www.adafruit.com/product/266
- LED https://www.sparkfun.com/products/10632
- Resistor 330 Ω https://www.sparkfun.com/products/8377
- Momentary Push Button https://www.sparkfun.com/products/9190
- Soldering iron (for model zero, pinout not attached)
- Battery pack/charger
Hardware setup
Raspberry Pi Pinout
- pinout https://pinout.xyz/
- in this project using pin GND, BCM 18, BCM 17
Step 1 – Attach Break-away pins on Raspberry Pi Zero
Step 2 – Solder the wires on LED, resistor and Push Button
Step 3 – Connect the LED on Raspberry Pi
- using pin (GND and BCM 18)
- GND: https://pinout.xyz/pinout/ground
- BCM 18: https://pinout.xyz/pinout/pin12_gpio18
- Test pins:
python led.py to test led
led.py script
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18,GPIO.OUT) print "LED on" GPIO.output(18,GPIO.HIGH) time.sleep(1) print "LED off" GPIO.output(18,GPIO.LOW)
Step 4 – Connect the Push Button on Raspberry Pi
- using pin (GND and BCM 17)
- GND: https://pinout.xyz/pinout/ground
- BCM 17: https://pinout.xyz/pinout/pin11_gpio17
- Test button:
python button.py
button.py script
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.IN,pull_up_down=GPIO.PUD_UP) while True: inputValue = GPIO.input(17) if (inputValue == False): print("Button press ") time.sleep(0.3)
Software Setup
(see git repository below for full source code)
Take a picture
- Take a picture into the current folder (resolution 800×600)
raspistill -t 1 -w 800 -h 600 -o {imgName}
Full script
- ddl-cam.py script monitors the button state, takes a picture and turns the led on during shot time.
- pictures are taken in the same folder where you run the scripts
- you can copy the files from remote machine using scp
- example, copy all jpg files from 192.168.1.15 (your current raspberry pi ip) to your current folder
scp pi@192.168.1.15:/home/pi/ddl-cam/*.jpg .
ddl-cam.py script
import RPi.GPIO as GPIO import time import subprocess GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) # LED PIN LED_PIN = 18 GPIO.setup(LED_PIN, GPIO.OUT) # BUTTON PIN BUTTON_PIN = 17 GPIO.setup(BUTTON_PIN, GPIO.IN,pull_up_down=GPIO.PUD_UP) def led( state ): print "LED state ", state if state == True: GPIO.output(LED_PIN, GPIO.HIGH) else: GPIO.output(LED_PIN, GPIO.LOW) def takePicture(): imgName = "ddcam-" + time.strftime("%Y%m%d-%H%M%S") + ".jpg" print "Take Picture! ", imgName subprocess.call(["raspistill", "-t", "1", "-w", "800", "-h", "600", "-o", imgName]) # monitor button while True: inputValue = GPIO.input(BUTTON_PIN) if (inputValue == False): print("Button press ") led (True) takePicture() time.sleep(1); led (False) time.sleep(0.8)
Git Repository
You can find full source code and instructions on the git repository: https://github.com/smarcu/ddl-cam
Clone the repo on your raspberry pi:
git clone https://github.com/smarcu/ddl-cam.git