Introduction: How to Make Raspberry Pi Webcam Server and Stream Live Video || Motion + Webcam + Raspberry Pi

Picture of How to Make Raspberry Pi Webcam Server and Stream Live Video || Motion + Webcam + Raspberry Pi

Hello and welcome to Being Engineers.

If you are watching this, then you might know how to work with Raspberry Pi and you may want to make a Webcam server that can stream live video over the internet ( local network ).

This is what we will be doing today. The process will be very simple but the result is pretty impressing and useful. Before starting you have to know 2 things:

  1. How to install OS in a Raspberry pi. ( link - https://www.instructables.com/id/HOW-TO-INSTALL-RA... )
  2. How to use your Laptop Screen a monitor for Raspberry pi. ( link - https://www.instructables.com/id/How-to-Use-Window... )

So before we get started, we want to clarify that the process is not the only process to achieve this result. I am showing this to you because I found this most convenient to the user.

You can check out our YouTube channel - www.youtube.com/c/being_engineers1

Our Website - www.being-engineers.com

We have made a video tutorial on it.So do have a look. :)

Now let's begin.

Step 1: Gather the Components

Picture of Gather the Components

In this project, you will need the following:

  • Raspberry Pi 3 Model B (Any version will work, but in PI 3 we have the provision for WiFi that can make this server wireless)
  • USB Webcam (I will use my old Logitech Webcam. Use a better camera for better results.)
  • 5V 2A Power Source (I will use my Honor 13000mah Power Bank )
  • Lan Cable ( RJ - 45 Cable )
  • Minimum 8 GB Class 10 SD Card ( I will use Sandisk 32GB class 10 SD Card )

If you haven't install the Raspbian OS on the SD card, then you will need a memory card reader and checkout our tutorial on how to install the OS in Raspberry Pi.

Step 2: Set Up Your Raspberry Pi

Picture of Set Up Your Raspberry Pi

We assume you have the SD Card with the raspbian OS installed.

Then insert the SD Card in the Pi.

Connect the USB camera to any one of the four available USB port.

Connect the ethernet cable aka LAN cable to your Pi and connect the other end to your router.

Then Power Up the Raspberry Pi.

The next step is only for Raspberry Pi 3 users. Others. go to step 4.

Step 3: Connect Your Pi to Internet Through WiFi (only for Raspberry Pi 3 Users)

Open the desktop of Raspbian and connect to WiFi by putting the correct password.

When the raspbian is connected to the network by WiFi, then shut down the system.

Now detach the LAN cable and restart. Then you must be connected to the Internet via WiFi only.

This will help to move your webcam and the pi anywhere without the RJ-45 cable.

Step 4: Know Your Raspberry Pi IP Address

Picture of Know Your Raspberry Pi IP Address

Do the following steps to view Pi IP address.

  1. Open your browser on laptop or mobile. ( laptop or mobile has to be in the same network as the pi )
  2. Go to your Router settings by typing in the default IP address of your router. ( written somewhere on your router. )
  3. Find the list of connected devices.
  4. Find the corresponding IP address of the device named raspberry.

In our case, it is 192.168.0.107

Step 5: Connect to Your Pi by SSH Connection ( PUTTY )

Picture of Connect to Your Pi by SSH Connection ( PUTTY )

Open up Putty and type in the IP address of your Pi and connect.

'pi' & 'raspberry' is the default 'login as' and 'password' in Raspbian.

It is always a good practice to Update and Upgrade the system as soon as you log in.

To do it, type in the command 'sudo apt-get update' and 'sudo apt-get upgrade' one at a time.

Step 6: Install the Software and Do the Necessary Settings

Picture of Install the Software and Do the Necessary Settings

Type in the command 'sudo apt-get install motion ' to start the installation.

Now to make sure that the camera is correctly detected.

Type in the command 'lsusb' and enter. You should see the name of your camera. If it is NOT there, then there is some problem in your camera or the camera is not supported in 'motion'.

After the installation is complete, type in the command ' sudo nano /etc/motion/motion.conf ' and press enter.

Then you have to change some settings in the .conf file. It might be difficult sometimes to find the settings but use 'ctrl + w' to find it. So follow the steps:

  1. Make sure 'daemon' is ON.
  2. Set 'framerate' anywhere in between 1000 to 1500.
  3. Keep 'Stream_port' to 8081.
  4. 'Stream_quality' should be 100.
  5. Change 'Stream_localhost' to OFF.
  6. Change 'webcontrol_localhost' to OFF.
  7. Set 'quality' to 100.
  8. Set 'width' & 'height' to 640 & 480.
  9. Set 'post_capture' to 5.
  10. Press ctrl + x to exit. Type y to save and enter to conform.

Again type in the command 'sudo nano /etc/default/motion ' and press enter.

Set ' start_motion_daemon ' to yes. Save and exit.

Step 7: Start the Server

Picture of Start the Server

First of all your have to restart the motion software. To do it type in the command 'sudo service motion restart' and press enter.

Again type in the command 'sudo motion' and press enter. Now your server is ready.

Step 8: It's DONE!!

Picture of It's DONE!!

Now open up your browser. Type in the IP address of your raspberry Pi and the port number in this way:

192.168.0.107:8081 (First there is the IP address, then a ':', then the port number). Press Enter.

Now you can see the Live feed coming from your webcam directly on your laptop or mobile or both at the same time.

Hope you have enjoyed this tutorial. If yes then please do SUBSCRIBE to our channel Being Engineers. It really helps us a lot on seeing your support and interest towards our channel and don't forget to share :)

Channel link - https://www.youtube.com/c/being_engineers1

Peace.

Comments

BlueEye.dk (author)2017-12-17

how do you make it work with the onboard cam and not usb cam

BlueEye.dk (author)2017-12-15

when iv edited the file and restarted the service i get this

Message from syslogd@raspberrypi at Dec 15 16:19:10 ...

motion: [0:motion] [EMG] [ALL] motion_startup: Exit motion, cannot create log file /var/log/motion/motion.log: Permission denied

Broadcast message from systemd-journald@raspberrypi (Fri 2017-12-15 16:19:10 UTC):

motion[654]: [0:motion] [EMG] [ALL] motion_startup: Exit motion, cannot create log file /var/log/motion/motion.log: Permission denied

englewentpro. (author)2017-12-03

WOW! Thanks for the detailed breakdown of the software coding and what needs changed to run the camera. I will use a lot of what you explained to make a dog treat dispenser so I have a way to check on them as they come over for the treats.. thanks so much again! Keep dishing out the good content!!

AnnishaA (author)2017-11-30

thank you so much. your post really help me out. bless you

Being Engineers (author)2017-01-30

sure. :)

Good afternoon all,

Thanks for creating this tutorial, it is very constructive and working like a charm.

A question if I may is : How to record the video please?

Many thanks.

Siamak

chươngn10 (author)2017-10-08

Thank you so much for this post. I've followed your instruction and finally got my video streamed. But after 2-3 days using this method and now my camera doesn't work with Motion anymore. It doesn't work when i type neither: "sudo motion" nor "sudo service motion start". The camera's just off. I try raspivid to test the camera and it works normally. I've tried deleting all the package and reinstall it but it's still the same. What could be the reason for that? Please help me.

TravisA32 (author)chươngn102017-10-09

I had a similar issue, not sure if you have the same issue.

But,
check if it storing photos/videos of every time something gets caught
on your camera (it does this by default, as Motion is for motion
detection and will store those pics). My raspberry pi got full, so I
had to turn that functionality off and remove the photos/videos from the
output folder.

After that, it worked fine. Hope this helps.

chươngn10 (author)TravisA322017-10-09

Thank you for your reply. I've made a recovery for my Pi but nothing changed.

chaitanyaw5 made it! (author)2017-09-12

I followed the above steps but when I entered my raspberry pi ip address and port number 8081 it shows blank screen with the messege "Unable to open video device". What could be the reason foe this error?

Gurkamals1 (author)chaitanyaw52017-09-21

try:

sudo modprobe bcm2835-v4l2

in terminal

柏翰陳1 (author)2017-09-12

How to do "just forward port 8081 to the pi in your router and vala, your camera is on the internet."

NigelT1 (author)2017-07-23

23.7.2017

Well that worked for me.

I would like to mount the WebCam on Pimorni's https://shop.pimoroni.com/products/pan-tilt-hat

How can one
draw 4 arrows on the screen for Up,Down,Left and Right so one can
control Servos via the screen and mouse to change the position of the servos.

Many thanks for any help...

advaith007 (author)2017-07-06

thank u sooo much .. very helpful.

graefawks (author)2017-01-30

Just to point out, this will not work if your phone/laptop is not on the same network as the Pi (so you cannot view the feed from work etc).

192.168.x.x are local IP addresses only.

Actually I have said that point in the video but forgot to mention here. Thanks for your comment.

This is ridiculous and a misleading instructable as you specifically state you can view the feed over the internet.

raht (author)Ben Choad2017-05-11

just forward port 8081 to the pi in your router and vala, your camera is on the internet.

http://<your internet ip>:8081

unless of course your isp blocks outgoing www ports. then you'd have to use a nonstandard port like 10721 or the like.

This is not misleading. I missed to mention the term " local network " . I have corrected it.

Just wanted to clarify that Internet is world wide web and Intranet is local network. However, if you have VPN access to the network on which the camera is located then you could potentially view the camera from the Internet. Hope that helps!

About This Instructable

43,024views

152favorites

License:

Bio: We run YouTube channel and provide some video tutorials on electronics and programming and also videos on cool projects - how to make them, tech news ... More »
More by Being Engineers:How to Use Mobile Hotspot to View Raspberry Pi Desktop in Android MobileIOT Based Surveillance Camera || Raspberry Pi + Pan-Tilt Arrangement + Cayenne + Webcam ServerHow to Communicate With Arduino From a Python Script
Add instructable to: