It’s been a while since my last post, so this one will be pretty long. The post below will be a documentation of how I built my arduino-controlled RC car and it’s progress as I work on it. You can treat this documentation as a guide which you can follow to build your own one of these.
My goal was to take a radio controlled car, gut the insides, and replace it with a custom microcontroller and an Android phone. Since I wanted to make it more difficult on myself (and keep it as dirt cheap as possible), I decided to not use a bluetooth or wifi shield for this project. Another reason I didn’t use these is because the phone would be 2-3 inches away from the microcontroller and it would be foolish to connect them via wifi. Rather, I made them communicate via the headphone jack. This way, I can easily replace the Android phone with anything else that has a 3.5mm headphone jack. The car also needed to have a decent battery to power heavy duty motors as well as the arduino microcontroller.
Original RC Car – Radio Shack Hurricane RC off-road racing buggy – I got this for Free at the MIT flea market, but you can find one of these online for around $10 on ebay. Most of these cars are made by Niiko, so you should be fine choosing a similar model online and still following the guide below.
Arduino Uno – You can find this online for $15 but if you’re thrifty, you can also follow this guide to make your own one for $4 using parts from radioshack. I plan on doing this soonish.
Dual Mini Board – (link) You can do half the circuit on a breadboard if you want. However, the other half with the mosfet cannot be done on a breadboard because it will melt the plastic. Make sure you have a soldering iron before buying this. You can also do all of it on a single board if you are neat enough, but I didn’t succeed in doing so because of a solder mess.
2 x 100k Resistors – $.20
10k resistor – $.10
10uF capacitor – $1.50
4.7nF capacitor – $.25
Lots of hookup wire – $20
2 x 2n2222 Transistor – $.60
2 Relays (steal it from the RC car above) – Free
TOTAL: $30ish (if you don’t have wire and if you use $4 arduino)
Android to Arduino Communication
Surprisingly, there was a bit more to this than I had expected. To start, strip the end of the Audio connector and make sure to not accidentally cut the wire. Once you do this, you will find a ton of wires in there (hopefully only 4, but in my case there were multiple ground wires, so you will surely be confused). To help with this, use the diagram below and a multimeter to determine which wire connects to which part of the connector. Finally, identify the Left and Right headphone wires and keep them separate.
Once you have done this, grab some hookup wire and a soldering iron and solder a wire to this headphone wire. We do this because the headphone wire is extremely fragile and may rip. Then, use some electrical tape to block off the remaining 3 wires (or cut them off).
Next, use the following schematic to make your first board. This will be your Audio board:
The Motor Controller
After that, use the following schematic to make your second board. This will be your Motor board:
My car also has a servo on the front to control the left-right turning of the wheels, but my current circuit doesn’t handle this yet, so your car will not be able to turn.
Android to Arduino Communication Software
My first version of this was simply an Arduino program that read from analog 0 and reported HIGH values as 1’s and LOW values as 0’s. Together, they can make a fairly effective and fast serial protocol. However, nothing is so easy. I was in fact naive to think of this initially. It seems that there is just too much noise to rely on this method. Also, whenever my wire shakes a little, there would be a lot of noise or occational spikes to drive the car nuts. To resolve this, I had to move to the FFT method. FFT (or Fast Fourier Transform) is a way to determine what frequencies are present in a given signal. For example, if you look at your iTunes spectrum analyzer (which isn’t present in itunes anymore), you see that it will show bars in the left side of your song has lots of low frequency bass (dubstep) and bars to the right if you are playing something like Taylor Swift. Similarly, I will play a low frequency note on my phone and make my Arduino read it as a 0. Then, I will make a high frequency note correlate to a 1. After some fiddling however, I further optimized this by setting these values:
HIGH BIT (corresponds to a 1) – 8000hz
LOW BIT (corresponds to a 0) – 450hz
SEPARATE BIT – 3665hz
STOP BIT – 5393hz
Here is how a signal is sent:
1) Arduino will wait for a HIGH/LOW bit from Android. This bit will represent 0 or 1 of the data.
2)Arduino will wait for a SEPARATE bit to signify the end of that transmission. This is because if there is a 1 followed by another 1, we need a way to separate the individual bits.
3)Arduino will wait for a HIGH, LOW, or a STOP bit from the phone. A high or low will represent another bit in the data. If a stop bit is received, it will take the list of previous HIGH/LOW bits and combine them together to make a piece of data (like HELLO WORLD).
If you are wondering how I got those super specific frequency values above, I wrote a small program on the arduino to dump its frequency values to usb and I wrote another program in Processing to read in that data and spit it out as a graph. So basically, its a spectrum analyzer.
Adding to the already over-complicated project, I decided I wanted it to also work with ANY of my android phones. I initially thought my Android program would work on all my phones (HTC One X and HTC Aria), but my phones were giving different frequencies. So, I wrote another part for the program that will force you to calibrate the communications whenever the arduino starts the program. Once calibrated, it is REMARKABLY accurate. Check out the pictures below to see the results…
Source code coming soon…