Turn a Raspberry Pi into a CCTV Security System

Raspberry Pi CCTVThe Raspberry Pi CCTV Solution

A few weeks ago I received the new version of the Nwazet Camera Box Bundle, re-designed to fit the B+ Raspberry Pi (and the Raspberry Pi 2) and once again designed to make a Raspberry Pi CCTV security system!

It reminded me that I had promised my dad that I would fit a Pi camera system into his porch so he could keep an eye on his beloved motor home when he was in the garden. I’d not got round to doing this as I hadn’t quite found a camera viewing solution that would be easy enough for him to use (and for me to figure out!).

Last week whilst browsing the Raspberry Pi forum I came across a camera viewing application for the Raspberry Pi called MotionPie. It almost turns your Raspberry Pi Camera Module into an IP camera, and is really (really!) easy to set up and use – perfect for old papa Average!

With my new CCTV-style case, and this seemingly simple yet brilliant camera application – a project was born!

The Nwazet camera case is perfect for our CCTV Pi solution as it has an adjustable mounting bracket, a fish-eye lens, and a nice stealty black look. It comes with all the parts you need, and even the fixings for mounting it to a wall.

Assembly

First on the list is to assemble the case. This is easy with the help of the very detailed guide on their blog. You first need to remove all the protective film on the individual panels, then then put it all together. No point in me covering that part – the instructions that come with the case are very clear.

Here are the parts:

Nwazet parts with film

The camera box parts with protective film…

Nwazet parts with film removed

…and with the film removed.

Here’s my assembled case, ready to catch bad guys and burglars:

Assembled Nwazet Camera Case

Assembled and ready for action

Installation

Installing the camera is simply a case of finding the right spot, drilling a couple of holes and screwing the mount to the wall. Obviously you need to consider things like glare, lighting, moisture, power source and all of the other ‘common sense’ factors. This case isn’t waterproof, so it needs to be installed indoors.

Note: You may want to skip to the camera software section below to set up MotionPie first so you can test where you want the camera before drilling any holes.

First mark where your camera will be mounted. Remove the mount panel and use it as a guide to mark your drill holes:

Marking camera mount position

Papa Average marks the mount position

Now grab your drill and screws/rawl plugs. The case comes with these fixings, but I left those at home so it was off to Papa Average’s workshop to grab some spares. I’m pretty sure this was his favourite part – any excuse to use his tools and supplies:

Workshop

I knew we would end up in my dad’s workshop at some point

Use the appropriate drill bit and drill the two holes for the mount where you marked earlier:

Drilling mount holes

Drill the holes where you marked the mount

Push in the Rawl plugs ready for the screws, to ensure you get a solid mount:

Fitting rawl plugs

If you don’t use Rawl plugs, it wont stay on the wall for long

Screw the mount in to the holes. Make sure you get the mount the right way round:

Fitting camera mount

Fit the mount to the wall

The case should now slide on to the mount, using the small screw at the end to secure it:

Nwazet case fitting to bracket

The case bracket slides on to the mount

There we have it, the camera box fitted and ready to plug in:

Nwazet Camera Case Fitted

Ready for crime fighting

Camera Software

This is the part that had me puzzled for a while. There’s a lot of different ways to get your camera streaming to a screen/computer, but I hadn’t had much time to look at them. The few that I did try didn’t quite offer the ‘simple’ factor that is so very important when trying to get my father to adopt new technology!

MotionPie

Then I came across MotionPie. This clever application comes as an image that you simply write to an SD card and put straight into your Pi – no code, no messing around. It feels a bit like cheating, but it does work very well and will keep papa Average happy as it’s so easy to use.

Download the Image

To install MotionPie you need a blank SD card and the MotionPie image available here (hit the big green download button). You can use a 4Gb SD card but you may want something bigger if you want to use the recording features of MotionPie.

Think of an image as an operating system, like Windows. This image is a dedicated image for MotionPie, which makes it very easy to install.

Once the file has downloaded, unzip the files to a folder and move to the next step.

Write the Image to an SD Card

Pop your SD card into your PC (using an SD card adapter if needed) and open up your favourite image writing software – I use Win32DiskImager for Windows.

Open up Win32DiskImager – you should see the drive letter for your SD card in the top right ‘device’ section. Make sure this is right before continuing.

Win32DiskImager

Win32DiskImager is an essential tool for Pi people

Next we need to tell the application which image file we want to ‘burn’ to the SD card. Click the little folder icon and navigate to the folder you extracted the MotionPie files to. Click the MotionPie.img file and then click ‘Open’:

MotionPie Image File

Your image file should be a .img file type

The file path should now be showing in the ‘Image File’ section.

Win32DiskImager load image

Double check the image and drive letter are correct

Now click on ‘Write’ to burn the image on to the SD card. A warning will show, telling you you can corrupt the device. Don’t worry about that, it’s a standard message. Click ‘Yes’ to proceed:

Note: The ‘read’ option is for doing it the other way – reading the SD card and making a file – great for backing up

Win32DiskImager Warning

This warning always shows – don’t panic!

A progress bar will give you an indication of progress – this image isn’t very large so should only take a few minutes:

Win32DiskImager progress bar

MotionPie takes just a few minutes to write to an SD card

Once complete, a message will pop up. Click ‘OK’:

Win32DiskImager complete

Don’t remove your SD card just yet!

Now we’re ready to remove the SD. Don’t forget to ‘eject’ the device safely using the icon in your taskbar, there’s a chance you could corrupt the SD card otherwise:

Eject Raspberry Pi SD Card

All storage should be removed this way

First Run

Your SD card is ready now, so push it in to your Pi and continue.

Setup

We need to connect MotionPie to a wired internet connection for the initial start up (ethernet), as we need to be able to retrieve an IP address. We can’t do any of this via a HDMI screen as MotionPie doesn’t have a video output (you’ll just see a colourful screen).

Once you’ve connected everything, push your micro-USB power supply in to the Pi and turn the plug on. We need to give it at least a few minutes to let the initial setup run, so go and grab a coffee.

IP Address

You now need to find the IP address of your MotionPie to be able to log in to it. You could log in to your router to find the IP addresses of your connected devices, but I always use the Android ‘Fing‘ app on Android as it’s quick and easy.

You also need the Pi’s serial number which will be visible when you check for the IP address.

I opened Fing, did a scan on my network, and found my MotionPie along with the serial number (the serial number is the part after ‘MP-‘):

Fing IP address

Fing is great for grabbing IP addresses

Log In

This part is easy. Using a laptop/tablet/phone connected to the same network as your MotionPie, simply type in the IP address and hit enter (the same way you would type in a web address). In the example above, I’m using 192.168.1.9.

The slick MotionPie interface should load up. You will at some point be asked for a log in, which is simply ‘admin’ and no password. For remote access such as SSH, the user name is ‘root’ and the password is the Pi’s serial number (which you can see above when we get the IP address).

I used SSH to set up my WiFi adapter so that this camera didn’t need to rely on a wired ethernet connection.

Interface

Here’s what MotionPie looks like on my Android phone – it was a bit of a dark day.

MotionPie Interface

The MotionPie mobile web interface

The icon top left takes you to the setting menu, where you can adjust all manner of things such as framerate, resolution, brightness, contrast, rotation, storage locations and loads more. I need to have a play with these settings over the next week or so.

You then have icons on the right which take you to full screen mode, camera and video capture and more options. To use the same interface on a PC or tablet, it’s the same process. Simply enter the IP address and away you go.

There currently isn’t a shutdown command on the interface but I have been told that it may be coming soon. You can run more than one Pi camera on MotionPie as well, almost creating a full security interface:

MotionPie Multiple Feeds

3 Pis running on MotionPie (image from MotionPie site)

Summary

I’m really happy with the outcome of this project, and more importantly, so is Papa Average!

The Nwazet case and mount is solid, looks the part and works very well as a CCTV housing. The fish-eye lens isn’t the greatest quality, looking a bit fuzzy at the edges, so we just removed this part. I’m going to look into drilling some holes in the top panel and wiring some ‘deterrent’ LEDs to make it a bit more visible.

The MotionPie application is very easy to set up compared to fiddling with code and ‘Motion’ yourself, although playback can be choppy if you set the resolution too high. It’s a bit of a lazy man’s solution, but I’d rather concentrate my coding on some of the other projects I have on the go.

I had this case and MotionPie on display at the recent Cambridge Raspberry Jam, which provided hours of entertainment for children running in front of the lens!

MotionPie at Cambridge Raspberry Jam

Who can resist a bit of live selfie action?

Until next time…stay safe Pi people!

**Update** – Check out my next Pi CCTV project here, using a Power over Ethernet HAT.

45 Comments on "Turn a Raspberry Pi into a CCTV Security System"

  1. The Raspberry Pi Revolution has become, rise of the Open Source Warrior!-Michael E. McKinzy, Sr.-10-27-2014

  2. Worked great for me, thanks Richard for this post. One problem I'm hoping you can help me with. The aspect ration is in portrait instead of the desired landscape. Are you able to shed any light on how this can be change or why this is occurring?

    • Hi Bec. I think we may have already covered this on Twitter, but my solution was to turn the Pi – simple! There’s probably a more sophisticated way of doing it…but this is ‘a’ way!

  3. Hi, do you have a tutorial for the wifi setting?

  4. cant get it to work on raspberry pi 2

    • I’m upgrading the version at my dad’s house in the next few weeks, so I will have a go then and see if it works for me. A lot of stuff isn’t working on the Pi 2 straight away, hopefully this will be resolved by the developer.

  5. Can anyone help me I'm curious is it possible to view stream from Internet , say from desk at work or mobile device. Haven't seen this addressed anywhere.

    • Yes you can, that would involve port forwarding and a DNS service. That’s a whole article in itself – but is well covered across the internet. Look for articles around “view an IP camera outside of the home”.

  6. Can you add Raspberry Pi NoIR Camera Module support please.

    Rj i think you can as there is a streaming URL is you can make a static IP on your router and then make it available for outbound connections on the internet.

  7. I want to set this up on a Pi A+ which doesn't have an Ethernet port. Is there any way I could do the IP address part over wifi? Ultimately I want to set up this Pi as a doggycam to monitor my dog over the Web while I am out of the house.

  8. OK so set up on a B+ to test MotionPie and it works great. I would like to get it working wirelessly but cannot get SSH to connect. Any hints?

  9. Then I got SSH to connect from my Nexus tablet and was really confused! So many command choices. Can you tell me where I can find out how to set up my wifi connection to MotionPie via bash? Thanks ☺

    • Hi Barry. The latest version makes WiFi setup very easy via the settings interface, not sure there is any guidance available on using Bash.

  10. BTW the software version I got has power controls to allow shut down of the camera and much more besides. They are included under the advanced options.

  11. The motion pi image does not allow me to save the wifi interface file from command line. It nano editor say's error when saving, read only file. How do we undo the read only option for Motion Pi ?

  12. Sure would like to know how to setup wifi with motion pi ? Seem's it's restrickted to read only. Can't set up wifi from command line.

  13. Re-loaded latest update version and now works great. Also wireless working well.
    Thanks for great project.

  14. Just explored Motionpie via ssh lots of files to investigate. As I want to set up a webcam using Picam I think probably ditching Motionpie and running Motion under Raspbian a better option. More opportunity to customise

  15. I dont mind sending you my pi2 to take a look at

  16. Richard Bernfort | 22/07/2015 at 19:37 | Reply

    I can´t log in as root to the ssh-service. what´s the password?

  17. Have anyone succeeded in connecting a MotionPie-box with 3G/4G?
    last time i checked it wasnt built upon debian (but maybe there’s another pkg-manager. Iknow that ppp and sakis3g is needed for connectivity.

    • Sorry Joel I haven’t tinkered with 3G/4G on the Pi (or any other board) yet. Definitely try the RPi forums though, lots of help available there.

  18. im having issues with the command shell sudo command? it says command not found when i try to use it in ssh.. any ideas?

  19. Amazing stuff 🙂 I was going to mess around with writing some code of my own, but it looks like MotionPie has everything covered! Quick question — have you tried using a RaspberryPi with 2 cameras? I am wondering if I should order the RaspberryPi 2 Model-B with the higher CPU and RAM specs. Thanks!

    • Hi Krishna

      You can’t directly connect 2 cameras (that other slot if for the new Pi screen) but you can use an add on board that will let you use more.

      However, I believe the Pi is still only able to view/read from one camera at a time, so these add on boards require you to jump from one camera module to an other – not view them all at the same time.

  20. How do we place this device outdoors for long periods of time? Is there a battery pack that can last for a long time?

    • You’d have to make a waterproof enclosure and either run an external power line, get a decent solar solution or use a big battery pack. PowerBanks can last a day+ these days.

  21. Thanks for the tutorial!

    Don’t drill through the brick. When you remove the device how are you going to repair it? You’ll never match the color and it will always be noticed.

    Always drill through the mortar – easy to repair and hide the holes previously created.

  22. I used the PI cam, motion eye, and streamed the feed to a Synology NAS running surveillance station, worked a treat. It also emailed stills to a Gmail account once i’d got to grips with motionEye.
    One thing that isn’t mentioned, and i can’t see from the images, is the power solution. Being outside, the case appears to leave power and USB positions exposed, are there any better cases you’ve found?

    • We used this on the inside for that exact reason. I haven’t come across many ‘ready’ solutions for Pi cameras being mounted outside CCTV style. There was a nature watching product released recently, but that’s not quite right for CCTV usage.

  23. very cool project – your shelter is nice.
    If you want live video streaming with your webcam too, you could use the open source software datarei/resteramer. it works perfekt with raspicam and the rest together. http://datarhei.github.io/restreamer

  24. In door ok, outside … no ip66…

  25. yea, nice. didnt read the article or any of the comments.
    lets see, i can take your usb wifi dongle and i can inject stuff into your rpi because your usb ports are exposed.

    • This is why you should have to pass a test to use the internet. How can you possibly comment without reading?

      This is inside a porch (you’d know that if you read it before sharing your ultimate wisdom…). To get access to the porch, you’d need to show your pretty face to the camera. By the time you’re even that close, it’s already taken 10 photos and stored them on my Google Drive. So criminals can feel free to steal the Pi and stick whatever they like into the USB ports, the police will collect them later when picking them up for jail.

  26. Any info on installing other software over SSH? A problem myself and others are having that nobody has seemed to touch in forums I’ve seen, is that you can’t install software like the no-ip duc because there’s no make compiler, and you can’t download the make compiler because apt-get doesn’t work. I’d really like to get the no-ip duc running on the pi because the other computers on this network are unreliable and I don’t want to lose access to the pi and have to spend a week trying to get access to one of these computers again to fix it.

  27. Azhar Mehmood | 23/11/2016 at 02:12 | Reply

    I need this Raspberry pi Case,

Leave a comment

Your email address will not be published.


*