Saturday, December 21, 2013

Control an RC Car Over the Internet

A few months ago I set out to make an RC car controllable over the internet.  I hosted a website from my laptop to make this happen.  This is what you would have found on the about section if I left the site up (the car was getting a bit annoying).  Source code can be found here


Real RC Race was a project to get an RC car controllable over the internet. I started at my local Radio Shack and bought the cheapest RC car I could find [1], as well as a breadboard, some transistors and LEDs.

I searched the internet for "control rc car from computer" and the first source I found was this [1]. This guy used a parallel port to run current on a circuit that flipped switches on an RC car's controller. At first I tried using a parallel port. Living in 2013, I did not own a computer with a parallel port. I bought a USB parallel port only to find that the microcontroller in the adaptor would provide an abstracted interface to the operating system, preventing one from physically setting bits on the wire like you could on an old school parallel port. One adventurer [2] used a transistor to latch the values written to the port on his USB adaptor, but this setup seemed unreliable.

I broke apart the car's remote control and soldered wires from the remote's switches to the breadboard. I also grounded the remote's batteries to the breadboard. From here I could control the car with copper wires. I set up 2N3904 transistors to gate these connections, as well as LEDs to show current was going through, and verified with a AA battery that I could use external power to control the car. The circuit remains roughly the same today.

Finally I resigned to make another investment and purchase an Arduino Uno. This was a breeze to set up, program and use. In a matter of minutes I was controlling the car using my keyboard through the Arduino's handy serial interface. I put 1K resistors and LEDs between the Arduino's digital pins and transistor gate. Originally I used the remote's AA batteries to power the antenna, but later connected the Arduino's +3.3V to a handily visible positive terminal on the remote, saving the need to replace its batteries in the future. The Arduino sketch is found below under "sauce". It's extremely straightforward.
Next I wanted to control the Arduino using Java. This wasn't terribly difficult; I found out that the Arduino IDE uses RXTX to communicate with the board and I grabbed a copy of this library. I had a Java program writing data to the serial port using RXTX.

Finally there was the the task of running a Java server to talk to the board, and a client application willing to talk to it. At first I tried using standard Java Sockets and an applet in a webpage to connect to it. I had a server and console application client talking to each other using sockets and controlling the car. However, it turns out that building and signing an applet on Linux is not easy. I didn't care to write an entire applet anyway, and I don't think anyone really enjoys running an applet in a webpage.
There had to be an easier way to do this. I tried to see if I could just set up a raw socket connection to my server from JavaScript. It turns out you just can't do this, but you can come close with WebSocket [4]. Java EE provides WebSocket support, but attempting to install the Java EE SDK on my Linux laptop resulted in my screen turning blank. So I decided to go with jWebSocket [5]. This library works, but I think it was written by apes and the documentation is abysmal. Regardless, that's what I used in my project.

With a WebSocket connection to my controller server from a webpage, I was controlling the car from any computer. For the webcam I used Motion [6], which magically sets up a web server running on 8081 that shows a stream from your webcam. I just used my laptop's webcam.

Anyway, I hoped you enjoyed this story. All of my code is found below and you're free to view, copy, modify and use it, barring any restrictions from the dependencies I used. If you want to copy this project entirely, you'll have to acquire the hardware I described, and install jWebSocket, RXTX, Motion and Python (for the static web server) on your machine. I used Linux but I'm sure this setup will work on any platform. Cheers.
  1. http://www.radioshack.com/product/index.jsp?productId=16767136
  2. http://www.jbprojects.net/projects/rc/
  3. http://www.linuxquestions.org/questions/linux-hardware-18/usb-parallal-adapter-i-o-trickery-836663/
  4. http://en.wikipedia.org/wiki/WebSocket
  5. http://jwebsocket.org/
  6. http://www.lavrsen.dk/foswiki/bin/view/Motion/WebHome

6 comments:

  1. Remote control cars are some of our top selling products at http://www.monkeyhobby.com. They are great gifts for all ages no matter what scale rc helicopter you choose. We offer Electric, Quadcopters and Gyro Helicopters that can be flown indoors and outdoors. We also offer a range of 2 Channel, 3 Channel and even 4 Channel Helicopters. Our most popular channel is the Gyro 3.5 Channel that gives you the extra stability while flying or hovering.

    ReplyDelete
  2. If your kids love racing, then Remote Control helicopter with Large Hand Remote Controller car is a perfect gift for them. Every Remote Control Products can Move Forward, Backward, Left and Right, Up and Down. This remote control car, remote control helicopter, rc trucks, rc plane, fms plane parts, rc drift cars, hsp parts, rc helicopter is powered by battery and responds excellently when moved in directions of their choice.

    ReplyDelete
  3. Chassis of the vehicle comes as a single molded plastic and most of the time vehicle does not have any racing components such as independent suspension systems, speed controllers, interchangeable body with stickers etc.
    http://www.swellrc.com/remote-control-cars-for-kids-top-7-unique-rc-vehicles/

    ReplyDelete
  4. You produced some decent points there. I looked online for your issue and located most people go coupled with with your web site. How to top up lycamobile online 

    ReplyDelete
  5. I have been gone for some time, but now I remember why I used to love this web site. Thanks, I will try and check back more often. How often do you update your web site? como borrar historial

    ReplyDelete

  6. I appreciate the efforts which you have put into this article. This post provides a good idea about Remote Control Car in Dubai Genuinely, it is a useful article to increase our knowledge. Thanks for sharing such articles here.

    ReplyDelete