Wireless Router Remote Control Car

This is my first RC car control by an Arduino and a wirless router running OpenWRT. There are many OpenWRT supported routers, I'm using a TP-Link TL-MR3020 3G/4G Wireless N Router for this project since it is very slim, low power consumption and it is cheap.
RC car features
- A webcam, the car can be driven without line of sight
- A horn so that you can honk at people.
- LED Headlights attached to the front of the car
- Two wheel drive motor
- Windows GUI application or web interface
- Future Additions: Control by a smartphone (Android & IOS)
Wheel Drive Layout
This project work with the following wheel drive layout.

Prerequisite
-
If you do not have SSH client, you need to install one. I'm using PuTTY
-
WinSCP (Windows Secure Copy)
-
A router flashed with OpenWRT, please read here on how to flash the OpenWRT to a TP-Link TL-MR3020 wireless 3G/4G router
-
Make sure the router have Internet connection (see below) as it will download the packages from OpenWRT repository
Setup Internet Connection for Router
Connect your PC to router as shown in figure below. After flasing OpenWRT to the router, make sure you have setup the internet connection.

Software
- Arduino sketch runs on Arduino (Arduino_Wifi_Car folder)
- Shell script (SH script) runs on the router (www folder)
- The Delphi Wifi_car client application (Delphi Wifi Car folder) or the web interface (www folder) run on computer



Arduino Code
Upload the following sketch to Arduino
The serial data send from router to Arduino must start with a special character such as @ and follow by the command (eg. @2), the router may not work correctly (may cause delay) without the start character.
Shell Script run on Router
The Shell Script is just three lines of code, it act as the interface between router and Arduino. Name this file as "car" and save it to router /www/cgi-bin
When a request is received by the server (router) for CGI, the parameters it receives are through QUERY_STRING environment variable. QUERY_STRING retrieves the string that follows the ? delimiter in the URL for a query, an URL containing a query string is as follows:
http://routerIP/cgi-bin/[email protected]
When the server (router) receives a request for such a page (eg. http://192.168.0.1/cgi-bin/[email protected]), it will write the command (@2) to /dev/ttyUSB0 port (it is COM1 in Ms Windows)
Lua Script run on Router
Lua is come with OpenWRT. If you know Lua programming, you can use it to replace Shell Script.
GUI Interface


Keyboard
|
Function
|
Command
|
Up Arrow
|
Move forward
|
@2
|
Down Arrow
|
Move backward
|
@8
|
Left Arrow
|
Turn left
|
@4
|
Right Arrow
|
Turn right
|
@6
|
Space
|
Stop
|
@5
|
Q
|
Cam (Reserved)
|
Q
|
W
|
Toggle head light
|
W
|
A
|
Toggle horn
|
A
|
S
|
Mic (Reserved)
|
S
|
1
|
Predefined speed 1
|
@S20 |
2
|
Predefined speed 2
|
@S40
|
3
|
Predefined speed 3
|
@S60
|
4
|
Predefined speed 4
|
@S70
|
5
|
Predefined speed 5
|
@S100
|

Interface between Arduino and Router
The router needs to install USB-SERIAL driver to work with Arduino, please select the correct serial driver for your Arduino.
- Run PuTTY and SSH ro router as shown in figure below
- Enter root as login and enter your router password as shown in figure below
login as: root
_______ ________ __ |
- Update list of available packages and stores it on your router RAM partion (make sure your have internet connection
opkg update
- If you are using Arduino Demilanove or FTDI usb-serial
opkg install kmod-usb-serial-ftdi
- If you are using Teensy / Arduino Uno / Arduino Mega
opkg install kmod-usb-acm
- If you are using PL2303 based USB/serial adapters
opkg install kmod-usb-serial-pl2303
- If you are using CP201x based USB/serial adapters
opkg install kmod-usb-serial-cp210x
Verify router is able to communicate with Arduino
Plug in Arduino to the router USB port and restart the router, wait until the router is ready then enter command below
dmesg | grep -i usb |
[email protected]:~# dmesg | grep -i usb [ 9.040000] usbcore: registered new interface driver usbfs [ 9.040000] usbcore: registered new interface driver hub [ 9.050000] usbcore: registered new device driver usb [ 10.240000] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver [ 10.250000] ehci-platform ehci-platform: new USB bus registered, assigned bus number 1 [ 10.310000] ehci-platform ehci-platform: USB 2.0 started, EHCI 1.00 [ 10.310000] hub 1-0:1.0: USB hub found [ 10.590000] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver [ 10.740000] usbcore: registered new interface driver usbserial [ 10.740000] USB Serial support registered for generic [ 10.740000] usbcore: registered new interface driver usbserial_generic [ 10.750000] usbserial: USB Serial Driver core [ 10.900000] USB Serial support registered for FTDI USB Serial Device [ 10.900000] usbcore: registered new interface driver ftdi_sio [ 10.910000] ftdi_sio: v1.6.0:USB FTDI Serial Converters Driver [ 11.040000] usbcore: registered new interface driver uvcvideo [ 11.050000] USB Video Class driver (1.1.1) [25677.400000] usb 1-1: new full-speed USB device number 2 using ehci-platform [25677.560000] ftdi_sio 1-1:1.0: FTDI USB Serial Device converter detected [25677.570000] usb 1-1: Detected FT232RL [25677.570000] usb 1-1: Number of endpoints 2 [25677.580000] usb 1-1: Endpoint 1 MaxPacketSize 16384 [25677.580000] usb 1-1: Endpoint 2 MaxPacketSize 16384 [25677.590000] usb 1-1: Setting MaxPacketSize 64 [25677.600000] usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB0 |
Plug in the Arduino to the router via USB and use the HTTP GET method to control Arduino from browser.
Syntax: http://routerIP + /cgi-bin/car? + command
Connect three LED to Arduino, first LED to D9, second LED to D10 and third LED to D6. Launch a browser and enter the URL as below:
http://192.168.0.1/cgi-bin/[email protected] |
http://192.168.0.1/cgi-bin/[email protected] |
http://192.168.0.1/cgi-bin/[email protected] |
http://192.168.0.1/cgi-bin/[email protected] |
- Make sure you have Internet connection as it will download the packages from OpenWRT repository
- SSH to the router
- Install the following packages
opkg update |
[email protected]:~# opkg update |
config mjpg-streamer core |
Arduino PCB


