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.

DIY Photo Camera using Raspberry Pi

DIY Photo Camera using Raspberry Pi

Required Materials

Hardware setup

DIY Photo Camera using Raspberry Pi

DIY Photo Camera using Raspberry Pi

Raspberry Pi Pinout

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

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

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

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *