SERVO 11.2016 27
system. In the real world, being close is good enough.
As the HMC5883L module measures extremely small
variations in the local magnetic field, it should be kept as
far away as is reasonable from:
For Berry, I mounted the HMC5883L module on a small
prototyping board that had a 3 mm hole, and mounted the
prototyping board about 2. 5” above the robot chassis using
Correcting for Magnetic
You might be surprised to learn that compass needles
do NOT point to “true north,” but instead point to the local
“magnetic north.” There can be a significant difference
between true north and magnetic north. True north is the
direction along the Earth’s surface that points towards the
geographic North Pole. True north is represented on maps
and globes by lines of longitude. Magnetic north can be
defined as pointing to where the horizontal component of
the local magnetic field points. Go to www.geomag.
nrcan.gc.ca/mag_fld/magdec-en.php for an excellent
Fortunately, there are sites that allow you to determine
the magnetic declination for your location on the surface of
Earth, thus allowing you to correct for the difference
between magnetic and true north. Refer to https://en.
www.magnetic-declination.com for more details.
I will add an ADXL345 module and code to
compensate for tilt in the next article in this series.
IR Distance Sensor and Nine
Gram Standard Servo
A Sharp IR range sensor provides us with the ability to
“see” how close Berry is to the nearest object, and the nine
gram servo allows us to pan the range sensor a full 180
degrees in front of the bot. (Refer to “Serving Raspberry Pi
#4” in the April 2016 of SERVO Magazine for more about
USB and 4xAA Battery Packs
Berry is equipped with a Patriot Fuel+ 5,200 mAh USB
battery pack, which can run the electronics for over four
hours — including Wi-Fi. The motors are currently powered
by four AA cells.
Until Next Time ...
You can download Berry’s demo code at the article link
or at www.mikronauts.com/robot-zoo/berry-4wd-pi-
robot. Berry can move around with the same simple motor
commands as Hobbit from the June 2016 article. Heck, you
could add the same joystick code if you wanted to drive
Berry around! However, the real fun will begin when he can
start mapping the floor in my home office.
Next time, I’ll add tilt compensation code for the
compass, and maybe get us started on indoor localization
by getting Berry to map my office floor. SV
PHOTO 8. Berry Bot's eyes.
PHOTO 9. Berry's batteries.