We are asked by several people how to create a geo based puzzle using A-blocks. Inspired by the wonderful project
The Reverse Geo Caching Puzzle from Mikal Hart some people want to make their own puzzle.
If you did not read the story yet make sure you do before you continue. Since we want to promote creative thinking we did not want to copy the project. So in this tutorial we are handing you the basic blocks to get you started and challenge you to build upon the idea
and create your own extended geo based puzzles.
Let's start with the hardware blocks. This is a simple task since all blocks we need are already available on A-blocks. We are using the following parts:
- Arduino Duemilanove
- A-Blocks interface
- Button & led module
- Servo module
- Serial lcd
- GPS receiver EM-406A
- Connection cables
Build and connect the modules using the instrucions and tutorials on this site. I you are using the Sparfun LCD use this
tutorial.
For a Parallax LCD use this
tutorial. The GPS is explained in this
tutorial.
In this tutorial we connected the modules as follows:
| Button & led module |
Digital port D3 |
| Servo module |
Digital port D5 |
| LCD | Digital port D4 |
| GPS receiver | Digital port D2 |
Using GPS position
Most puzzles would want to use a distance to a certain location. To decode the GPS info and calculate the distance we use the
NMEA library from Maarten Lammers.
This very nice library can not only calculate the distance to a certain point but also direction and speed. The code below shows you how you can get and display
the distance to a coordinate.
// check if data from GPS available on Serial1 port
if (gps.available() > 0 ) {
// check if full sentence recieved from GPS
if (myGPS.decode(gps.read())) {
// display distance to destination in meters
lcd.print(0x86, BYTE); // Move to 6,0
lcd.print("DIST:");
lcd.print(round(myGPS.gprmc_distance_to(dest_latitude, dest_longitude, MTR)),DEC);
lcd.print("m");
// display GPS positioning status ('A'=active, 'V'=void)
lcd.print(0xA3, BYTE); // Move to 15,1
lcd.print(myGPS.gprmc_status());
}
}
The LCD code in this example is based on the parallax LCD. You need a valid satelite fix so depending on the sensitivity of your GPS you need to be near a window or outside. If you use the EM-406A you can watch the onboard LED to see the status.
If the LED is on it is searching for a signal. If the LED is blinking it has a position fix.
Using the servo motor
The servo motor can be used to open a box or add another mechanic effect. The code for this is simple. We add a servo to the A-blocks servo controller motor 1 connection and use the following code:
ServoTimer2 Motor1;
// The actual position depends on the servo you use
// For our servo position 0 is 0 degrees
// and position 2000 is 300 degrees rotated
void turnServo(int position)
{
Motor1.attach(0);
Motor1.write(position);
delay(2000); // Allow the servo to turn
Motor1.detach();
}
Battery power
We want the puzzle to be mobile so we need to run it on battery power. Our first tip is to make the batteries accessible without having to open the puzzle enclosure.
This way you never have to worry that the puzzle gets ruined if the batteries run empty.
You have several options when it comes to managing your battery usage:
Option 1: Use a on/off switch
This is the simplest. The on/off switch turns the Arduino on or completely off. The disadvantage of this method is that the battery gets drained in a short timespan if the user
forgets to turn off the device. There is no way to power off the device from your code. If you have replaceable batteries that are accessible without opening the puzzle enclosure
then this does not have to be a problem. The second thing that you have to keep in mind is that you pobably want to keep track of the state of the puzzle. You can use the onboard EEPROM
memory of the Arduino to do this.
Option 2: Use sleep mode
You can also put the Arduino in sleep mode when not in use. Unfortunatly the Arduino power regulator will keep using about 10 mAh. This means that if you use 4 AA batteries as power supply then
it will take about 10 days before your batteries are empty. With this option the puzzle state is maintained automatically as long as the batteries do not run out. Since there is is no
guarantee that the batteries do not run empty it is still probably best to save the state in EEPROM. You can also combine option 1 and 2.
Option 3: Use a low drain power switch
This option is nice because you can switch off the power from your code. The power switch itself uses very little power so your batteries last for years when your puzzle is not powered up.
This option also requires you to save the puzzle state in the EEPROM. This powerswitch from SparkFun can do the job
Pushbutton power switch
The puzzle code
We have handed you some basics and the rest is something for your own creative mind to make up...