Homemade Remote Controlled Spycam

Homemade Remote Controlled Spycam


Spycam’s are cool, but mobil spycam’s are even cooler! Using a Raspberry Pi, a webcam, and an old RC car, we’re going to learn how to make a web controlled spycam!

STEP 1: Gather The Parts

If you want to follow along with this project here’s a list of parts you will probably need to order. The more parts that you already have, the cheaper this project will be.

    1. Webcam = $5
    2. RC Car = $12
    3. Raspberry Pi = $35
    4. Motor Controller = $4
    5. Wireless Adapter = $8

STEP 2: Connecting the Components

If you recall, a few months ago, I showed how to create a Smartphone controlled RC Car. As we did for that video, you’ll want to gut the current electronics from the RC car (except for the motor and battery pack) and replace them with the L298N H-bridge motor driver.

Using the GPIO pins on the Raspberry pi, you can connect it to the motor controller. Use the schematic to your left for reference, but here’s the basic outline:

          • GPIO 4 >> INA
          • GROUND >> GROUND
          • GPIO 17 >> INB
          • GPIO 21 >> INC
          • GPIO 22 >> IND
STEP 3: Writing The Code
Installing the OS

As with all new Raspberry Pi installations, you need to download and install the OS. The OS we’ll be using is the Raspbian OS. Clicking that link will download an image file that you will then need to burn to an SD card.

If you are using Windows, then you can burn the image using Win32DiskImager. It will take several minutes to complete, but when it’s through you can eject your card and install it in your Raspberry Pi device. Then with a keyboard, mouse, monitor and wireless plugged in, plug in the power and let it boot up.

Setting up the OS

Once the Raspberry Pi boots up, you’ll be greeted by the configuration screen. Basically, you can configure it however you see fit, but here’s a list of my suggested changes:

        1. Expand Filesystem (Expands the files to use the entire SD card)
        2. Enable Camera (use this option if you have a Raspberry Pi branded camera)
        3. Overclock (useful if you want the streaming software to run faster. I used the 1 Ghz setting)

If you are not from the UK, then it’s a good idea to also go into the internationalisation options and change the keyboard layout to match your country. Otherwise, choose Finish and let the Pi reboot.

After it’s back up, it’ll prompt you for a username and password. The default credentials are “pi” for the username and “raspberry” for the password.

Once you’ve successfully logged in, we need to set up the Raspberry Pi to connect to your wireless. The easiest way to do that is through the desktop interface, so to launch it, type


Now you can run the wireless configuration program and use it to scan for your wireless signal and connect to it. Then you can logout of the desktop to get back to the command line interface.

Installing the Streaming Software

Now it’s time for the fun part (sarcasm). We need to install all the software to run this monstrosity. So as we do with all good linux distributions, let’s update and upgrade it.

sudo apt-get update
sudo apt-get upgrade

Next we need to install the webcam streaming software. I’m going to be using mjpg-streamer. There are plenty of different other options for streaming, but this one proved to be the easiest to set up and the easiest to interface with.

sudo apt-get install libjpeg8-dev imagemagick libv4l-dev
sudo ln -s /usr/include/linux/videodev2.h /usr/include/linux/videodev.h
git clone https://github.com/jacksonliam/mjpg-streamer.git

This should download it to your home folder, so now we can just make it, and then copy the new files to their appropriate directories.

cd ~/mjpg-streamer/mjpg-streamer-experimental
make mjpg_streamer input_file.so input_uvc.so output_http.so
sudo cp mjpg_streamer /usr/local/bin
sudo cp output_http.so input_file.so input_uvc.so /usr/local/lib/
sudo cp -R www /home/pi/www

Then edit the bashrc file

sudo nano ~/.bashrc

And add this to the bottom of it.

Export LD_LIBRARY_PATH=/usr/local/lib/

And then reload bash

source ~/.bashrc

Now we can test it out. If you have a USB webcam, you would want to enter a command similar to this one using “input_uvc.so”(this is untested, so it may not work).

mjpg_streamer -i “/usr/local/lib/input_uvc.so" -o “/usr/local/lib/output_http.so -p 9000 -w www”

If you are using a Raspberry Pi camera, you want to first create a streaming directory, assign it read/write permissions, and then run the following mjpg_streamer command

cd ~
mkdir stream
chmod a+rw stream
mjpg_streamer -i “/usr/local/lib/input_file.so -f stream -n pic.jpg" -o “/usr/local/lib/output_http.so -p 9000 -w /home/pi/www" &

With the server now running, you can use CTRL C to escape out of it and then run this raspistill cammand to launch the camera

raspistill -w 640 -h 480 -q 5 -o stream/pic.jpg -tl 100 -t 9999999 -th 0:0:0 -n &

The stream should now be ready! You can access it from any browser by typing in any IP address followed by port 9000 (ex. If you click on the “stream” tab, you can see a live stream from your webcam.

When you’re done testing things out, you can kill the program processes by using these commands

pkill raspistill
pkill mjpg-streamer

Installing the GPIO Software
With the webcam streaming software installed, next we need a way to control RC car. We have it all hooked up, so now let’s install the software to control it. For this project, we’ll be using a program called Wiring Pi

git clone git://git.drogon.net/wiringPi
cd wiringPi

That’s all you have to do to install it. So now here’s how you can control it:

gpio mode 4 out
gpio write 4 1
gpio write 4 0

Basically you find the GPIO pin that you want to activate, set it’s mode to “out”, write a 1 to turn it on and write a 0 to turn it off. With that done, now all we need as a way to control it from the web.

Installing the Web Software
Like the streaming software, there are also many different options for web server software. For this project, I’m going to be using nginx because it uses the least amount of resources. Then we’ll isntall PHP, because the GPIO software requires it, and then we’ll edit the nginx config file to allow it to run.

sudo apt-get install nginx
sudo apt-get install php5-fpm php-apc
sudo nano /etc/nginx/sites-available/default

Then you want to add these lines below the # listen [::]::80 line.

listen 80;
server_name $domain_name;
root /var/www;
index index.html index.htm;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

location ~\.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
try_files $uri =404;
include fastcgi_params;

Below are commands to both start and reload the PHP and nginx servers.

sudo /etc/init.d/nginx start
sudo /etc/init.d/php5-fpm reload && sudo /etc/init.d/nginx reload

The last thing to do is to make a webpage that has both the controls and the webcam. If you want to create your own, you can use the following PHP commands:


I’ve created an example setup that you are free to download and use as a very basic web interface. You can download and unzip it like this:

wget http://www.tinkernut.com/demos/373_spycam/373_spycam_resources.zip
unzip 373_spycam_resources
mv 373_spycam_resources/* www

Then you will need to edit the spi-cam.php file and change it to match your Pi’s IP address.

sudo nano www/spi-cam.php

STEP 4: Test the Setup
Now everything should be ready to go! Be sure to re-start your mjpg-streamer and raspicam serverices and then navigate any browser to http:///spi-cam.php and test it out! Feel free to edit what I’ve already set up and customize it or make it even better!

Leave a Reply