7.f. Coordinating turns with the compass

This example program demonstrates using the Zumo Shield’s 3-axis magnetometer (described in section Section 3.d) to help the Zumo coordinate ninety-degree turns and drive in squares. With the Zumo Shield Arduino library installed, the sketch file can be opened in Arduino by selecting File > Examples > ZumoShield > TurnWithCompass.

Because the batteries, motors, and motor current affect the z axis of the magnetometer much more strongly than the x and y axes, this program calculates the Zumo’s orientation using only the x and y readings from the magnetometer, assuming that the robot is always level. In order to prevent external, locally varying magnetic fields (e.g. from rebar in a concrete floor) from affecting the Zumo’s navigation too much, the program measures the magnetic heading before each turn, then turns ninety degrees relative to that heading.

Related Products

Zumo Reflectance Sensor Array
Zumo Shield for Arduino, v1.2
Zumo Robot Kit for Arduino (No Motors)
Zumo Robot for Arduino (Assembled with 75:1 HP Motors)
Zumo Shield for Arduino, v1.3
Log In
Pololu Robotics & Electronics
Shopping cart
(702) 262-6648
Same-day shipping, worldwide
Shop Blog Forum Support
My account Comments or questions? About Pololu Contact Ordering information Distributors