It’s been a busy couple of weeks in Arduino-land. When I realized gloomily that my sewable GPS project was having some major power issues, I decided to move my project back to my larger, decidedly un-sewable Arduino board. Since the whole idea behind the project was to create a portable GPS-based game (in the vein of childhood favourite “hot and cold”), it seemed like a fun idea to house the whole thing in a squishy enclosure that looked nothing like a traditional GPS unit. Enter the toy store.
While browsing the aisles, I came across a display of very cuddly-looking creatures. Some didn’t have the body cavity space to house a whole Arduino board and battery pack. Others were huge. One was perfect. So perfect, actually, that it inspired a completely separate project. Six dollars later, I had a charming penguin. Sixty minutes later, his stuffed innards were all over the kitchen table.
Weeks ago, I had borrowed an HMC6352 compass module from Bill’s lab with the intention of using it in tandem with my GPS module to provide some directional clues to game participants (without a compass, the device could only calculate its distance away from its target location, not the direction a person would have to travel to bring them closer together). My busy library school schedule had unfortunately limited the time I had to develop this idea further, and the compass was left sitting idly in its plastic bag.
When I saw the penguin toy, two thoughts occurred: (1) An adequately-sized body cavity! and (2) Penguins live in the SOUTH.
Since compasses can detect their orientation relative to the north pole, coding something that would react when the compass was pointing 180° away from north seemed easy enough. My first step was liquidware’s compass sensor library for Arduino. While a few compass libraries are floating around online, this one comes with a handy calibration sketch that makes setting up the device a lot easier (I spent a few hours exploring the alternatives without a lot of luck, and boy did the compass require calibration!). At any rate, calibrating the device required running the sketch, opening the serial monitor, entering some commands according to the directions provided, and rotating the compass a full 720° on a flat surface. I used a third hand tool to keep it parallel with the tabletop while rotating since the header pins connected to the device preventing me from setting it flush against the surface.
Once the compass started returning plausible headings, I moved on to coding. The whole thing relied on a very basic IF/ELSE statement within a loop. If the heading returns a value between 170 and 190, turn on the vibe board. If not, don’t!
#include <Wire.h>
#include <LibCompass.h> // liquidware's compass sensor library.
// See https://github.com/liquidware/LibCompass
int vibePin = 10; // One end of the vibe board is plugged into Pin 10.
LibCompass compass = LibCompass(0);
void setup() {
Serial.begin(9600); // Start a serial connection with the computer.
pinMode(vibePin, OUTPUT); // Set the vibe board pin as an output.
}
int c;
void loop() {
c = (int)compass.GetHeading(); // Set the value of c to the heading reading.
Serial.print("Heading: ");
Serial.print(compass.GetHeading()); // This part just prints the heading.
Serial.println(" degrees");
if (c > 170 && c < 190) // If the heading is between 170 and 190...
{
digitalWrite(vibePin, HIGH); // Vibrate!
}
else // If it isn't...
{
digitalWrite(vibePin, LOW); // Don't vibrate!
}
delay(10); // Compass manufacturer-recommended delay period.
}
Once everything was working well, I smushed the whole thing plus battery pack into the penguin. This video, filmed just before everything went inside, shows all of the electronic penguin guts and how the compass and vibe board work together.
Overall, I’m really happy with the final product. Even though the penguin is subject to many of the pitfalls of these types of compasses (if the compass isn’t parallel to the earth’s surface, the heading readings are a little wonky, for instance), assembling the toy was a great stress reliever and fun way to wrap up the course. *
* Fans of the GPS game need not worry! I’m hard at work thinking up more interesting enclosures for that project too.














