- This is a two wheels drive RC car
- An universal wheel in the front.
- Two wheels and the car motors on the back.
- OpenWrt compatible router such as GL.iNet 6416.
- USB Video Class (UVC) compatible webcams, I'm using Microsft LifeCam HD-5000 with auto focus
- 4 x 3.7V Rechargeable Lithium-ion batteries (Built-in Protected Circuit)
- Arduino Compatible DIY Motor Smart Robot Car Chassis Kit 2 WD
- L298N Motor Driver Controller Board
- Multifunctional DIY DC to DC Converter
- Female to Female Dupont Jumper wire cable
- Male to Female Dupont Wire Jumper wire cable (20cm), with additional $0.07, you can get a solderless breadboad
- 47ohms resistor and white colour LED
- Nuts and Bolts
As shown in block diagram, everything is controlled by a wireless router, the webcam is connected to the wireless router via USB port that allows live streaming video, the motor controller board is connected directly to the router via GPIO in order to control the motors without the use of a microcontroller.
I chose the GL.iNet 6416A for this project because it is an extremely small wireless router (dimension: 58*58*22mm), the 5 GPIOs & serial port are all easily accessible via though holes or headers.
All other wireless routers supporting OpenWrt should work fine provided there is enough space in flash, you can find a list of supported router models on OpenWrt's website.
Most of the wireless router may not have enough GPIO to control the motors, however, you can use other pin on the router such as the LED pin, this require to unload the leds_gpio module or this way to control LED manually.
I do already have a Microsoft HD-5000 webcam, it’s capable of capturing video up to 1280x720 pixels. The auto-focus was really getting annoying and I do not want autofocus in a car, so why not disable this feature (see here).
Those USB webcams that are UVC compliant should work for this project.
Motor Controller Board
A motor may require significantly more current than the wireless router can provide, it may damage your router if you control the motor without a H-bridge. Hence the L298N Motor Driver Controller Board Module is used in this project in order to control the direction & speed (see PWM) of two DC motors.
I found out that there is about 1.5V voltage drop between the input voltage and the L298’s motor outputs.
Multifunctional DIY DC to DC Converter Auto Step - Up Step - Down Boost Buck Solar Power Supply Module
This is a buck–boost converter that has an output voltage magnitude that is either greater than or less than the input voltage magnitude.
Comparing with linear regulator, dc-dc converters primarily strive for efficiency, it can deliver efficiencies greater than 95% while boosting and hence reducing power consumption.
Here is a simple test for the module. I set the module output to 5V and feeding 2V-24V to its input, no matter the input voltage is higher or lower than 5V, I always get a very stable 5V except the input is lower than 2.6V.
Car Chassis Kit
Chassis is made from acrylic material, size(L x W x H) 19.8 x 14.0 x 6.5 cm which is smaller than expected, I ended up spending hours and scratch my head on how to fixed all the gadgets/modules/devices onto the chassics.
The kit included two deceleration motors, two plastic wheel, a battery holder for 4xAA batteries, and there are also two speed encoder which I'm not using.
The motor power supply is 3V-12V according to the product description given by Gearbest.com, following is the additional specifications getting from internet.
- Recommended operating voltage of about 6 to 8V
- Maximum torque: 800gf cm min @3V
- No-load speed: 1:48 @3V
- Load current: 70mA (250mA MAX) @3V
Something very interesting, the two deceleration motors is small but it is very strong that can push and move a placstic chair.
Batteries and voltage supply
I'm using 4 pcs 3.7V 18650 Li-on Rechargeable Batteries, 2 pcs connecting in series and the other 2 pcs connecting in parallel yielding 7.4V (full charge = 8.4V). Charging or using the batteries incorrectly may cause explosion or fire, therefore I suggested to use the batteries with built-in protection circuits.
The RC car may require two different voltage supplies depend on the input voltage of motors, the 5V goes to the wireless router and the other voltage supply goes to the motors.
Before building the RC car, I order a Double USB Voltage Step Down Regulator Module as shown in figure below and a DC to DC Converter (Auto Step-Up & Auto Step-Down) (Auto Step-Up & Auto Step-Down). The Double USB Voltage Step Down Regulator Module provide a constant 5V to the wireless router and webcam via a USB cable, while the DC to DC Converter required to adjust its output voltage before power the motors.
During testing, I found out that the input voltage of the motor must not exceed 5V, otherwise the RC car is running too fast or in worse case the power is shut down automatically (battery protection circuit triggered).
Based on the results of the experiment, I only need a DC to DC Converter that the output voltage is adjusted to 4.5V, while the Double USB Voltage Step Down Regulator Module is not using in this project. Therefore the wireless router & webcam is running on 4.5V, and the two motors is running on 3V (4.5V-1.5V voltage drop, see here).
OpenWrt - a Linux distribution for your router
The GL.iNet wireless router comes with OpenWrt Barrier Braker pre-installed, it includes their newly designed easy to use web interface for configuring the router. Navigate to http://192.168.8.1 & login to the router, the GL.iNet web interface should appear on the screen.
You can click on the Advance Settings (or navigate to http://192.168.8.1/cgi-bin/luci) in order to open the traditional Luci Web Interface.
I'm faced with a problem that the video streaming is not working without login to the router, for this reason I have to download the image file from OpenWrt website and flash it to the router.
If you do not already have a OpenWrt firmware on your router, please refer to this tutorial for instructions on how to upgrade the firmware.
Network and Internet Connection
The router need to have internet connection in order to perform the package installation. Check this tutorial out, it gives you a detailed guide to setting up network and internet connection for your router. Additonal it shows you how to create a new virtual interface (SSID) that allows your computer/notebook/smartphone connect to the router.
Installing packages - Install Additional Software On Router
By default, OpenWrt includes standard software that lets the router create wireless network or join existing ones, it would require to install additional software on the router which is currently not included. Steps below show you how to install all the software needed by webcam, you can skip this section if you don't have a webcam or you don't need video streaming.
- SSH to router and execute the command line by line, preferred PuTTY.
- You must download the current list of packages available from local package repositories before you can install packages onto your router.
opkg update #update list of available packages
- Set Up a Web Camera, please read this turotial for more info.
opkg install kmod-video-uvc #UVC camera driver
opkg install mjpg-streamer #stream JPEG files over an IP-based network
- Edit the file /etc/config/mjpg-streamer in order to enable video. I'm using WinSCP to edit file.
config mjpg-streamer core
option enabled "1"
option device "/dev/video0"
option resolution "640x480"
option fps "10"
option www "/www/webcam"
option port "8080"
- Require to install uvcdynctrl if you want to disable/enable auto-focus.
opkg install uvcdynctrl
- Require to install lsof if you want to get the webcam status.
opkg install lsof
- Start video on router reboot.
- Reboot the router and you are ready to stream.
- Command below will temporary disable auto-focus. You should disable auto-focus on startup (see here).
uvcdynctrl --set='Focus, Auto' 0
- Getting webcam state via lsof command
Disable auto-focus on startup
Save the following code to /etc/init.d/disableAutoFocus. Please click here for more information about Init Scripts.
- Set file permission to 0755, you can also use WinSCP to changing permission.
chmod 0755 /etc/init.d/disableAutoFocus
- Disable auto-focus when needed
- Enable service autostart
Lua is an interpreted language, a change in a script will not necessarily require a rebuild of the entire project, its code is executes immediately after you have saved it, and therefore it is easier to update and maintain. Please read the following Lua files for those interested in seeing how it works.
GPIO's read/write function for router, more information is available here.
Work with gpio.lua in order to control 2 DC motors, more information is available here.
A program that acts as an interface between browser (web page) and router.
The main program, load the external js & css files and implement image onClick events.
The main program, bigger video size.
Layout options such as image postion, colors, and fonts.
A folder consists of the images which shows on the web page.
The software do not need installation, make sure you have transfer them to the correct folders on router. I'm using WinSCP to manage files and folders.
WinSCP is a SFTP/FTP/WebDAV/SCP client for Microsoft Windows that allow you to transfer files and manage folders between computer and router.
Assumes you already have WinSCP running on your computer and are connected to the router. Now extract the downloaded file (2W_WiFi_car.zip) to your computer and transfer them to the respective folders on router as shown in figure below.
The /www/cgi-bin/control file require execute permission, please change its permission to 0755 (rwxr-xr-x) as shown in figure below. Please refer to WinSCP on how to changing permission.
PWM - Speed Control
GL.iNet wireless router use Atheros AR9331 CPU and it doesn't have hardware PWM, the only way to implement PWM is through adopt software PWM.
Kernel after 3.14 , OpenWrt such as Barrier Breaker and Chaos Calmer has dropping support for PWM over gpio, therefore you must compile your own OpenWrt firmware in order to enable the software PWM feature.
I'm trying to follow this tutorial and compile the OpenWrt firmware successful, when I upload the compiled image to the GL.iNet router, it bricked my router (the network interface is not working). Lucky it is recovered easily.
Installing kmod-gpio-pwm-ar9331 (3.10.49-1) to root...
Moreover, i recompiled the gpio-pwm-ar9331 from source, this time it can install onto my router, unfortunately it is not working.
I found out a tutorial related to software PWM that is not fully tested yet. It is now compiled succesful for my router. Hopefully it can run without any problem.
At the moment, the PWM is not working for my router, hopefully this will get fixed on the next few week. If anyone has any idea how we can fix this, please let me know.
Controlling the car
You can control the car from a web browser (do not use Internet Explorer, recommended Google Chrome) or Android application.
- Open up a browser and navigate to http://routerIP/car/ (eg. http://192.168.8.1/car/) or http://routerIP/car/pantilt.html
- Click on the images or use a keyboard to control the car
- Keep pressing a key on the keyboard will keep the car running, release the key will stop the car.
|8 or Up arrow||Move forward||routerIP/cgi-bin/control?RUN=8|
|2 or Down Arrow||Move backward||routerIP/cgi-bin/control?RUN=2|
|4 or Left Arrow||Move left||routerIP/cgi-bin/control?RUN=4|
|6 or Right Arrow||Move right||routerIP/cgi-bin/control?RUN=6|
|5 or Space||Stop||routerIP/cgi-bin/control?RUN=5|
|9||Headlight ON/OFF (use GPIO20)||routerIP/cgi-bin/control?LED=20|
|1||Horn (not implemented)||routerIP/cgi-bin/control?SPK|
|3||Enable/Disable mic input (not implemented)||routerIP/cgi-bin/control?MIC|
|Q||Speed 1 (lowest speed)||routerIP/cgi-bin/control?SPD=40|
|W||Speed 2 (low speed)||routerIP/cgi-bin/control?RUN=60|
|E||Speed 3 (high speed)||routerIP/cgi-bin/control?RUN=80|
|R||Speed 4 (full speed)||routerIP/cgi-bin/control?RUN=100|
I'm Wi-Fi RC Car
My name is Wi-Fi RC Car, I was born in Malaysia on Oct 2015. I can run, I can see, I'm strong, I'm handsome, please try to knowing me, I'm sure you love me.
Higher resolution images available on Flickr