Intruder detection with Raspberry-Pi

ole Examples 9 Comments


This demo is featuring use of Raspberry-Pi as a gateway in an alarm system. We connected a camera and accelerometer to the Pi and used Reactive Blocks to make a simple intruder detection application.

Every time vibration is detected, the camera takes a picture and checks if there is a change in the image. If a change is detected, it sends an SMS and an email with an attached image of the intruder.



To make this demo application, we used the following:

  • Raspberry-Pi with Raspbian OS
  • A standard USB camera
  • An accelerometer, we used XLoBorg
  • Reactive Blocks development platform 


You can see the XLoBorg accelerometer connected to the GPIO I2C bus of the R-Pi in the lower right corner.  Refer to these documents for specification.

How we built it

The Raspbian release has Oracle Java preinstalled, so running Reactive Block applications on Raspbian is very easy. At the top level we ended up with this system:

Screen Shot 2015-04-17 at 12.13.55

The top system consists of 8 building blocks; 7 standard blocks and 1 custom made block:

Standard Blocks from the IoT Library

  • Grabber, grabs images from the USB camera
  • Image to file, writes buffered image object to file
  • Motion detection, compares mages to detect motion using an algorithm
  • Limiter, to avoid too many mails/SMS when intruders are detected.
  • Send SMS, sends SMS through the Clickatell service
  • Send Email, sends email via an SMTP server
  • Read Java Properties file, reads a Java property file to setup the SMS and Email properties.

The Grabber block uses the Open Intelligent Multimedia Analysis for Java, OpenIMAJ. When the block is initialized, a separate thread is started to read data from the camera. The thread listens to a command queue. When the block receives a command via the grab pin it will take one picture and deliver it on the image pin.

The Motion detection block also uses OpenIMAJ. A method within this block compares two images and will flag changes in image when motion is detected. The method is very CPU intensive and has to be run in a separate thread. When an image is detected it is signaled on the motionDetected pin.

So lets look closer at the Vibration sensor block that is custom made for this application. It interfaces the accelerometer via the I2 bus on the Raspberry Pi. If you click on the block you can see the detail inside:

Screen Shot 2015-04-17 at 12.20.55

You will see that it consists of all standard building blocks from our IoT libraries:

  • RPi 12C, interfaces the Raspberry Pi I2C Bus using Pi4J library
  • Iterator, makes each element of a list a separate event to iterate
  • Easy Periodic Timer, timer with start at accurate timestamps
  • Timeout, monitors if the arrival or non-arrival of an event happens within a certain time.

The RPi 12C block, is used to initialize and read data from the accelerometer. It is polled at 10Hz, but vibration has to be continuous for more than 1 second to be detected. The isVibration() method will return true and start a timeout if acceleration of all axes combined is above 1.05 g or below 0.95 g. If detection continues for more than one second, the vibrationDetection pin is fired. The Timeout is handed as a filter to avoid overloading the Pi with too much heavy image processing.

Notification is done with SMS and email.  The file with image is attached to the email, and could be attached to the SMS if the service supported that feature.

If you want to make a detection system like this one you can get access to the building blocks used in this project from team reference systems.

You can of course experiment and use a motion detection sensor instead of an accelerometer to detect changes. We have building blocks and example systems for that as well. Download Reactive Blocks to learn more and start developing your own applications with Reactive Blocks. Please feel free to contact me if you are interested.




Share on FacebookTweet about this on TwitterShare on LinkedInGoogle+Email to someone