Introduction: PiCam IP Security Camera

RpiCam (raspberry pi zero IP camera)

This guide will show the steps to setup a fast IP camera with the raspberry pi zero. The web interface with live streaming and motion detection. We will set the trigger to send snapshots automatically to Android or iPhone via push notifications using the free telegram API

Supplies

Parts List:

  • Raspberry Pi Zero W $10
  • Micro SD Card (8GB to 32GB) $ 5
  • 1A Wall Power Supply $ 2
  • Rpi Camera Module with ribbon cable $24
  • M2 x 8mm screws (2x)
  • M2 x 15mm screws (4x)

Total cost of parts: $41

Notes:

- I used camera v. 1.3 but v.2 or NoIR variants should work also equally well. - 3D printed case was made with black Hatchbox ABS filament. STL here: https://www.thingiverse.com/thing:3661961 - The cost of machine screws is so little i chose not to include prices on the parts list. I already had a box of various sizes so i didn't need to purchase these for the project.

Step 1: Software Setup

Setup:

  • write latest rasbian stretch image to microSD card with etcher
  • add wpa_supplicant.conf and ssh file to boot partition for headless setup
  • plug in picam next to router
  • connect over ssh
  • in raspi-config, set locale, timezone, and most importantly set region for network (controls power and available channels)
  • in raspi-config enable camera in interfaces.
  • in raspi-config expand filesystem
  • reboot pi , reconnect over ssh
  • install rpi-cam-web-interface
    > git clone https://github.com/silvanmelchior/RPi_Cam_Web_Int...
    > cd RPi_Cam_Web_Interface
    > ./install.sh
  • in rpi cam installer replace default webserver option "apache" with "nginx" I think other options are available as well, but i tested nginx on the pi zero w and it was quite fast and responsive - wait for installer to download and install packages
  • reboot (mabey not needed but why not)
  • on pc/laptop/phone open webbrowser and navigate to ip address of the pi zero
  • if everything went smoothly , should display a the rpicam interface with live stream from the camera
  • click the button "motion detection start" to enable motion detection events
  • click the "Edit schedule settings" button
  • replace the motion start command to trigger photo capture. (replace "ca 1" with "im")
  • apply changes and navigate back to the main interface page.
  • click the "Edit motion settings" button
  • replace the default value for event_gap (replace "3" with "60")
  • apply changes and navigate back to the main interface page.
  • expand system section. set the macro:end_image command (replace "&end_img.sh" with "&motion_detect.sh" and press ok button
  • back in ssh window, navigate to macros folder and create motion_detect.sh
    > cd /var/www/html/macros
    > sudo nano motion_detect.sh
  • enter the following script for motion_detect.sh (you will need to sign up for telegram and get an API key, get a chat id)
	#!/bin/bash
	CHATID="your_telegram_chat_id"
	KEY="your_telegram_api_key"
	PHOTOURL="https://api.telegram.org/bot$KEY/sendPhoto"
	TEXT="motion detected"
	curl -s -X POST "https://api.telegram.org/bot"$KEY"/sendPhoto" -F chat_id=$CHATID -F photo="@$1"

  • press Ctrl+X, then Y to save changes. - make script executable
    > sudo chmod +x /var/www/html/macros/motion_detect.sh
  • DONE! Now any motion in the camera should trigger motion_detect.sh which will send a snapshot from the camera to your android or iOS device via push notification

Resources: