Monday, October 17, 2011

Wiimote Controlled Remote Controlled Car(R/C Car)


Wiimote has opened up many possibilities to explore the open Wiimote APIs. Much already given in wiimoteprojects.com.

This post is to explore how to control a normal R/C car using the motion sensing feature of Wiimote.

First I would like to thank Wiiusej, IOport test and other tools which helped to create the programs and get the idea click.There are many similar applications available but with high cost hardware support. This attempt is with minimum cost and hardware.

First would like to present what is the goal..

1. Attach the R/C remote with the parallel port of the computer.
2. Write a small program in Java to send specific command to the parallel port .
3. The car should turn right/left if the wiimote is turned right/left.i.e the car should react to the motion sensing of the wiimote.
4. You can record the car moves and replay it as you wish.


Hardware needed  -
1. ULN2003 IC - Cost - 40 /- INR
2. BreadBoard or any Circuit Board - 120/- INR
3. Wires -  10/- INR
4. Parallel port cable - 120/- INR
5. 1 Wiimote - 1000/- INR
6. R/C car with remote - 250/- INR
7. Bluetooth dongle for PC. - 150/- INR

Software Needed
1. Wiiusej library  - Wiimote API in java
2. IOPort test - Parallel port control in java 
3. Developed software to control the Wiimote

Below is the schematic diagram of the overall system.


Attaching the remote controller to the PC -
First would like to put the plan to attach the Car remote controller. To do this we need to first understand the remote of any R/C car.
Mainly it contains 4 switches.
1 for forward , 1 for backward, 1 for left and one for right.
The below picture is a normal remote controller that comes packed up with a R/C car.



What we need now is to connect the 4 switches with the 4 output port of ULN 2003 IC.
The 4 input ports of ULN2003 are connected to D0 - D3 of the parallel port.
Through the software program D0 to D3 are made high/low to trigger the 4 switches of the remote controller using the ULN2003 IC.
ULN2003 acts as the NPN transistor acting as the switch to trigger the remote switch.
For example when the D0 pin of the parallel port is high it simulates a human pressing the up button on the remote.
The parallel port of the PC can be connected using a normal male - male parallel port cable.
The below pic shows the soldered wires to the 4 switches like below.


The below diagram shows the circuit for connecting the remote to the parallel port of the PC.

The next part is to connect the wiimote to the PC.

Wiimote -PC connectivity -
First discover the wiimote in your PC bluetooth devices.One can get huge amount of literature on the net on this.Once discovered pair the wiimote bluetooth device.
Wiiusej - http://code.google.com/p/wiiusej/
This is Java API available to control all the wiimote events .These include the accelerometer events when the wiimote is used.
There is a standalone application in wiiusej which can be launched to test the connectivity between the wiimote and the PC.
IOPort test
Then you need a Java API to read/write on the parallel port. There are lots on net using JNI library . I used this IOPort test which is a simple Java API with JNI dll to control the parallel port.There are other APIs also which can be used.

Program -
Now you need to write a small piece of program which will transfer the wiimote events to send data bytes to the parallel port. These data bytes would then drive the remote to move the car in different directions.
Also what additionally I have done is I have recorded all the  moves the car is making in a file.
So this data is saved in a flat file.So we can replay the path of the car using the file reading the motion changing events that was initially recorded with.
These are the parallel port data bytes and the delay between them which is recorded and replayed.

If you are interested in the full program you can leave your email id in the comment section and I will mail it. I am yet to set it up as a google project where I can share the link directly...
I will do that later when I create some more fun stuffs with the wiimote..

The below youtube video shows how the wiimote is controlling the R/C car and how the recording and replay works.

Next posts will continue on similar interesting stuffs using wiimotes.