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

About: come visit me!


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.



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:
  • 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=""></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/

with CTRL-W find the line with this argument:


and change it to:


save and exit

try to send an email with the command line:

$ sendEmail -f -t -u "OBJECT" -m "MESSAGE TEXT" -xu -xp YOURPASSWORD -o tls=yes -s

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

hostname=raspberrypi # you can use one of two accounts created to send email

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 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 -t -u "Motion detected!" -m "http://"`curl -s|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'`":8080" -xu -xp YOURGMAILPSSWD -o tls=yes -s -a %f (OBSOLETE)

on_picture_save mpack -s "MOTION DETECTED!" %f

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

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

on_movie_start sleep 10 && mpack -s "http://"`curl`":8080" %f

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


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

$ nano

add this script:

CURRENT_IP=$(curl -s | sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
if [ -f $IPFILE ]; then
if [ "$CURRENT_IP" != "$KNOWN_IP" ]; then
sendEmail -f -t -u "your IP is changed!" -m $CURRENT_IP -xu -xp YOURGMAILPASSWORD -o tls=yes -s

save and exit

$ chmod 700

if you want to check every five minutes:

$ sudo nano /etc/crontab
*/5 * * * * pi bash /home/pi/

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)

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

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

then add:

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/ & 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


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:


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:


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


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