sensor described in the previous
section. Its output varies from nearly
zero volts, to perhaps the full five volts
of the robot’s power supply. The instantaneous reading of the sensor indicates
the amount of light falling on it. Though
digital inputs can be used to read
analog values (this requires additional
circuitry), the best method is to use a
microcontroller with analog inputs.
Many controllers come with at least
a few analog input pins. In some, the
pins are to an analog comparator; you
can compare the voltage to one pin
against a control voltage. In others, the
pin is connected to an analog-to-digital
converter inside the controller. Your program reads the pin, and a digital value
representing the voltage level is returned.
So far, we’ve mentioned connecting
the microcontroller to a motor, LED, or
other output. The ability of a microcontroller to directly interface to a device
depends on how much current it can supply from its output pins. Most controllers
can be connected to an LED — through a
current-limiting resistor, of course. Typical
LEDs don’t require more than 10-14 mA
of current to light up, and most
controllers can supply this on a single pin.
This is not often the case with
motors and other devices that require
high currents. If the microcontroller does
not have its own high-current outputs —
and most do not — then in these cases,
you need to use a driver circuit of some
type. The most common driver circuit for
motors for use in robots is the H-bridge,
so called because it uses four transistors
connected in a kind of H-shaped pattern.
Two outputs of the microcontroller turn
the motor on and off, and determine its
direction. With more elaborate programming, you can pulse the control pin to
control the speed of the motor. This
involves a technique known as pulse
width modulation, or PWM. You can do
an Internet search to learn more about it.
There are other features that differ
from one microcontroller to another,
such as the number and type of internal
timers. You use these timers to do things
like create wait delays, generate complex
signal forms (like PWM), even generate
music. Then there’s the amount of memory reserved for your programs, the maximum operating speed of the controller,
72 SERVO 01.2008
the package style (whether DIP or
something else), and much, much more.
The feature set of a microcontroller is
described in its specification sheet.
That’s where you can read up on what
the chip does, and how you might use it.
The large microcontroller companies (such as Microchip and Atmel)
provide comparison charts that list the
differences. If you’re just starting out
with microcontrollers, all these differences can be mind-boggling. Rather
than guess as to which one is best, go
by the example of others. What are
other robo-builders using? Find out, get
the same chip, and start experimenting
with it. Learn by their example.
or Compiled Language
One last major difference between
microcontrollers is how they are programmed. The two principal methods
are either using an interpreted language built into the chip or compiling
your program to a form for direct use in
the controller. In both cases, you devise
your program on a PC, then download
the result to the microcontroller itself.
Let’s start with the interpreted
language approach first. These microcontrollers are inherently easier for most
beginners. The chip itself contains an
interpreter that accepts programming
instructions — typically modeled after the
Basic programming language — and
converts these instructions in real time to
something that the chip can use. The venerable BASIC Stamp is a good example of
an interpreted language microcontroller.
In order to use the BASIC Stamp,
you need only a programming environment for your PC and a cable to connect
from your PC to the microcontroller.
Parallax — the makers of the BASIC
Stamp — offers a development kit with
all the pieces necessary to get started.
With the compiled approach, the
microcontroller starts out with a blank
canvas. You write a program on your
PC, then compile it to a form that the
controller can use. Once compiled, the
program is downloaded to the
microcontroller via a cable. The form of
the program is most often a series of
hexadecimal (base 16) numbers. If you
were to open one of these program
files in a text editor, it would appear as
gibberish. But to a microcontroller, the
numbers represent specific programming steps and actions.
By and large, interpreted language
controllers tend to be a little more expensive, but they don’t require the investment
of a programming language and compiler,
as these are already built into the chip.
You’re given the software that lets you
program the chip for free. The interpreted
language controllers are often easier to
use because the programming environment is more consistent. Because the language is built into the chip, it doesn’t
change as much; this leads to more examples from both the makers of the microcontroller, and the existing user base of
those sharing their ideas on the Internet.
Your choice of whether to use a
microcontroller that’s programmed
with an interpreted language versus a
compiled language is largely a matter
of personal needs and requirements.
Following is just a small selection
of low-cost microcontrollers suitable
for use in amateur robotics. There are
literally hundreds and hundreds to
choose from, and there simply is not
space to list them all.
Selection of robots and robotic
construction products, including
microcontroller boards designed with
amateur robots in mind.
Makers of several lines of
microcontrollers, including AVR — a
very popular eight-bit controller used
extensively in amateur robotics.
Axiom Manufacturing, Inc.
Specializes in single board computers, embedded controllers, custom
design, and manufacturing solutions.
Products include single board computers based on the Motorola 68HC1x
microcontrollers, as well as others.