Raspberry pi remote control car camera

Wednesday, October 26, 2016

This project will make remote car control which can view camera attached on car.
It will need:
Hardware side:

1. Car toy
2. Two gear motor
3. Raspberry B+
4. Wifi dongle
5. Power bank (10A) (for Raspberry board)
6. Battery (for gear motor)
7. H-bridge circuit (L298N)

Software side:
1. Install camera using ffmpeg (Link)
2. Install Local web (Apache)
3. Make web page to control
4. Control through Internet (by port forwarding)

Step 1. Make a car
Install gear motor to car toy. It will need your clever hand and some thinking to put all things in right way
Also put H-bridge inside the car

Briefly introduction about H-bridge:
H-bridge is used to control motor direction: to make motor run clockwise A1 and A2 must be ON; run counter clockwise B1 and b2 must be ON
Above image is type of Mechanical H-bridge using relay, this project will use H-bridge from IC L298N
This electronics H-bridge also have 4 inputs A1 A2 B1 B2 (indicated in PCB is IN1 IN2 IN3 IN4) which will triggered by Raspberry GPIO
Make connection from Raspberry to H-bridge
This project connect:
GPIO0 - IN1 
GPIO2 - IN4 
GPIO3 - IN3 
GPIO4 - IN2  
GND Raspberry - GND H-bridge
For example, to make car run forward -> 2 motor have to run clockwise -> IN2, IN4 should be ON; IN1, IN3 should OFF -> GPIO2, GPIO4 should ON; GPIO0, GPIO3 should OFF

Step 2. Install camera
In previous article, follow instruction there to install ffmpeg into Raspberry (Link here)

Step 3. Make a web page to control
Install Apache and php by following command
sudo apt-get install apache2 php5 libapache2-mod-php5
After installation, input Raspberry IP address (this case is in Web browser to see if local web working or not. If working, it will have result as here:

This webpage is saved at /var/www/html/
Next is making a local web which will load camera image on Step 2, and have 4 buttons to control motor of car
cd /var/www/html/
gedit camera.php

Then, input following content:
        <meta charset="utf-8" />
        <title>Raspberry Pi - Camera rotate</title>

    <body style="background-color: white;">
<img height="240" width = "320" src="" />
<button id="myP" onmousedown="mouseDown(02)" onmouseup="mouseUp(02)">Backward</button>
<button id="myP" onmousedown="mouseDown(03)" onmouseup="mouseUp(03)">Turn right</button>
<button id="myP" onmousedown="mouseDown(37)" onmouseup="mouseUp(37)">Forward</button>
<button id="myP" onmousedown="mouseDown(27)" onmouseup="mouseUp(27)">Turn left</button>

<!------------------------------------------------ php -->
//set the GPIO0, GPIO7 mode to output
system("gpio mode 0 out");
system("gpio write 0 0");
system("gpio mode 2 out");
system("gpio write 2 0");
system("gpio mode 3 out");
system("gpio write 3 0");
system("gpio mode 7 out");
system("gpio write 7 0");

//-----update button status
$output = shell_exec("cat temp");
if ($output ==0) {
echo ("<img id='status' height=48 width = 120 src='data/ON.png'/>");
else {
echo ("<img id='status' height=48 width = 120 src='data/OFF.png'/>");


<!------------------------------------------------ javascript -->
<script src="camera.js"></script>


Save file, go to web browser, input will see camera image come along with 4 buttons

To make those buttons working with 2 motor (e.g: push "Backward" button, 2 motor should run anti-clock wise; so on for other buttons), two more files need to be done:
   (1) The file camera.js contains mouse_up and mouse_down function for Raspberry GPIO, also update this signal come to Raspberry or not.
   (2) The file camera_rotate.php receive content from camera.js, then will apply GPIO output command, which make GPIO in state 0V or 5V

This project web page can be download at here (Google share)
All files should be saved in /var/www/html
From now, go to local web ( -> can see: camera image & car wheel will rotate if button is clicked (wheel will stop when button is released)

Step 4. Put all thing in car
Attach power bank in car. This power bank will feed Raspberry board

Attach camera, another power for H-bridge motor, and car cover

Done! Now open Local web at to control it

4. Control through Internet (by port forwarding)
In order to control through Internet (any where in world!), port need to open in Router
At Raspberry:
   Change port of /etc/apache2/ports.conf from 80 to 8082
   Change port of /etc/apache2/sites-enabled/000-default.conf from 80 to 8082

At Router:
   Depend case on case at Router manufacturer, follow Router manual to open port 8082 for Local web, and port 8090 for camera
Now, finding Internet IP address by webpage, eg. http://www.canyouseeme.org/
Put internet IP address with Raspberry webpage, now the car can control anywhere in world!

You might also like:
1. Rasbperry pi - FFmpeg install and stream to web
Following tutorial will show how to install FFmpeg into Raspberry Pi, then stream video to Local web which can be access through Computer/Phone/Tablet


  1. This comment has been removed by the author.

  2. Hi Dear,

    i Like Your Blog Very Much..I see Daily Your Blog ,is A Very Useful For me.

    Speed Muscle Remote Control RC Buggy 2.4Ghz 1:16 Scale Truggy Ready to Run w/ Suspension Toy (Green Color) …

    Visit Now - https://www.amazon.com/Speed-Muscle-Remote-Control-2-4Ghz/dp/B01M712G8Y/ref=sr_1_1?m=A3KIGJ5D7AQK8I&s=merchant-items&ie=UTF8&qid=1504848759&sr=1-1&keywords=B01M712G8Y

    Remote Control Car



Search This Blog

Most Reading

Google+ Followers