Tip:
Highlight text to annotate it
X
Hi. Microcontrollers are useful for a great many things. One very practical application
of microelectronics is to bridge together the real world and the digital world.
For this project, we are going to show how you can control this remote control car with
this iPhone. The first thing we did was to take apart the remote control and this is
what we saw. This is a pretty simple car because it doesn't allow for speed control, just forward
or reverse for each of the two motors. From this picture, you can see that the left and
right joysticks both just press on these metal tabs and connect them down to the wires underneath.
With the multimeter we quickly found that the metal tabs were connected to ground and
the wires underneath corresponded to forward and reverse directions. So to highjack that
behavior, we soldered long wires on to those four nodes. Using a transistor driven by the
microcontroller, we can electronically overridethe joysticks by connecting the right ones the
ground when we want a particular motor to go forward or backward. So we just need these
four wires going to 4 transistors on the NerdKit's breadboard. The microcontroller turns on the
right transistor when it wants a certain behavior. We also tapped into the battery connectors
to power the NerdKit. Here's an overview on how our system works.
The iPhone talks over wireless to the computer, the computer sends information to the NerdKit,
and the NerdKit controls the remote control that controls the car. So, let's go over on
what we did, the iPhone is running a very simple web script to figure out where are
you touching on the screen. It's using the iPhone web API that has JavaScript support
for advanced touch events like onTouchStart and onTouchMove. This web script is running
on a web server on a same computer that is hooked up to the NerdKit. As you can see from
the relative simplicity of the code, the iPhone JavaScript API is fairly easy to use. Here
we just defined functions to keep track of where your finger is on the screen. Every
time it has a new value, it sense the X Y coordinates over your finger using an asynchronous
JavaScript call to another page. Now that we have the coordinates of your finger
on the iPhone, we need to get that information over to the NerdKit. We have already shown
how can do this with a Python script that writes the information over the serial port
to the NerdKit. But how can a web script give information to a running Python script? Well
to do this we use something called a named pipe. Pipes are what we use in programming
for different process to talk to each other. PHP treats the name pipe just like a file
so you just open a file and write information to it. On the other side, the Python script
opens the file and just reads the information from it and writes it over the serial port
into the NerdKit. With the NerdKit hooked up and ready to turn
the controller on or off, we just need to read in the value from the serial port and
figure out a way to run the motor at that speed. To do this, we use a technique called
Pulse Width Modulation or PWM. Basically, we pulse the pin on the NerdKit on and off
very quickly and what we do is control the width of each pulse. When we want the car
to go quicker we make the pulses wider keeping the motor on for a bigger portion of a time.
When we want the car to go slower we make the pulses smaller keeping the motor on for
a smaller portion of a time, and therefore making the car go slower. Apart from controlling
the car from the phone, this project also improves the car. Becaues we are using PWM
to drive the motor, we have some sort of velocity control that we did not have before.
In this video, we showed how you can use different technologies along with our NerdKit to perform
a fairly complicated set of tasks. This is just one example of cool things you can do
with your NerdKit. For more videos like this one or more information about our kits, please
visit us at www.NerdKits.com.