Eventually we all want to know just where our robot is, so we can choose an absolute direction. Usually this type of device is quite expensive. However to our rescue comes [url=http://dinsmoregroup.com/dico/]Dinsmore[/url] with low-cost electronic compass module. It outputs the four cardinal points and combinations thereof that will give eight directions. I decided that combining this with tilt sensors (the Dinsmore compass will only work if not tilted more than 12 degrees) would be a cool project. I am using a PIC 12C508 to do the dirty work and return an 8 bit number with the directional and tilt data all included. Here is the schemo that I am working with, I haven’t yet found tilt sensors that I like so only the compass part has been implemented. Download from below the PIC source code for the 12C508 that will return the direction as a number from 0 to 7 in a single byte number at 2400 baud when the trigger line is cycled from a 1 to a 0 and back to a 1. Here is a Parallax Basic Stamp II program written to test the compass (download below as well). It has the compass connected to Port 2 and an LED connected to Port 0.
The compass works by sensing the active low reactions of the Hall Effect sensors and arranging them arbitrarily on the “map”. The “<<” on my PC boards is the direction of the front of the robot, when THIS part of the board is facing North, the compass will return a 0; 1 through 7 are returned as you go around the compass to the East, South, West, etc. in 45 degree increments. So, your main controller can just multiply the number returned by 45 to get the compass points in degrees. The PIC takes two readings 1/3 of a second apart, if these readings differ it means that the compass hasn’t settled yet. It will set bit 6 of the returned byte to show this along with the number of the last reading taken. For instance, if you are transitioning from North to North East, it will return 0x41, if you have settled on North East, it will return 0x01.
The nice part about this design is that a single line is used to start the reading and then read back the results! Very convenient, in my opinion. Below is the schematic, the PC board layout and a picture of how it looks.
Copyright 2006 [url=http://users.frii.com/dlc/robotics/botlinks.htm]DLC[/url]