Webcam Streaming Using Raspberry Pi and Java

DZone 's Guide to

Webcam Streaming Using Raspberry Pi and Java

· IoT Zone ·
Free Resource

There are lots of devices in the market that allows monitoring home remotely from a central interface which are very expensive. Tech lovers can now own their inexpensive security systems with the tiny super computer called Raspberry Pi. Instead of using the traditional wireless CCTV surveillance cameras, IP cameras can serve better as they can send and receive data via computer network and internet based on internet protocol. Also resolution clarity of IP cameras is far better than CCTV cameras. With the increasing rate of larcenies it might be smart to invest on a Raspberry Pi controlled security system. A webcam connected to the Raspberry Pi will records all the happenings in the monitored area and live streaming can be viewed from any browser. This blog will explains the procedure for setting up webcam streaming using Raspberry Pi.

 Hardware Essentials:

  • Webcam (I used Logitech c110)
  • Raspberry Pi Model B                                     
  • Power Supply for Raspberry Pi (Mobile Charger will suffice)
  • Ethernet Cable/ WIFI Dongle (I used Ethernet cable)

Software Requirements:

  • Raspbian OS
  • Motion Library

Steps for connecting Webcam to Raspberry Pi:

  • Install Raspbian operating system on Raspberry Pi
  • Install motion library by inputting the following command from terminal 
    • sudo apt-get install motion
  • Ensure that the webcam connected is Raspberry Pi compatible. To check that run the below command from terminal
    • Lsusb
  • Then the camera connected to pi should be listed as a USB device like this
    • Bus 001 Device 006: ID 046d:0825 Logitech, Inc. Webcam C110  (If not detected, then the webcam connected is not Raspberry Pi compatible
  • Motion library has a configuration file where in one can define parameters such as the port number which motion will run on, actions to be triggered when motion is detected
  • Edit the motion configuration file using nano editor
    • sudo nano /etc/motion/motion.conf
  • Below are the parameters that needs to be configured:
    • daemon: set to ON to start motion as a daemon service when pi boots
    • webcam_localhost: set to OFF so that one can access motion from other computers
    • webcam_port : the port for the video stream (default 8081)
      • e.g.:  webcam_port:8089
    • control_localhost: set to OFF to be able to update parameters remotely via the web config interface
    • control_port: the port that will allow access to the web config interface (default 8080)
      • e.g.: control_port:8088
    • framerate: number of frames per second to be captured by the webcam. Warning: setting above 5 fps will hammer pi’s performance
  • To run motion as a daemon service, edit the following file
    • sudo nano /etc/default/motion
  • Set start_motion_daemon to YES
  • Now everything is set up and to start the service type
    • sudo service motion start
  • Wait for couple of seconds for motion to start and open the streaming in browser by typing
    •  raspberrypi_IP: webcam_port
  • Let us suppose Raspberry Pi IP address is, streaming can be viewed from browser by using This streaming can also be used in web applications by putting the streaming in a simple <img> tag like <img src="">

cloud ,internet of things ,iot ,java ,opinion ,raspberry pi model b ,webcam

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}