My image

Basic Video Surveillance with the Raspberry Pi

Last Update: Sat, Aug 12 2023

Sometimes, you would like to monitor your home from another angle that what the Raspberry Pi camera can achieve. In order to do that, you will need to use an external USB camera.

In this project we are going to see how to connect an external USB camera to your Raspberry Pi, and make a simple video surveillance system from it, allowing you to see in live what is seen by the camera.

To do that, we will first connect a USB camera to your Pi, and then test if it works correctly. After that, we will configure the Raspberry Pi so it streams the video continuously on a web page.

Hardware & Software Requirements

Apart from the Raspberry Pi itself, the most important component of this chapter will be the USB camera. You need a camera that is compatible with the UVC standard, which is the case for most of the cameras you will find today. I used a Logitech C720 HD camera for this project.

This is the list of the components you will need for this project:

Hardware Configuration

The hardware configuration is really simple: you just need to plug the camera in your Pi, using one of the USB port on the Raspberry Pi.

This is a close-up of the final result:


Testing the Camera

We are now going to test the camera. Again this is really easy to do. Just type this in a terminal:

sudo apt-get install fswebcam

Then, take a picture with:

fswebcam -r 1280×720 image.jpg

The camera LED should turn on, which means it is active and currently taking a picture. Then, simply check the image that was created by the command.

Local Video Streaming

We will now stream video locally using the mjpg-streamer module. This module is really great for video streaming, as it will create a nice web page from which you can access the video stream.

However, the module is not available in the official Raspberry Pi Linux repository. But luckily for us, a developer made a version available for the Raspberry Pi, and we are going to install it now. You can find all the details at:

https://github.com/jacksonliam/mjpg-streamer

First type the following command in a terminal from your Pi:

git clone https://github.com/jacksonliam/mjpg-streamer

Then type this command to install required modules:

sudo apt-get install cmake libjpeg62-dev

After that, type this command to build the mjpg-streamer package:

sudo make clean all

And then type this command:

export LD_LIBRARY_PATH=.

And finally type this command to start the streaming:

./mjpg_streamer -i “./input_uvc.so” -o “./output_http.so -w ./www”

You will see that a lot of text will be printed inside the terminal, which means the streaming is active. Then, go to this URL from a computer:

http://rpi_ip_address:8080

This is the web page you should get:


Simply go on ‘Stream’ in the menu, and you should see live streaming from the USB camera connected to your Pi!

If you just want to see the stream, go to:

http://rpi_ip_address:8080/javascript_simple.html


How to Go Further

In this project, we built a basic surveillance camera using the Raspberry Pi camera module and some open-source software.

You can now of course add more Raspberry Pi modules in the game, to make a whole surveillance system! From the mjpg-streamer module it is easy to get a piece of code that can be embedded in another web page.

From that, it is easy to build a page where you have the pictures from all your camera modules, and monitor them from a single interface!

Want to learn more about how to use the Raspberry Pi?

I wrote a free step-by-step tutorial to show you how to build a simple thermostat with the Raspberry Pi. It will show you everything you need to build this simple project & also teach you how to use the Raspberry Pi at the same time. To get this free guide, simply click on the button below: