Nerds with Toys: Phone controlled R/C Car

Hello Internet,

I’m lucky enough to have a job where I get paid to play with toys. So I figure it’s only fair that I share some of the cool stuff I get to do with you. Today I made an R/C car that can be controlled from my phone. You drive it around by hitting gas and brake buttons, and tilting the phone left and right to steer. I also threw a honk button in there that controls a speaker I installed, along with a LCD screen that you can send messages to from the app. Wanna make one? Well keep reading, I’ll tell ya how to do it.

First thing, buy an R/C car. You only really want the frame and the motors, but it’s easier to just buy it than trying to build a frame. The one we have has a servo on the front for steering and a motor controller and motor on the back for the drive. Basically 90 degrees on the front servo is center, 180 is right, 0 is left. The motor controller on the back is controlled the same way except 90 degrees is neutral, 180 is full forward, 0 is full backward. If you want to vary your direction or speed just send numbers in between the max and the center positions. The battery on the car is 8.4 volts. The motor controller for the rear has BEC, which regulates that to a nice usable 5 volts for the arduino. That power will come through the servo leads connected to it and take care of your need for a second power supply.

To send these positions I used an Arduino and a BlueSMiRF bluetooth modem. The bluesmirf chips are pretty awesome. Give them 5 volts, ground and jump to the the RX and TX lines on your arduino (D0 and D1) and you’re ready to communicate with any bluetooth device. In this case, my Droid X. All ya have to do is pair your phone, and make sure your serial connection’s BAUD rate set to 115200 in your arduino sketch. The key to the communication is to keep your commands short and sweet or you’re going to clog that connection and notice a delay between when you send a command and when the car reacts. I decided to use single characters for each position and action of the car. When you steer left and right you’re actually just sending the characters A-I where E is center, A is full left and I is full right. As the accelerometer position changes on the phone I lock it to the closest degree in this range. These commands will come through as their ASCII code (65-73) in the arduino sketch, and you can run a simple switch statement to send the correct position to the servo you’d like to send the position to. The only time I break away from this is to send messages to the LCD screen. This works because when you send the message you don’t need the same response time as driving. Honking is pretty simple. Hook up a speaker to one of your digital pins and pulse a tone.

On the Android side, the application is pretty simple. Write a background service that handles your bluetooth connection. In your main activity create your buttons and your accelerometer listeners. When the events fire, convert them into the characters I mentioned before and call the service to dispatch these to the arduino. A good thing to do here is check your current command against the last so you don’t send the same data twice if you don’t need to. The SensorManager on android can give you accelerometer updates as fast as 10ms apart. Sending all this data through will cause a pretty noticeable delay. What i did to fix this was store the time stamp of the last command and check it against the time i received my next update minus the amount of delay i chose to enforce. I decided to only send commands if they were 100ms apart. There are several ways to implement your controls. But I found buttons for gas and brake, and tilt for steering, made it easier to control. Let me know if you come up with something better.

Well… that’s how ya do it. If you have any questions or would like to see some code shoot me an email. If you decide to build one yourself, let me know how it works out. Have fun!


icon-instagram icon-twitter icon-linkedin icon-news icon-vimeo icon-realmart `