This project is about making a remote control car with a view through an attached camera.
- Toy car
- Two gear motors
- Raspberry B+
- WiFi dongle
- Power bank (10A) (for Raspberry board)
- Battery (for gear motor)
- H-bridge circuit (L298N)
- Install camera using FFmpeg (link)
- Install Local web (Apache)
- Make web page to control
- Control through Internet (by port forwarding)
Install a gear motor to the toy car. It will need your clever hand and some thinking to put all the things in right way. Also, put the H-bridge inside the car.
Brief introduction about H-bridge:
H-bridge is used to control motor direction: to make the motor run clockwise, A1 and A2 must be ON; and to run counter clockwise, B1 and B2 must be ON.
The below image is of a type of Mechanical H-bridge using a relay; this project will use H-bridge from IC L298N.
The H-bridge also has 4 inputs: A1, A2, B1 and B2 (indicated in PCB as IN1, IN2, IN3 and IN4) which will triggered by Raspberry GPIO.
Make connections from Raspberry to H-bridge
Connections are as follows:
- GPIO0 - IN1
- GPIO2 - IN4
- GPIO3 - IN3
- GPIO4 - IN2
- GND Raspberry - GND H-bridge
For example, to make the car run forward 🠚 2 motors have to run clockwise 🠚 IN2 & IN4 should be ON; IN1 & IN3 should OFF 🠚 GPIO2 & GPIO4 should ON; GPIO0 & GPIO3 should OFF.
In the previous article, follow the instruction there to install FFmpeg into Raspberry. (Link here)
Install Apache and PHP by following command:
sudo apt-get install apache2 php5 libapache2-mod-php5
After installation, input the Raspberry IP address (this case is
192.168.1.71) in a web browser to see if the local web working or not. If it is working, it will have the result as shown here:
This webpage is saved at
/var/www/html/. Next is making a local web which will load camera image from Step 2, and have 4 buttons to control the motor of car.
cd /var/www/html/ gedit camera.php
Then input following content:
Save file, go to the web browser, input
192.168.1.71/camera.php and you will see the camera image along with 4 buttons.
To make those buttons work with 2 motors (e.g., push "Backward" button and 2 motors should run anti-clock wise; and so on for the other buttons), two more files need to be done:
- (1) The file camera.js contains
mouse_downfunctions for Raspberry GPIOs, also, updates this signal coming to Raspberry or not.
- (2) The file camera_rotate.php receives content from camera.js, then will apply GPIO output commands which makes the GPIO state 0V or 5V.
This project's webpage can be download here (Google share). All files should be saved in
/var/www/html. From here, go to local web (
192.168.1.71/camera.php) 🠚 you can see: the camera image. The car wheel will rotate if a button is clicked (wheel will stop when the button is released).
Attach the power bank to the car. This power bank will feed the Raspberry board.
Attach the camera, another power for the H-bridge motor, and the car cover.
Done! Now open local web at
192.168.1.71/camera.php to control it.
Control through Internet (by port forwarding)
In order to control it through Internet (any where in world!), the port needs to open in the router.
From the Raspberry:
- Change port of
/etc/apache2/ports.conffrom 80 to 8082
- Change port of
/etc/apache2/sites-enabled/000-default.conffrom 80 to 8082
From the Router:
- Depend case on case at Router manufacturer, follow Router manual to open port 8082 for Local web, and port 8090 for camera
Now, find the Internet IP address by webpage, e.g., http://www.canyouseeme.org/. Put the Internet IP address with the Raspberry webpage, now the car can control from anywhere in world!
Did you replicate this project? Share it!I made one
Love this project? Think it could be improved? Tell us what you think!