How to use the Raspberry Pi as a Network Camera
The Raspberry Pi has become quite popular in the recent years. It is an inexpensive, universal piece of hardware for do-it-yourself enthusiasts that can be used in a lot of projects.
Of course it can also serve as a network camera and for time-lapse recording.
The great thing is: you can connect multiple cameras to it! Besides the Rasperry Pi Camera module you can attach (multiple) USB cameras.
Here we will show the steps to use a Camera module + an additional USB camera and then use it in our service.
Step 1: Buy the Hardware
Part list:
- Raspberry Pi 1 / 2 / 3
- Power supply
- (micro)SD Card
- Rasperry Pi Camera module
- an USB camera, i.e. the Microsoft LifeCam HD-3000 – camera list
- Wifi USB dongle (not required on Raspberry Pi 3) or Network cable
- Raspberry Pi Case
Step 2: Basic system installation
First you need to install the OS and required software to the get the Raspberry Pi online. The best way is to start with Raspbian (a Debian based Linux) which is popular and there are a lot of tutorials all over the internet.
We will not go into detail on these steps as there are already great other tutorials from Adafruit. The following are recommended:
Then log into you Raspberry via ssh and check your network with ping webcam.io
. If everything is ok it should look similar to this:
Then upgrade your system and add some packages required here:
This can take a while on the Raspberry Pi 1.
fswebcam
is required to grab the image from the USB webcam. And ftp-upload
is used to upload files later to webcam.io
Step 3: Camera module Setup
First you need to install the camera module hardware if not done already (powered off, of course) and enable the camera for the OS:
Activate ‘Enable Camera’. Finish and reboot.
Then try taking an still photo:
Check if filesize is greater 0:
You can also copy it over to your desktop using scp
(from your desktop). Mac OS example:
That’s it for the RaspiCam.
Optional: create a ram disk. When capturing the still image every minute there are a lot of files written to the SD card per day. To expand the cards lifetime we use a ram disk instead:
Step 4: USB Camera Setup
Connect the USB camera (perhaps reboot) and take a photo:
This is skipping 5 frames for the LifeCam HD-3000 to fix a bug with broken images. And the camera only has a 1280x720 resolution.
Then again check the image:
If everything is fine you can proceed to uploading the images in the next step.
Step 5: Connect to webcam.io
First, sign in to webcam.io and create two webcam entries with FTP connection set. (You can try out the FTP connection by signing up for the free trial)
Grab your credentials from the webcam settings page.
Now set up a script for RaspiCam picture upload:
This limits the image to full HD size. See documentation for camera control and raspistill options.
And another one for the USB cam:
Then make them executable with and run a test:
If there are no errors, you can schedule the upload by using cron
This takes a snapshot every minute. And it uses flock
to have only one upload script (of each type) running at a time.
Wait a minute and then check your webcam.io webcam pages.
Of course you can also use the cameras without webcam.io. You can upload via FTP to your own server. You can also render your own time-lapse videos on the Raspberry Pi itself. This needs a lot of precessing power and might block your system from taking in new snapshots, especially with multiple cameras. At least a Raspberry 2 is recommended.
Conclusion
For around 60-100 dollar you can build a universal network camera you can always change for your requirements and have full control over. To build it into a weatherproof casing for outdoor usage is only one example.
Have fun using your camera(s). Embed them somewhere and share great time-lapse clips!