Introduction: Wifi Controlled Tank
After following the robot lessons on this site I began to dream and started with my first remote controlled car. I've chosen WIFI as the communication channel between the tank and my laptop because I also wanted to stream the video from the tank.
But first let us start with the beginning and take a look at the materials that is needed to build the tank in step 2...
Step 1: Used Materials
- Metal Tank Robot Chassis
- H-bridge to power the motor
- Arduino UNO
- Electric heat shrink sleeve
- TXS0108E (3.3V 5V 8 channel converter)
- Battery Holder for 6 AA batteries
- PCB with solder islands
- M3 & M4 nuts and bolts
- 4 x Aluminium pipes 3.5 cm internal diameter 3.5 mm
Step 2: Principle Design
- Webcam is via USB connected to the wireless router GL-AR150.
- Arduino is connected via a level shifter to the wireless router GL-AR150
- The H-bridge which will control the motors will be connected to the Arduino Uno board.
Step 3: Wireless Router GL-AR150
Connect to GL-AR150
Connect a laptop through a UTP-cable with the WIFI-router (LAN-port). The laptop will get an IP-address in the range 192.168.8.2…254.
Enable Wifi on LAN-side (see pictures)
With a PC or laptop we are going to make a wireless connection to the router. Therefore we need to enable Wifi on the LAN-segment. (See below)
Surf to http://192.168.8.1 (default password:goodlife)
Enable GL-AR150-ef1 150m
Disable Wifi on WAN-side (see pictures)
Because we are going to use batteries to power the robot we should disable the WIFI on the WAN-side.
In the right upper corner there is a link to “Advanced settings”. Disabling WIFI on WAN can be done by pressing on the disable button on the second SSID. (Already disabled below)
Normally the serial is used as a last resort to configure the GL-AR150 when there is no connection possible through WIFI or Ethernet. But in our case we are going to use this port to forward the remote control commands to the Arduino UNO.
To make this possible we need to install an extra package ser2net. To install the package we need to login through SSH into the WIFI-router. (Freeware programs like Tera term or putty can be used to login on the wireless router)
Open Tera Term and fill in the following fields:
- Host: 192.168.8.1
- Service: SSH
When a popup is appearing fill in the fields username and password.
- Username: root
- Password: goodlife
When the terminal window appears type following lines in that terminal to install ser2net:
- opkg update opkg
- install ser2net
The configuration file of ser2net can be found in the /etc directory and is called ser2net.conf. This file needs to be changed and can be edited with vi or winscp.
Goto the following directory /etc/ser2net.conf
Open the file add following lines to the config and safe the file again.
BANNER:banner1:ser2net ttyATH0:115200,N,1,8, dest port:2002
2002:telnet:600:/dev/ttyATH0:115200 NONE 1STOPBIT 8DATABITS -XONXOFF -LOCAL -RTSCTS banner1
Start ser2net up at bootup of router
At following lines to file /etc/rc.local and safe it.
ser2net -c /etc/ser2net.conf
Disable serial debug from GL-AR150
Normally the serial port is used as a last resort to configure the wireless router. It will also send out debugging or info messages out of the serial port. To disable these messages you need to add following line to the file below:
kernel.printk = 0 4 1 7
Replace the line:
PS. The bootmessages are always seen.
Testing serial port
open the router you see a 3 pin header. This is the 3.3V TTL serial port of the wireless router. There is already a header connected on the connector to make testing easier.
Don’t connect this serial port directly to the Arduino or a PC/Laptop because this will damage this serial port.
By connecting TX to RX we can test our setup already to see whether the IP to serial-port conversion works.
Just start with the program tera term a telnet connection to destination port 2002.
- Host: 192.168.8.1
- TCP-port: 2002
You’ll get a black screen and if everything works well you’ll see this message:
ser2net ttyATH0:115200,N,1,8, dest port:2002
Before starting to type something there is an option in tera term to enable LOCAL ECHO this way we see what we are typing.
Everything what is typed next will follow these steps:
- PC sends Character over IP to the wireless router
- Wireless router will convert IP to a serial communication
- The character will be send out over the TX-port of the serial port
- It will be received again on the RX-port of the serial port
- Character will be send back over IP to the PC/laptop
Step 4: 3.3V - 5V TXS0108E 8 Channel Bi-directional Logic Level Converter
The GL-AR150 will be connected to the Arduino UNO. Because the WIFI-router GL-AR150 has a 3.3V TTL serial port we need to convert the signal to a 5V TTL serial port.
I have chosen for an 8 channel convertor this way there are some extra ports left for future extensions…
Again by connection B1 to B2 we can redo the test as described in step 3
Step 5: Webcam
Very important that you chose a UVC compatible webcam. (These are the webcams which are supported by GL-AR150)
I’m not sure that there are webcams which consumes less energy but this is also something to keep in mind. I didn’t look at this specification… I only wanted a nice looking webcam.
Power consumption of my webcam: 5V * 150mA= 750mW
Click on FULL HD 1080P Webcam
Normally there is a video seen in the window. If not check whether the Webcam is UVC-compatible
Disable USB-port on Wifi-router
It’s possible to disable/enable the USB-port through a SSH-connection. (Tera Term or Putty can be used to make a SSH connection with the router.) This is an interesting option to minimize the power-consumption.
- root@(none):~# echo "0" > /sys/class/gpio/gpio6/value (Disable)
- root@(none):~# echo "1" > /sys/class/gpio/gpio6/value (Enable)
Step 6: Arduino Configuration
The Arduino will get commands through the wireless router and will control the 2 motors via the H-bridge.
Commands that can be used are always ending with a “.”:
|Hello.||Check end-to-end communication with Arduino:|
Arduino respond: Namaste :)
|M1F000_M2F000.||Stop the 2 motors from spinning|
|M1F255_M2F255.||Max speed forward (if the tank moves backwards, then reverse the cables from the H-bridge to the Motor)|
|M1R255_M2R255.||Max speed forward (if the tank moves backwards, then reverse the cables from the H-bridge to the Motor)|
In attachment you'll find the configuration of Arduino. I've put some comments in the code to make it more readable.
I've made a list of all the connections from the microcontroller of the Arduino board in this table below.
|pin 0||Serial port Rx Arduino||Via level convertor to Tx Serial port GL-AR150|
|pin 1||Serial port Tx Arduino||Via level convertor to Rx Serial port GL-AR150|
|pin 2||dir1PinA||IN4 (H-bridge Module)|
|pin 3||dir2PinA||IN3 (H-bridge Module)|
|pin 9||speedPinA||ENB (H-bridge Module)|
|pin 4||dir1PinB||IN2 (H-bridge Module)|
|pin 5||dir2PinB||IN1 (H-bridge Module)|
|pin 10||speedPinB||ENA (H-bridge Module)|
The 3.3V of the Arduino UNO board is also used for the level shifter.
Step 7: Putting All Things Together
I’ve chosen to put connectors on a print so it will be easy to rebuild the robot up or to troubleshoot possible issues.
I didn’t use a real PCB so I had to connect the components together with wires. It’s time consuming but in the end it could look like 1 of the photos attached. It’s important to test the soldering and the connection between all the components, it makes the troubleshooting easier. (Try to use some colored cables it will make this easier.)
I’ve made an extra platform because the chassis of the tank was a little bit too small. I used an aluminium pipe and sawed 4 equal pieces of 3.5 cm. Afterwards I tapped a screw thread for these small pipes which I then could use to fixate the aluminium platform.
To power the tank I use 6 NiMH batteries which are installed below the tank in a battery holder. To power the wireless router and the Arduino UNO I used 2 USB cables.
And finally the test...
- Put the magic switch button on of the tank
- Connect to the SSID which is send out by the wireless router (GL-AR150-ef1)
- Connect via tera term to port 2002 (telnet) and send the strings which are described in step 6 Arduino-configuration.
--> Eureka it runs :)
Step 8: Controlling the Wifi Tank With VB.NET
For testing purposes it was good enough to use for instance Tera Term to send the commands to the Arduino. But once it was working, I was looking for a more user friendly way to control the Tank.
It is written in VB.net and there's no need anymore to type the commands to control the tank. The only thing what you need to do is connect to WIFI SSID which is send by the wireless router. (The sourcecode and project file is attached in this step.)
This will initiate the TCP-connection to the wireless router (port 2002). Once your connected the other buttons will be enabled.
The button router will open the routers webpage in google chrome. (It's possible that It won't work on other PC's because I added the directory of google-chrome on my PC.)
Button Clear log
Every character that is received will be put in the textbox. To clear the textbox, the "clear log" button can be used.
This test will send the command "Hello." to the Arduino. (The response "Namaste :)" will be seen in the textbox)
Control buttons (Forward, Reverse, Left, Right)
These buttons will send the corresponding commands which are needed to control the tanks movement. The mouse-button needs to be held down to keep the tank moving. Once the mouse-button is released, the program will send the Stop-command to the tank.