Making Robots With Arduino 2 PDF
Making Robots With Arduino 2 PDF
Making Robots
With The Part 2
Arduino
The ArdBot is a low-cost, 7 diameter servo-driven robot base, ready for
expansion. Its called ArdBot because its based on the popular and
inexpensive Arduino microcontroller board. The ArdBot costs under $80 to
build; even less if you already have some of the components, like the
breadboard, jumper wires, and battery holder.
By Gordon McComb
n the last installment, we introduced the ArdBot and is the practical minimum and 3 the maximum.
www.servomagazine.com/index.php?/magazine/article/december2010_McComb
enough for the basic experiments well be doing in this optional, and are for attaching sensors and other
series of articles. Dont let the small size of the breadboard accessories.
limit you. The ArdBot is large enough for bigger Pair of servo mounts (see Figure 4) for attaching the
breadboards, even multiple boards, should you need them. servos to the bottom deck. You can make these
You might want to start with the mini breadboard, then as
you use the ArdBot for further experiments you can add
more prototyping space.
Table 1. Mechanical Parts.
Qty Description
About the Servo Drive
1 7 diameter bottom deck with wheel well cutouts
The ArdBot uses differential steering where the base is for the drive wheels.
propelled by two motors and wheels on opposite sides. To 1 7 5 top deck.
keep costs down and minimize construction complexity, the 2 Servo mounts.
robot uses a pair of skids placed in the front and rear to 90 plastic L brackets for attaching the servo
provide balance. With this arrangement, the ArdBot is able mounts to the bottom deck. These brackets
4 measure 3/4 3/4 with hole centers at 3/8, and
to move forward and back, turn left and right, and spin in
are made to work with the two servo mounts.
place. The skids are smooth and polished metal, so they
present little drag on whatever surface the robot is rolling 16 4-40 x 1/2 machine screws and nuts for attaching
the servos and servo mounts to the bottom deck.
over. Even so, the ArdBot is best suited for travel on hard
surfaces or carpet with a short nap. Deck risers consisting of: (4) 1-3/4 aluminum
4 (or plastic) risers with 4-40 threads; (4) 4-40 1/2
The two drive motors run off their own battery supply pan head machine screws; and (4) 4-40 1/2
which is a set of four AA rechargeable or non-rechargeable flat head machine screws.
cells. The motors are standard size radio control airplane 2 Skids consisting of: (2) 8-32 3/4 machine screws;
servos that have been modified for continuous rotation. (2) 8-32 hex nuts; and (2) 8-32 acorn (cap) nuts.
The ArdBot reference design uses servos that come Sets of mounting hardware for Arduino Uno,
3 consisting of (3) 4-40 1/2 machine screws;
from the factory already modified so you dont have to (3) 4-40 nuts; and (3) plastic washers.
hack them. I used a pair of GWS S-35 servos, but there are
* For your convenience, all mechanical pieces including
others available (see Sources) for under $15 each. I wont precut decks and servo mounts at are available through
provide instructions here on how to modify a servo for Budget Robotics. See the Sources box for details.
continuous rotation. That subject has been tackled in past
issues of SERVO and Nuts & Volts, so Ill leave it at that. Table 2. Motors and Wheels.
Making the ArdBot Base Qty Description
SERVO 12.2010 53
McComb - Arduino Robot Part 2 - Dec 10.qxd 11/1/2010 5:51 PM Page 54
FIGURE 3.
Layout
pattern for
cutting and
drilling the
top deck of
the ArdBot.
Critical holes
are the four
small ones
nearest the
center. These
must match
the four
servo
mounting
holes in the
bottom
deck.
FIGURE 2. Layout pattern for cutting and drilling the bottom
deck of the ArdBot. The only truly critical dimensions are the
cutouts for the wheels and the placement of the two sets of holes
immediately beside the wheel cutouts. These holes are for the
servo mounts. See Figure 5 for a description of all holes.
yourself or, if you choose, purchase them separately. circles when using these materials. If you dont own a
If you make the mounts, be aware that sizing is circular jig yourself, see if the local picture frame store will
critical. The two holes on either side of the mount make the cuts for you. When using picture mat material,
must be spaced 3 apart to accommodate the same cut two of everything, and double-up the pieces for extra
hole spacing in the bottom deck. stiffness. Except for the large center hole in the top deck,
all holes are drilled with a 9/64 bit.
The base parts may be cut from stock measuring 12
x 12 which is a common size for expanded PVC or other Assembling the ArdBot
plastic purchased through mail order. A motorized scroll
saw is the perfect tool for cutting out the ArdBot base With the body pieces constructed (or purchased) and
components, but if you dont have one handy, a coping all other parts in hand, youre ready to build your ArdBot.
saw also works. Use a wood blade; itll work whether Heres how.
youre making the base with aircraft-grade plywood
(available at the hobby store), PVC, or other plastic. Step 0
If using foam board or picture mat, you can cut the Before assembly, you may want to use 150 grit
pieces using a sharp hobby knife or mat cutter. The usual sandpaper to smooth the edges of the base parts. Orient
safety precautions apply. A circle cutting jig makes perfect the bottom deck so that the holes are aligned as shown in
Figure 5. Note that the holes for each servo are not
symmetrically placed on the deck. This is to accommodate
Table 3. Electronic Parts.
Table 4. Power.
Qty Description
Qty Description
Arduino Uno (or compatible) microcontroller 4 AA alkaline or nickel metal hybride
1 board with USB programming cable. rechargable batteries.
1 Nine volt battery.
1 Mini solderless breadboard; 170 tie points.
Set of solderless breadboard wire jumpers
1 (or make your own using 22 gauge solid Table 5.
conductor wire). Optional (but nice to have) Parts.
1 AA x four battery holder, with female header
connector; see text. Qty Description
1 Nine volt battery clip, with 2.1 mm polarized 1 Nine volt metal or plastic battery holder.
barrel plug; see text.
Hook-and-loop (Velcro) strips for mounting
1 Length of 12 (or more) breakaway 0.100 male 1 battery holders and solderless breadboard;
header pins, double-sided (long) pins; see text. small pieces of double-sided foam tape.
54 SERVO 12.2010
McComb - Arduino Robot Part 2 - Dec 10.qxd 10/31/2010 4:14 PM Page 56
the L bracket, and then into the standoff as shown in FIGURE 8. Secure the servo mounts to the bottom deck using
Figure 8. When orienting the mount assembly, be sure that machine screws and threaded standoffs.
The standoffs serve to separate the decks.
the servo shaft is centered in the wheel well cutout. Align
the assembly so they are parallel with the wheel well
cutout, then tighten all the screws. Figure 9 shows how 1. Using a screwdriver, thread a machine screw into the
the completed servo, mount, and standoffs should look. hole at the front and back of the deck (refer to
Repeat the same procedure for the right mount assembly. Figure 5 for the location of these holes). The screw
is inserted from the top of the deck (the side with
Step 4 the servos). The holes for the skids are undersized
Attach the front and rear skids as shown in Figure 10. for 8-32 machine screws. When using a soft material
Each skid uses an 8-32 machine screw, hex nut, and acorn like wood or PVC plastic, the fastener will tap the
(cap) nut. hole as you screw it in. Continue threading the screw
into the hole until the head is about 1/4 from the
deck, as indicated in the picture.
Repeat these steps for the other skid. You may adjust
the height of the skid by loosening or tightening the
machine screw in the hole. If you need greater height
adjustment or the hole for the skid is too large to self-tap,
FIGURE 10. ArdBot uses static skids (made with 8-32 metal
FIGURE 9. Heres how the completed servo mount should look fasteners) for front and back balance. You can adjust the height
with standoffs in place. of each skid to compensate for the diameter of wheels you use.
56 SERVO 12.2010
McComb - Arduino Robot Part 2 - Dec 10.qxd 10/31/2010 4:14 PM Page 55
Step 1
Insert a servo into a servo mount by sliding it
back-end first through the mount. The fit may be
tight, depending on the make and model of the
servo. (As necessary, enlarge the rectangle for the
servo using a file or coarse sandpaper.) Do not
force the servo into the mount or the mount may
be damaged. FIGURE 4. Layout pattern for cutting and drilling the servo mount. Youll
Secure the servo to the mount with 4-40 x need two of these. If cutting the inside rectangle proves difficult, you can
1/2 screws and hex nuts (Figure 6). You can use instead make the mounts by cutting through at the dotted line.
The mount will be a little more fragile, so handle it carefully.
four screws for each servo, or only two. When Use all four screws to secure the servo in the mount, rather than just two.
using two screws position them on opposite
corners of the servo mounting flange, as shown.
Repeat for the opposite servo and mount. Be sure to Insert the machine screws through the L bracket, then
construct the second servo and mount in a mirror image to through the servo mount. Secure on the other end with a
the first! Refer to Figure 9 in Step 3 to see how the motors nut. Before tightening, be sure the bottom of the L bracket
should be inserted into the mounts. For reference, also see is flush with the bottom edge of the servo mount.
Figure 12 for an aerial view of the ArdBot and its
completed bottom deck. Step 3
Attach the left mount assembly to the bottom deck
Step 2 using two 4-40 x 1/2 screws and standoffs. The screws
Using 4-40 x 1/2 machine screws and nuts, attach should come up from the underside of the deck, through
two plastic L brackets to each of the servo mounts (Figure
7). Youll be make a left and a right mount assembly.
For the left mount assembly, the motor shaft should
face to the left and toward the top of the deck (as
referenced in Figure 5). Attach the L brackets to the right
side of the mount. For the right mount assembly, the motor
shaft should face to the right, also toward the top of the
deck. Attach the L brackets to the left side of the mount.
FIGURE 5. Only four holes are critical for the bottom deck: the two
sets marked Holes for servo mounting, and the front and rear Skid.
FIGURE 6. Servo motor secured into one of the servo mounts. The rest are optional for sensors and other
You need two of these. accessories you may want to add later.
SERVO 12.2010 55
McComb - Arduino Robot Part 2 - Dec 10.qxd 11/1/2010 4:52 PM Page 57
FIGURE 11. If you need additional height control for the skids FIGURE 12. The completed bottom deck of the ArdBot. Note the
or the hole for the skid cannot be threaded, use a longer 8-32 orientation of the servos in the mounts.
screw with hex nuts above and below the deck.
merely use a longer machine screw and tighten into place assure proper polarity. With just two pins, you must
using nuts on both the top and bottom of the deck, as be VERY careful to never (and I mean NEVER, EVER!)
shown in Figure 11. reverse the polarity of the connector. If you do, your
servos will be instantaneously and permanently
Step 5 damaged. By using (for example) a four pin
Attach the wheels to the servos. Each wheel is secured connector, you can block up one of the unused
with a small self-tapping screw that is supplied with the terminals. This helps prevent you from reversing the
servo. Note that the servo shaft is splined; this spline connector when you plug it in. (Of course, still be
matches the wheel hub. Be sure to press the wheel onto careful, no matter what system you use!) Insert fresh
the shaft firmly while tightening the screw. Do not over- batteries into the holders and attach the clip to the
tighten the wheel mounting screw, but be sure the wheel is nine volt battery. The holders with batteries are
on snugly. Figure 12 shows the completed bottom deck of shown in Figure 13.
the ArdBot, with motors, mounts, and wheels attached.
(Ive bound the wire leads for the servos using cable ties to Step 7
keep things neat. You can do the same if you wish.) Find a favored spot on the top deck for your Arduino,
and mark three holes for mounting the board. Be sure not
Step 6
Secure the side of the nine volt battery holder against
the side of the AA battery holder using a small piece of
double-sided foam tape or hook-and-loop (Velcro). Next,
secure the AA battery holder to the approximate center of
the bottom deck using a square or two of hook-and-loop to
keep it in place. Note the electrical connections for both the
nine volt battery and the AA battery holder:
SERVO 12.2010 57
McComb - Arduino Robot Part 2 - Dec 10.qxd 11/1/2010 4:52 PM Page 58
Listing 1 to cover up any of the four holes used for securing the top
deck in place. Otherwise, youll have to remove the Arduino
in order to take off the top deck
/*
ArdBot ServoTest Drill the three holes using a 9/64 bit. Secure the
Tests servos of robot by moving them in Arduino board to the top deck using 4-40 machine screws,
different directions nuts, and plastic washers. The washers go between the
Requires Arduino IDE version 0017 or later
(0019 or later preferred) heads of the screws and the board, and minimize the
*/ possibility of a short circuit.
Mount the mini solderless breadboard so that its close
#include <Servo.h>
to the Arduino, but doesnt block the 1/2 wiring access
Servo servoLeft; // Define left servo hole in the top deck. Though most mini breadboards come
Servo servoRight; // Define right with double-sided self-adhesive tape, I recommend that you
servo
dont use the tape. Instead, mount the board using a
void setup() square or two of hook-and-loop. This allows you to easily
{ remove the board when you need to.
servoLeft.attach(10); // Set left servo to
// digital pin 10
servoRight.attach(9); // Set right servo Step 8
to To complete the ArdBot, secure the top deck to the
// digital pin 9
} standoffs using 4-40 x 1/2 flat head screws. Assuming you
are using a soft material (wood, PVC plastic, foam board,
void loop() // Loop through etc.), the heads of the screws should countersink by
// motion tests
{ themselves as you tighten them and lay flush against the
forward(); // Example: move deck. Thread the battery and servo leads through the center
// forward hole of the top deck. To keep down cost and complexity,
delay(2000); // Wait 2000
// milliseconds there are no power switches for the batteries, so leave the
// (2 seconds) battery leads unattached until youre ready to program and
reverse(); use the ArdBot. (When youre done playing, be sure to
delay(2000);
turnRight(); unplug the batteries to keep them from draining.)
delay(2000);
turnLeft();
delay(2000); Two-Servo Wiring Plan
stopRobot();
delay(2000); The Arduino lacks direct connections for attaching the
} servo motors. Instead, the mini breadboard provides
// Motion routines for forward, reverse, turns, prototyping space for connecting up both servos, as well as
// and stop the AA battery holder that powers the servos. Refer to
void forward() Figure 14 (schematic) and Figure 15 (pictorial) for wiring
{
servoLeft.write(0); the solderless breadboard. Using a strip of 0.100 double-
servoRight.write(180); sided (long) male header pins, break off two sets of three
} pins, and one set of pins for the AA battery connection.
void reverse() Note that you want the version of male header pins
{ that are double-sided theyre long on both sides. If you
servoLeft.write(180); use the standard header pins, the length of pins on one
servoRight.write(0);
} side is shorter. These dont make good contact when used
with solderless breadboard designs. See the Sources box
void turnRight() for a couple of mail order companies offering double-sided
{
servoLeft.write(180); long header pins. In a pinch, you can use right-angle header
servoRight.write(180); pins instead and straighten them out so that all the pins are
} flat. The reference design uses a AA battery holder with a
void turnLeft() four-pin female connector. The + and leads are on the
{ two outside positions of the connector. Ive broken off the
servoLeft.write(0); pin right next to the + connection of the male header, then
servoRight.write(0);
} used a short piece of solid conductor hookup wire to fill in
its corresponding hole in the connector. This prevents the
void stopRobot() connector from being reversed when plugged in.
{
servoLeft.write(90); When wiring the solderless breadboard, be especially
servoRight.write(90); careful not to mix positive and negative leads to the servo.
} Reversing the power leads to a servo will permanently
58 SERVO 12.2010
McComb - Arduino Robot Part 2 - Dec 10.qxd 11/1/2010 4:52 PM Page 59
damage it. Heres an important FIGURE 14. The wiring schematic for the
note: The ArdBot uses separate Arduino with two servos and separate power
battery supplies for the Arduino supply for the motors.
and the two servos. In order for
everything to function properly,
the ground connections for the
Arduino and the servo battery
supply must be connected
together. This is shown in both
the schematic and pictorial
circuit views.
Make sure to also properly
orient the connectors for the
servos when you plug them
into the board. Servo power
leads are color-coded, but the
colors arent universal.
Ground () is typically
black or brown.
Power (+) is most often
red, and with modern
servos is always in the
middle.
Signal is white, yellow, or
sometimes orange (but
take care on some
servos the power wire is
orange!).
power to the Arduino power jack. (If you are using an
When in doubt, check the spec sheet that comes with Arduino Diecimila, be sure to switch over the power
your servos. Dont guess! selection jumper from USB to EXTernal.) If everything is
connected properly, the servo motors should go through a
Servo Test Sketch test pattern.
Assuming the motors are working as they should,
With the ArdBot constructed and the breadboard depress the Reset switch on the Arduino board and place
wired, youre ready to test the robot and put it through its the ArdBot on the ground. Release the switch and the
paces. Refer to Listing 1 for a quick servo test sketch. robot should perform its self-test maneuvers. If the motors
Start the Arduino IDE, connect a USB cable between arent moving, double-check your wiring, making sure the
your computer and the Arduino (as noted on the Getting servo connectors are properly oriented. They wont work if
Started pages of the Arduino website), and type the the connectors are reversed on the breadboard.
program as shown. When done, Verify
(compile) the sketch and look for any
syntax errors. If there are none,
download the sketch to your Arduino.
Once downloaded, put a small
book under your ArdBot to lift its
wheels off the ground. Disconnect the
USB cable, and in this order plug
the AA battery connector into the
breadboard, then plug in the nine volt
Sources ArdBot, lets quickly review how the test sketch works. First
off is an include statement to the Servo.h library header file
Arduino Parallax which is provided with the Arduino IDE installation. This file
www.arduino.cc www.parallax.com and its corresponding C language program, provide all the
Prefabricated ArdBot body actual coding to make the servos function.
pieces with all construction Pololu Next comes two statements that create, or instantiate,
hardware. www.pololu.com
two Servo objects for use in the remainder of the sketch.
Budget Robotics Robotshop Each object represents a physical servo attached to the
www.budgetrobotics.com www.robotshop.com Arduino. Methods of these objects include things like
AdaFruit Solarbotics specifying which digital pin is used to connect from the
www.adafruit.com www.solarbotics.com Arduino to the servo, and the position of the servo. Note
Ive given the two Servo objects descriptive names:
HVW Tech SparkFun
www.hvwtech.com www.sparkfun.com servoLeft and servoRight. Its easier to keep track of things
this way.
Jameco In the setup function, the servoLeft and servoRight
www.jameco.com
objects are wired to their respective pins on the Arduino;
Please note! The list of sources is not exhaustive, and is in this case, pin 10 for servoLeft and pin 9 for servoRight.
merely designed to get you started in the right direction. Now comes the main body of the program, provided in
There are other companies who sell these items, and not all
sources are listed. Common parts like battery holders and the loop function. It contains a series of user-defined
breadboard jumper wires are not included here, as they are functions for forward, backward, and so on, plus a delay of
readily available at RadioShack and hundreds of online 2,000 milliseconds (two seconds) between each function.
electronics supply stores.
Check out www.fritzing.com for a user-to-user Arduino You can see that the robot repeats the same demonstration
project community, including an Arduino development library steps over and over:
that allows you to create virtual breadboard designs of your
projects. You may then turn your projects into schematics and
even etchable circuit boards. Weve used Fritzing to prepare Goes forward for two seconds.
some of the illustrations for this series of articles. Reverses for two seconds.
Turns right for two seconds.
Turns left for two seconds.
Closer Look at the Test Sketch Stops for two seconds.
Before closing out this months installment of the Finally, each user-defined function specifies the specific
motion to apply to the servos.
With the Servo object, servos are
Main Components Sources commanded to move one
direction or another by (among
This is a selected list of North American Continuous Rotation Servo
sources for the main components for the other ways) specifying an angle
(Futaba spline)
ArdBot. between 0 and 180. The servo
Source Item or SKU
Parallax 900-00008 then moves to that angle in
Arduino Duo or Duemilanove Pololu 1248 response.
Source Item or SKU RobotShop RB-Gws-23 When using servos that have
Adafruit 50 Solarbotics 36000
HVW Tech 28920 (Freeduino SB) SparkFun ROB-09347
been modified for continuous
Jameco 2121105 rotation, 0 makes the servo rotate
RobotShop RB-Ard-03 one direction; 180 makes the
Pololu 1616 2-1/2 or 2-5/8 Rubber Wheels
SparkFun DEV-09950 (Futaba spline) servo rotate in the opposite
Source Item or SKU direction; and 90 makes it stop.
Solderless Breadboard; 170 tie-points Adafruit 167 Pretty easy, isnt it?!
Source Item or SKU HVW Tech/ In our next installment, well
Adafruit 65 Solarbotics SW
HVW Tech 21380 Parallax 28109 look at servo programming in
Jameco 2109801 Pololu 226 depth, as well as connecting some
Parallax 700-00012 RobotShop RB-Sbo-86 sensors to the ArdBot for reactive
RobotShop RB-Spa-139 control, getting feedback from the
Double-sided (long) Male Header
Nine volt to 2.1 mm Barrel Plug Pins robot, and more! SV
Cable Source Item or SKU
Source Item or SKU Parallax 451-00303
Adafruit 80 Pololu 1065 Gordon McComb can be reached
SparkFun PRT-09518 at rduino@robotoid.com.
60 SERVO 12.2010