How to make a Raspberry Pi into a streaming webcam server with the RasPi Cam

The complete guide!

I recently bought a Raspberry Pi. I was in awe of all the projects you can complete with the little computer. It is quite amazing.

I found a tutorial on how to create a webcam/ security camera that is capable of streaming. I followed this tutorial mostly, but also this one.

However I found myself having to piecemeal different tutorials together in order to get it working. I am also on a Mac, which made things a little more difficult. What was most confusing was also this nonsense about having to use a dynamic dns service. So, here I will try to explain, step by step, how I got my setup running.

Here we go. (I am assuming you have Raspbian installed. I suggest the NOOBS package from if you do not have an OS installed)


First, we want to make sure the RPi is up to date.

sudo apt-get install rpi-update
sudo rpi-update

Now update all packages.

sudo apt-get update
sudo apt-get upgrade


Now, before anything else we want to assign a static IP address to the Pi. This is quite simple to do following the steps below. This is important so we will be able to view the video stream later.

First, look up your IP address info with the following:


Now make note of the following:

inet addr: (Pi’s IP address)

Bcast: (broadcast IP range)

Mask: (subnet mask)

Network IP:

Now run this command and take note of your gateway address and network address. (network is the first number on the left)

route -n

Now you are ready to edit your network interface config file.

sudo nano /etc/network/interfaces

Then, change

iface wlan0 inet dhcp


iface wlan0 inet static
netmask YOUR MASK

Hit Ctrl + X to save, press Y and then enter. Now you can can reboot your Pi and you should have a static IP. Now, when you get the stream up and running you can forward port 8080 on router to your Pi’s IP address in order to view it remotely. (more about this later…)

sudo reboot


Now, here is a step that is important. The first time I followed this step in the aforementioned tutorial, I did it from my Pi, and not SSH, this caused issues with permissions.

First you need to enable SSH if you have not done so already. You can do this by running raspi-config like so:

sudo raspi-config

Now you can navigate to SSH and enable it, do another reboot when complete.

Once rebooted, get onto a different computer. If you have Mac, you can just open Terminal and type the following command:

ssh PI'S IP ADDRESS -l pi

You should connect successfully and the prompt will change to:

pi@raspberry — $

You are now connected to your Pi over SSH.


Now, you need to configure your WiFi USB dongle. (I purchased an Edimax from Amazon). Just google setting up a WiFi USB, Edimax is widely used by Pi enthusiasts and is well documented.


Now to install the software that will detect motion. This is a little tricky, so pay attention to each step.

sudo apt-get install motion

Packages will be installed and you will be prompted to enter Y to continue.

The current version of motion does not support the RasPi cam, so we will be installing a special build.

Enter the following commands in order:

cd /tmp
sudo apt-get install -y libjpeg62 libjpeg62-dev libavformat53 libavformat-dev libavcodec53 libavcodec-dev libavutil51 libavutil-dev libc6-dev zlib1g-dev libmysqlclient18 libmysqlclient-dev libpq5 libpq-dev

Now unpack the file to your /tmp directory.

tar zxvf motion-mmal.tar.gz

Now, we need to update the current motion build with the package we just downloaded.

sudo mv motion /usr/bin/motion
sudo mv motion-mmalcam.conf /etc/motion.conf

Now, we need to configure the motion daemon so that motion will start on boot.

sudo nano /etc/default/motion

change ‘start_motion_daemon=no’ to:


Now, you can configure the motion configuration file yourself if you prefer, but now that you have SSH setup, you can easily use SFTP to paste a pre-configured file onto your Pi.

To edit the configuration file use the following command:

sudo nano /etc/motion.conf

You can find the pre-configured file here. Connecting to your Pi through SFTP is very easy. I use Transmit on my Mac. FileZilla is a great free program for Windows. Just copy and save the file as ‘motion.conf’ in your /etc folder.

After that do another reboot. Now, the camera’s red light should be on and it’s detecting motion! You should be able to view your stream locally now using:


(8080 is the configured port if you used the config file supplied in this tutorial.)


Now, some guides tell you how to mount Windows shared folders or some other way to remotely save your files when motion is detected. This gave me a lot of trouble when trying to view the stream. Personally, I have a 16gb SD card, so I am not too worried about it filling up. Also, using SFTP I go in and delete old videos and pictures from time to time to free up space. You can set up nettalk which is a bonjour service which will allow your Pi to be seen by your Mac and listed as a shared device in Finder, this makes it even easier than SFTP to get to your Pi’s files.

I just created a new directory to save my motion capture files. You can do this by simply:


Then go into the motion config file to update it to the directory you just created. Getting familiar with the config file is handy later when you want to tweak things. Motion is a very powerful software. The documentation can be found here.

Ok, now make sure the stream is up and running before this next step.

We need to go into our router settings and open a few ports. Most important is opening 8080 so we can view our live stream outside our local network. This is fairly straightforward depending on your router, but I am going to assume post people attemping this tutorial will know something about port forwarding. Once you have that done, you will be able to access your stream from any computer using your outward facing IP. You can do this by going to another computer on your WiFi/local network and googling ‘What is my IP address”. Then append it with the same :8080 as before.

For example, my Pi address is something like

And my public IP is

(not real numbers)

So there you have it. A streaming camera on a $35 linux machine. There is a lot more you can do, and you can find that stuff in the tutorials I listed above. The Pi is quite awesome and I hope you will adventure and find new ways to use it.