IP Camera Using the Raspberry Pi Zero (Home Surveillance Part 1)

Introduction: IP Camera Using the Raspberry Pi Zero (Home Surveillance Part 1)

About: #BnBe is a platform to help teach electronics no matter what the age or skill level. We’re currently designing a wide range of products from beginner level kits to industry-standard microcontroller platforms.

This is the first post in a new mini-series, where we build a home surveillance system, mainly using Raspberry Pis. In this post, we use a Raspberry PI zero and create an IP camera that streams video over RTSP. The output video is of a much higher quality compared to the previous example and even the esp32-cam board. By default, it is set to output 1080 video at 30fps with a bit rate of 2Mbps, but all of these can be updated to suit your needs.

The video above guides you through the entire process and I would recommend watching that first, to get an overview of how it all comes together.

Step 1: Gather the Components

We will be using a Raspberry Pi zero here, mainly becuase it is compact and cheaper compared to the other variants. However, this will also work with any other Raspberry Pi variant.

Here are the main components that we would need:

  • Raspberry Pi board
  • microSD card
  • Camera module
  • Suitable camera cable
  • Suitable power source
  • USB card reader to access the card and it's contents

Step 2: Load the Operating System

The first thing we need to do is load an operating system on the microSD card. To do this, head over to the downloads section of the Raspberry Pi website and download the Raspbian Lite OS.


Then, download and install Etcher, if you do not already have this. Select the image you downloaded, make sure you have selected the microSD card and then click the Flash button. Wait for it to complete.

We then need to enable WiFi networking by creating the wpa_supplicant.conf file in the boot drive. You can also download the following template and update it with your details - country code, network name and password. It is recommended to use a text editor like notepad++ or sublime to do this.


The last thing left to do is enable SSH. This allows us to remotely access and control the Raspberry Pi, over a network. Doing this is simple. Simply use one of the text editors mentioned above to create a new file, and then save it to the bootdrive with the name "ssh". You do not need to add any extension to the file.

We are now ready to power ON the board, so insert the microSD card into the board and connect the camera using the cable. Be gentle with the connector tabs as they are a bit delicate. Once done, insert a microUSB cable and power ON the board. It will take about a minute to boot completely, so do give it some time.

In order to communicate with the board using ssh, we need the IP address of the board. Download and install AngryIP scanner as this will help us obtain it. You can even download the legacy version on windows, which does not need any installation. Once done, enter the IP range as shown in the image and hit the start button. Wait for it to detect the board and then note it's IP address. The IP address of my board is

Step 3: SSH Into & Prepare the Operating System

Open up a command prompt window by typing in "cmd' in the start menu. You can use the terminal if you are on Mac OS. Then, type in "ssh pi@" and hit enter. Remember to use the IP address corresponding to your board. It will ask you if you want to authenticate/store the key. Type in yes and hit the enter key. It will then ask you for a password, so enter "raspberry" which is the default password, and then hit enter again. This will log you into the board.

Before we can work on the actual script, we need to enable the camera module. This can be done by running the "sudo raspi-config" command. Navigate to the "Interfacing Options", then "Camera" and hit enter. Select "yes" when it asks you if you want to enable the camera and then navigate to the "Finish" option. It will ask you if you want to reboot. Select "yes" and then wait for the board to reboot. Give the board a minute and then ssh back into it like before.

Next, it is a good idea to update the OS so type in "sudo apt update" and hit enter. Then type in sudo apt full-upgrade" and hit enter. Follow the onscreen prompt to install the updates. This may take a while depending on your internet connection, so do have some patience.

Finally, we need to install vlc and this can be done by running the "sudo apt-get install vlc" command. Follow any prompts and wait for it to complete. You can now move on to creating the script.

Step 4: Create & Test the Script

In order to create the script, run the following command "sudo nano rtsp-stream.sh". This will open up a text editor and you can then type in the contents of the script which is shown below:


raspivid -o - -t 0 -rot 180 -w 1920 -h 1080 -fps 30 -b 2000000 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/stream}' :demux=h264

We are simply creating a video stream using the raspivid command and we then make this available over the network using VLC. You can update the resolution, frame rate and bitrate to suit your needs. The following link will take you to the relevant page which contains some documentation.


Once this is done, press the "CTRL+X" keys and it will prompt you to save the File. Type "y" and hit enter to save. We then need to make this script executable and that can be done by running the "chmod +x rtsp-stream.sh" command. To execute the script, simply type in "./rtsp-stream.sh" and hit enter. This will enable the stream.

In order to view the stream, you will have to download and use VLC. Once done, select the "Open Network" option from the File menu and enter the following URL:


Again, be sure to use the IP address of your board. Then, hit the open button and you should be able to view the stream.

If you want to check the resource usage, then you can open up a new
command prompt window, SSH into the board and then run the "top" command. Please watch the video for further details.

Step 5: Automate the Stream

Now that we know that the stream works, we simply need to automate it such that it runs on startup. Doing this is simple, simply run the following command "sudo nano /etc/systemd/system/rtsp-stream.service". This will open up the text editor and you will have to type in the following contents:


Description=auto start stream










Once done, save the file by pressing the "CTRL+X" keys, then Y, then Enter. We then need to enable the service by running the following command "sudo systemctl enable rtsp-stream.service". That's all we need to do. The next time the board boots, it will automatically execute the service which will call the script. You can also manually control the service using the following commands:

To Start: "sudo systemctl start rtsp-stream.service"

To Stop: "sudo systemctl stop rtsp-stream.service"

View Status: "sudo systemctl status rtsp-stream.service"

Reboot the board by running the "sudo reboot" command. Give it a minute to boot and then open up VLC to view the stream.

And that's how you can create an IP camera using the Raspberry Pi zero. Everytime the board boots, it will automatically create the stream and you can view this remotely. In an upcoming post, we will learn how to create an NVR which will allow us to view multiple streams and save them to some storage. If you like this kind of projects, then please consider subscribing to our YouTube channel as it helps us continue creating projects like these.

YouTube: https://www.youtube.com/channel/UCbWiK1A5RqAugSquBHuyBdA

Thank you for reading!

Be the First to Share


    • Build a Tool Contest

      Build a Tool Contest
    • Remote Control Contest

      Remote Control Contest
    • Sculpt & Carve Challenge

      Sculpt & Carve Challenge



    4 months ago on Step 5

    This does not work. When testing it throws a bunch of errors, and I'm stumped.


    5 months ago

    Hello, i just finish this Instructable, and it works !
    I do it on Pi Zero, with "debian light" and your instructions...

    Thanks for sharing this project.
    Very good job !


    6 months ago

    Sorry. This doesn't work with Bulleye!

    Time to update!


    Question 9 months ago

    When I run rasp-stream.sh I got
    h26x demux error: this doesn't look like a h264 ES stream.
    main stream error: unknown query 0x30e in demux_vaControlHelper
    and VLC log says: main error: connection failed: Connection refused
    satip error: Failed to connect to RTSP server
    Any idea how can I fix it? thank you!
    I am connecting my Pi to university wifi after wpa configuration, could this be a problem?


    Answer 9 months ago

    I met the same problem as well... while I am not using the university wifi


    Reply 9 months ago

    This doesn't work for me. does it work for you? I am basically still having the same error


    1 year ago

    If you are using Raspberry Pi Lite over ssh, you have to install vlc first, otherwise you get the error: "cvcl command not found" I hope this helps someone.


    1 year ago

    Project is quite attractive and looks simple.
    Nevertheless, it seems not being able to connect to my router.
    I tried many configuration of the wpa_supplicant.conf file without success.
    The ssh file disappears right, but the wpa_supplicant.conf file is still there.
    Neihter my router DHCP list does show it, nor the angryIP scanner. Putty via hostname also fail.
    It is probably related to the linux distribution.
    Maybe there is another thing to do to with the wlan0 network interface.
    Is it possible to do so headless or do I need a regular screen/keyboard ?


    Reply 1 year ago

    put sudo in front of Chmod +x rtsp-stream.sh, only the super user (pi) can change permissions


    1 year ago

    Thanks for the clear and informative instructions - I'm hoping to do something similar with the Pi Zero and camera module to stream a video feed of the wildlife in my back garden. What are the advantages of using VLC over the Pi Camera HTTP server? (https://picamera.readthedocs.io/en/release-1.13/re...


    Reply 2 years ago

    Guess you like Atom :)