FIGURE 4. Robbie following a line.
You can either draw the walls with
lines, or just draw a central single
line wide path for the robot to
At this point, Robbie can now
also follow lines or avoid them. But I
want Robbie to be capable of even
more ... especially on his own!
Adding a compass
There are a lot of compass
modules for sale these days, but
after researching the integrated
circuits used on them, I ended up
choosing an HMC6352 module. This
small, simple module is capable of
self calibration and has one degree
repeatability. Even more importantly,
it communicates via a standard I2C
Parallax was out of stock when I
wanted to order a module, but fortunately SparkFun had
one based on the same chip.
Figure 5 shows the compass module on Robbie.
Now you know what the four-pin header was for. I
added the small prototyping board with the IR remote
sensor on it earlier, drawing power from the I2C expansion
header because I knew I would also be adding the
Since RoboProp has an I2C expansion header, adding
the compass was very simple:
number of specified degrees.
• Wire up a small converter PCB as the I2C pinout on
RoboProp differs from the module.
• I added the Parallax HMC6352 object to the RoboProp
library, and wrote Calibrate and GetHeading functions.
If we combine the data from the compass and the
wheel encoders, it becomes possible for the robot to
navigate in its environment with fairly decent precision.
With the addition of a distance sensor, the robot can
even be programmed to generate maps of its
environment, and with further programming, it will be
possible for a robot to recognize what room it is in and
plan its route to different locations in different rooms,
however, such mapping and route planning is beyond the
scope of this article.
adding a range sensor
Initially, I got unexpected results — the heading
jumped around too much. After doing some research, it
turns out that there was a known bug in the Parallax
HMC6352 object, and the suggested solution was to slow
down the I2C access rate. After a bit of sleuthing in the
code, I found the problem — the code needed an
additional delay between reading the two bytes of the
response, so I added a small delay and voilà! No more
corruption of the first bit in the second byte of the
heading! (You can download the fixed HMC6352 code
Now, why did I want to add a compass? There are
• Know what direction the robot is facing in.
• Be able to turn to any compass heading.
• Be able to precisely turn left or right by the
Remember the front virtual bumpers and line
sensors we added to Robbie? The SirMorph sensors are
actually short range infrared distance sensors, but their
range is too short for use as a "radar" style range/distance
sensor. Currently, the most popular sensors used for
robots for measuring distance to the nearest object are
based on either infrared light or ultrasonic sound. One
of the most popular ultrasonic sensors is the Parallax
SERVO 10.2011 45