downloaded to the Arduino, where
it will automatically run once the
download is complete.

At first glance, it may appear that
the Arduino programming statements
don’t provide very much power for
doing things like running servos,
operating stepper motors, reading
potentiometers, or displaying text on
an LCD. Like most any language based
on C, the Arduino programming
environment supports the notion of
libraries — code repositories that help
make your job easier. Libraries let
you re-use code without having to
physically copy and paste it into all
your programs. The standard Arduino
software installation comes with
several libraries you may use and you
can download others from the
Arduino support pages and from
third-party websites that publish
Arduino library code.

A good example of a library
you’ll probably want for your robot
projects is Servo, which lets you
connect a hobby R/C servo to any
of the Arduino digital I/O pins.
Like all libraries, you use Servo by
downloading its files and placing them
in the hardware/libraries path of the
Arduino program directory. You then
add an #include statement at the top
of your program with the name of the
library. For example, #include
<Servo.h>.

From there, you may access the
functions of the library which include
things like specifying which I/O pin
the servo is connected to and the
angle — from 0 to 180 degrees — that
you want the servo moved to. All in
all, pretty simple.

Structurally, Arduino sketches are
straightforward. After any #include
statements you wish to use, the
typical Arduino program contains
two parts: named setup() and loop().
These are programming functions that
do what their names suggest: setup()
sets up the Arduino hardware, such as
specifying which I/O lines you plan to
use, and whether they are inputs or
outputs. The loop() function is
repeated endlessly when the Arduino
is operating.

For additional features and
discussion of the Arduino
programming environment, see
the Arduino support pages which
include a reference and tutorial on
all the language elements.

Extending the
Arduino

The Arduino hardware is an
example of minimalist design. There
are no connectors to directly attach
motors or other devices. You’ll find
only a couple of rows of headers that
make it easier to reach the AVR’s I/O
pins. This simple design makes sense
because the Arduino is a universal
(or generic) development board.

For an application like robotics,
you’ll want to expand the Arduino I/O
headers to make it easier to plug in
things like motors and ultrasonic or
infrared sensors. One method is to
use an add-on board with the Arduino
Diecimila — add-on boards are called
shields in the Arduino parlance. A
shield fits directly on top of the
Arduino, plugging itself into the
board’s I/O headers. Two common
expansion shields are the solderless
breadboard and a proto shield, which
is basically a prototyping board
with thru-hole solder connections.
Several of the companies that offer
these shields are listed in the Sources
that follow.

Of course, you don’t absolutely
need a shield to expand the Arduino.
You can place a breadboard —
solderless or otherwise — beside the
Arduino and use cables or individual
wires to connect the two together.

Some variations of the Arduino
depart from the standard form-factor
of the Diecimila and are not designed
for use with shields. A good example
is the LilyPad, a special Arduino layout
engineered for making (among other
things) wearable microcontroller
projects — like Borg implants, only
more friendly looking. The LilyPad
is in a flower shape with a flat profile
and connection points at the ends of
22 petals.

If you need something smaller,

the Arduino Nano is a fully-functional
Arduino in stick shape and is expressly
designed for use with solderless
breadboards. There’s also the Arduino
Mini, a stamp-sized variation if you’re
limited by cramped space. These
alternate designs may lack one or
more of the physical features of the
Arduino Diecimila, such as the USB
interface (in the case of the Mini).
You’ll need to provide a USB
connection with an accessory board.
This approach makes economic sense
if you are building several Arduino-based projects. The USB interface
adds to the cost of the board, so
buying it just once (and using it just
when you’re programming) will save
you money in the long run.

Several Arduino resellers, such as
Adafruit, offer their own custom
variations of the Arduino — these
typically go by different names such as
Boarduino or Freeduino, to differentiate
them from the original Arduino
designs. The Adafruit Boarduino
(available in kit form for under $18) is
like the Arduino Nano. It uses thru-hole components for ease of
soldering. You can also purchase the
board already assembled.

The Arduino is available with
built-in wireless capability. There’s a
Bluetooth version for about $150,
which does away with the USB
connection and allows communication
with a host PC via Bluetooth. The
XBee add-on shield — priced at about
$80 — provides ZigBee wireless
communications with the Arduino.

Finally, because the Arduino is
based on the AVR microcontroller,
it can be used as a basic AVR
development board. Many of the
current Arduino designs provide extra
pins to connect to an in-circuit serial
programmer which you can purchase
or make. With this programmer, you
can erase the bootloader from the
AVR on the Arduino and replace it
with your custom code. At about
$35 for an assembled Arduino
Diecimila board, this is an attractive
alternative to many of the general-purpose AVR development boards
currently available.