Raspberry Pi Webcam Robot – Best Video Streaming Tutorial

It is always cool to add a camera to your remote controlled car or robot, so that you can see where its heading exactly and probably use a wifi enabled smartphone or tablet to view the video as well.Its very simple now to do this using a raspberry pi and a USB webcam.Real time streaming can be done with minimum delay too. Here, steps are given on how to view the feed from your webcam on the monitor connected to the raspberry pi as well as on another device in the same local network. This tutorial will show you how you can add a camera and video broadcasting system and make a raspberry pi webcam robot . Have fun with this DIY Hacking tutorial!

Step 1 Connecting the USB webcam and checking it

Required Materials


  1. Raspberry Pi model B with memory card preloaded with an OS.
  2. WiFi dongle : Edimax EW 7811UN.
  3. A USB webcam.

Software (Programming languages and OS  involved):

  1. HTML.
  2. Linux/Rasbian.

How does it work?

The working of the raspberry pi webcam robot is explained as follows. Here, the USB webcam connected to the raspberry pi usually associates with the pi at /dev/video0.A streaming service called mjpg streamer after installation is then used to broadcast the video on the raspberry pi’s local IP address and port number. The resolution of the video and frame rate can be set using linux commands while running the mjpg streamer.The video feed can then be viewed on any local network connected device by opening an HTML file in a browser that invokes the video from raspberry pi’s IPaddress:portno.The file required for this is provided in this tutorial as well. Also, in order to test the webcam locally on the pi, a service called ffmpeg is used. This allows you to view the webcam feed on the monitor connected to the raspberry pi. A block diagram showing the basic working:

Raspberry Pi Webcam Robot – Best Video Streaming Tutorial Schematic


Step 1: Connecting the USB webcam and checking it

First of all, you need to check if your webcam is getting detected in the raspberry pi and whether its feed can be viewed. For this, first run the command “lsusb” in the terminal of the raspberry pi. This shows you a list of all the USB connected devices on the pi. Find out, from the list if your webcam’s name or software is displayed (sometimes driver name is displayed eg: Microdia for Iball webcams). Next, we need to check whether you can view the feed from the webcam on the pi. For this use “cd /dev” to go to /dev directory. Next, use “ls” to list its contents, check if “video0″ is present.

Now, you have to use a service called ffmpeg to view the feed from the webcam on the monitor connected to the pi.Use “sudo apt-get update” to update lists. To install ffmpeg service, use these commands:

sudo apt-get install ffmpeg
ffplay -f video4linux2 -framerate 15 -video_size 320x240 /dev/video0

The first command installs ffmpeg. The second commands starts up the video having a frame rate of 15fps using the video4linux2 mode , having a resolution of 320×240 and using the device from /dev/video0. Once you run it, you will see the webcam feed on the monitor.

Step 2: Setting up the video streaming service for the webcam

Here, the video from the raspberry pi is broadcasted on the local network. Any device on this network can view the video from the webcam.To do this, you need to first install the mjpg streamer. Use these commands to install it:

sudo apt-get install libv4l-dev
sudo apt-get install libjpeg8-dev
sudo apt-get install subversion
sudo apt-get install imagemagick

libv4l-dev and libjpeg8-dev serve as dependencies, image magick is used for installation whereas subversion is used for installing open source softwares.


For more detail: Raspberry Pi Webcam Robot – Best Video Streaming Tutorial

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top