Introduction: Old PC Accessories + Raspberry PI = DoorCam & Surveillance Kit **updated 2016**

About: come visit me!

NEW VERSION

https://www.instructables.com/id/New-Door-Cam/

This project has been made with old tech accessories that i don't use and was in a cardboard box stored in my basement flat.

Have you got an old webcam, a couple of PC audio speakers, a composite monitor ? If yes, you have to perform following instructions to create a complete surveillance kit, IOS and Android compatible.

Excluded cost of a Raspberry Pi, for this project i have spent only $2 to buy a relay. After assembled it, you'll have:

  • Door cam with automatic display switching on at motion detection;
  • Cloud photo and video storing;
  • IP camera stream on your mobile phone or PC browser;
  • Acoustic alerts activated by motion detection;
  • Automatic photo and video email sending.

TESTED ON:

LINUX RASPBERRYPI 3.18.7+ #755

Step 1: You Will Need

  • Raspberry PI B (this project is based on B+ model)
  • 5V Raspberry PI power supply
  • A couple of PC speakers
  • TV/Monitor with composite input and its power supply
  • 3.5mm jack to RCA A/V cable
  • Compatible webcam (see at: http://elinux.org/RPi_USB_Webcams)
  • Three female/female jumpers
  • Relay 1 channel 5V PIC ARM AVR DSP

To make something easy, my webcam is conencted directly to Raspberry PI usb port. To do this i have simply drilled the wall. Everything is connected directly to the LAN network to contain costs.

Step 2: How It Works

My first need was to check who is outside my home door. To do this Raspberry PI has been programmed as follow:

at a motion detection in webcam area

  • turn on monitor for 40"
  • send email with snapshot & public IP URL
  • send email with timelapse video & public IP URL(*)
  • sound alert

obviously, snapshot and video are chronological order stored in your gmail messages.

when my public IP changes, system sends an email with updated IP.

(*) on IOS mobile devices video file can be played with Ace Player app.

Step 3: Initial Settings & Packages Installation

Initial settings

Create two GMAIL accounts, one for store jpeg files and one for mjpeg files.

On your RPI enable access directly to graphical interface:

$ sudo raspi-config

choose option:

Desktop Log in as user 'pi' at the graphical desktop

Then reboot.

Install sendEmail (OBSOLETE)

Download sendEmail tar file:

$ wget <a href="http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz"> http://caspian.dotconf.net/menu/Software/SendEmai...</a>

extract it:

$ tar -zxvf sendEmail-v1.56.tar.gz

copy to correct path:

$ sudo cp -a sendEmail-v1.56/sendEmail /usr/local/bin

make it executable

$ chmod +x /usr/local/bin/sendEmail

Install TLS support for Gmail (OBSOLETE)

$ sudo apt-get install libnet-ssleay-perl libio-socket-ssl-perl

after installing, change it as follow:

$ sudo nano /usr/share/perl5/IO/Socket/SSL.pm

with CTRL-W find the line with this argument:

m{^(!?)(?:(SSL(?:v2|v3|v23|v2/3))|(TLSv1[12]?))$}i

and change it to:

m{^(!?)(?:(SSL(?:v2|v3|v23|v2/3))|(TLSv1[12]?))}i

save and exit

try to send an email with the command line:

$ sendEmail -f YOUREMAIL1@gmail.com -t YOUREMAIL2@gmail.com -u "OBJECT" -m "MESSAGE TEXT" -xu YOUREMAIL1@gmail.com -xp YOURPASSWORD -o tls=yes -s smtp.gmail.com:587

Install SSMTP

$ sudo apt-get update<strong><br></strong>
$ sudo apt-get install ssmtp<br>
$ sudo apt-get install mailutils

now edit SSMTP config file

$ sudo nano /etc/ssmtp/ssmtp.conf

add or modify extistings lines

root=postmaster
mailhub=smtp.gmail.com:587
hostname=raspberrypi
AuthUser=YOUREMAIL1@gmail.com # you can use one of two accounts created to send email
AuthPass=TheGmailPassword
FromLineOverride=YES
UseSTARTTLS=YES

Save and exit

$ sudo apt-get install mpack



Install Chromium Browser

$ sudo apt-get install chromium-browser 

set now Chromium browser autostart kiosk mode:

$ sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

(if you haven't NOOBS : sudo nano /etc/xdg/lxsession/LXDE/autostart)

#@lxpanel --profile LXDE
#@pcmanfm --desktop --profile LXDE
#@xscreensaver -no-splash
# auto run the browser
@xset s off@xset -dpms
@xset s noblank
@chromium --kiosk --enable-kiosk-mode --enabled --touch-events --touch-events-ui --disable-ipv6 --allow-file-access-from-files --disable-java --disable-restore-session-state --disable-sync --disable-translate --disk-cache-size=1 --media-cache-size=1 http://localhost:YOURWEBCAMPORT


now reboot

Install MP3 PLAYER

$ sudo apt-get install mpg123

Install Motion

$ sudo apt-get install motion

modify configuration file:

$ sudo nano /etc/motion/motion.conf

Basically, i've changed these options:

#start as
daemon
daemon on
# Rotate image
rotate 90 (my webcam is 270° rotated)
# Image width
width 640 (check your webcam resolution)
# Image height
height 480 (check your webcam resolution)
# Maximum number of frames
framerate 2
# Threshold
threshold 15000
# Picture frames must contain motion
minimum_motion_frames 2
# Specifies the number of pre-captured
pre_capture 5
# Codec to used by ffmpeg for the video compression
ffmpeg_video_codec mpeg4
# The mini-http server listens
webcam_port 8080 (selected your preferred port)
# TCP/IP port for the http server to listen on
control_port 8081 (select different port by webcam port)
# Restrict webcam connections to localhost only
webcam_localhost off
# Command to be executed when an event starts.
on_event_start mpg123 -m --gain 70 /home/pi/testsound.mp3 ;
# Command to be executed when a picture (.ppm|.jpg) is saved (default: none)
on_picture_save sendEmail -f YOUREMAIL1@gmail.com -t YOUREMAIL1@gmail.com -u "Motion detected!" -m "http://"`curl -s checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'`":8080" -xu YOUREMAIL1@gmail.com -xp YOURGMAILPSSWD -o tls=yes -s smtp.gmail.com:587 -a %f (OBSOLETE)

on_picture_save mpack -s "MOTION DETECTED!" %f YOUREMAIL1@gmail.com

# Command to be executed when a movie file (.mpg|.avi) is created.

on_movie_start sendEmail -f YOUREMAIL2@gmail.com -t YOUREMAIL2@gmail.com -u "Motion timelapse" -m "http://"`curl -s checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'`":8080" -xu YOUREMAIL2@gmail.com -xp YOURGMAILPSSWD -o tls=yes -s smtp.gmail.com:587 -a %f (OBSOLETE)

on_movie_start sleep 10 && mpack -s "http://"`curl icanhazip.com`":8080" %f YOUREMAIL2@gmail.com

Final settings

add following lines at rc.local file:

$ sudo nano /etc/rc.local

before "exit" add:

sudo mkdir /var/run/motion
sudo chmod a+rwxt /var/run/motion
sudo motion
sleep 60

save and exit

OBSOLETE

create now a script that check if public IP has been changed (OBSOLETE)

$ nano ipchangecheck.sh

add this script:

#!/bin/bash
IPFILE=~/ipaddress
CURRENT_IP=$(curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
if [ -f $IPFILE ]; then
KNOWN_IP=$(cat $IPFILE)
else
KNOWN_IP=
fi
if [ "$CURRENT_IP" != "$KNOWN_IP" ]; then
echo $CURRENT_IP > $IPFILE
sendEmail -f YOUREMAIL1@gmail.com -t YOUREMAIL1@gmail.com -u "your IP is changed!" -m $CURRENT_IP -xu YOUREMAIL1@gmail.com -xp YOURGMAILPASSWORD -o tls=yes -s smtp.gmail.com

save and exit

$ chmod 700 ipchangecheck.sh

if you want to check every five minutes:

$ sudo nano /etc/crontab
*/5 * * * * pi bash /home/pi/ipchangecheck.sh

save and exit

Step 4: Composite TV/Monitor

Change video output configuration file as follow( using NOOBS Configuration):

$ sudo nano /boot/config.txt
# NOOBS Auto-generated Settings: (i'm using PAL composite monitor 270° rotated)
#hdmi_force_hotplug=1
#config_hdmi_boost=4
sdtv_mode=2
sdtv_aspect=2
overscan_left=24
overscan_right=24
overscan_top=16
overscan_bottom=40
disable_overscan=0
display_rotate=1

save, exit and reboot.

Step 5: Relay

To automate your composite monitor startup, you have to check if your display can do this option.

Turn it on, unplugs the power, re-plugs and then check if it turn automatically on. If yes, you can proceed with this step.

Connect display as show on image.

Relay to Raspberry PI

VCC to PIN 1 3.3volts
IN1 to PIN 15 GPIO 22
GND to PIN 39 GND

12V DC to Relay

cut your positive cable and connect one end at COM relay port and the other to NC (normally closed) relay port

now in your terminal:

$ sudo nano /etc/rc.local

add these lines before "exit 0"

sudo echo "22" > /sys/class/gpio/export
sudo echo "out" > /sys/class/gpio/gpio22/direction
sudo echo "1" > /sys/class/gpio/gpio22/value

save & exit

create following script in your home directory:

$ nano monitor.sh

then add:

#!/bin/bash
sudo echo "0" > /sys/class/gpio/gpio22/value
sleep 40
sudo echo "1" > /sys/class/gpio/gpio22/value

save and exit

with this script, after modified Motion configuration file as below, when a motion detection event starts, your display turn on for 40 seconds. Then power off. Change "sleep" value at your needs.

Modify Motion configuration file for this step:

$  sudo nano /etc/motion/motion.conf

at the line:

# Command to be executed when an event starts.
on_event_start mpg123 -m --gain 30 /home/pi/testsound.mp3 ;

change as follow:

on_event_start bash /home/pi/monitor.sh & mpg123 -m --gain 70 /home/pi/testsound.mp3 ;

change "--gain" value to increase volume.

save and exit

Step 6: Audio

A word about audio. I've connected two PC audio speakers to RPi. My idea was to create two different situations:

1. when we are at home

2. when we are out for holiday

in the first case i use a Geiger counter audio file that alert me if there is some moving detection outside the home door. In the second case i use a Neapolitan mastiff bark sound alert, with increased volume, to deter "unwanted people".

Save your file inside your home directory under the name

testsound.mp3

Step 7: Door Cam on Browser

To view your webcam from a PC inside your domestic net, you have to use Firefox or Safari browsers just typing the URL:

http://RASPBERRYPI_IP_ADDRESS:YOURWEBCAMPORT

It seems work on Ipad too. Open Safari with above mentioned URL and, if image freeze, try reloading the page.

If you want to view from outside your domestic net, you need to open the relating port on your modem. I cannot explain how can do because each modem brand has different parameters to set. When you have open modem port, from outside your domestic net, you can simply type the URL in Firefox or Safari browsers:

http://YOUR_PUBLIC_IP:YOURWEBCAMPORT

My TP-Link modem support dinamic DNS service NOIP (FREE) and, once you are registered to that, you'll be able to access to your webcam from outside your domestic net, just typing domain name given by NOIP always adding

http://YOURNOIPDOMAIN:YOURWEBCAMPORT

Step 8: Door Cam on Your Mobile Phone

Opening modem port is useful to view your webcam over your domestic net.

For this feature, on IOS, i can use two different apps available on APP Store for free.

The fisrt one that i prefer is Cu4GE and, in the first image, you find parameter settings.

The second Monitor Bee. In the second image you can see parameters.

On Android OS exists an easy app named Mjpeviewer.

Free and very easy, only URL:PORT adding needed.

Step 9: Final Considerations

Following this project step by step, you can see that it's very easy.

Thank you in advance and sorry for my poor English.

Pi/e Day Contest

Participated in the
Pi/e Day Contest