A home intrusion detection setup (sort of)

Mutt Ain't No Shaggy Dog

Mutt is a classic in Unix-like operating systems and probably offers the easiest way to send an email with attachments (your photo) from the command line.

To install mutt, enter:

sudo apt-get install mutt mutt-patched

Suppose you want to send the picture to your Gmail account: You create a configuration file in the /home/pi directory called .muttrc containing the following,

set smtp_url="smtp://yourgmailusername@smtp.gmail.com:587/"
set smtp_pass="yourgmailpassword"

where yourgmailusername is the username you use to access your account, and yourgmailpassword is your password. As you won't be using mutt for anything but sending, you don't need any other parameter.

Now you can send a picture by typing the following at the command line:

echo " " | mutt youraddress@gmail.com -s "Test" -a /path/to/picture.png

The echo command provides the text body (otherwise, mutt will open a text editor for you to type in, and you don't want that) which is piped over to mutt proper. Mutt takes as a parameter the destination address (youraddress@gmail.com). You can give your message a subject with the -s option, and -a creates an attachment out of a file on your disk.

After you hit Enter, the email is sent on its way.

Bearing in mind all of the above, your surveillance_mail.sh will look something like the following:

echo " " | mutt $1 -s $2 -a $3

If you look at the content of the incrontab file described above, you'll see that

  • $1 contains your email address.
  • $2 sets the subject to Intruders!!!
  • $3 is the path and name of the file you want to send.


You're done. All you have to do is run the Python script in Listing 4, and your surveillance system will start, first scanning, and later taking pictures of anything it considers abnormal. Incron and mutt will send pictures of miscreants automatically in the background to your inbox (Figure 8).

Figure 8: An Ubuntu User lowlife trying to steal your Raspberry Pi Geek magazines gets caught red-handed.

Although this project is more a thought experiment than an effective safety system (there are much better ways to create a surveillance system), it serves as an example of what a maker can achieve with stuff lying around the house.

If nothing else, it will help you understand how several technologies, including hardware that is affected by or affects the real world, can be combined to create a complex project.


  1. Adafruit 16 channel servo controller: https://www.adafruit.com/products/815
  2. Article code: ftp://ftp.raspberry-pi-geek.com/pub/listings/raspberry-pi-geek.com/04
  3. The Motion program: http://www.lavrsen.dk/foswiki/bin/view/Motion/WebHome
  4. "Analog Pi" by Paul Brown, Raspberry Pi GEEK, Issue 3, pg. 56.
  5. "Controlled Files" by Paul Brown, Linux Magazine, Issue 158, pg. 42, http://www.linux-magazine.com/Issues/2014/158/Monitoring-with-incron

Buy this article as PDF

Express-Checkout as PDF

Pages: 8

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content