The digital compass we are using is not a high precision instrument but nevertheless it can discern 8 distinct orientations: N, NE, E, SE, S, SW, W, and NW. The compass has four terminals that behave symmetrically. If the compass is pointing in one of the cardinal directions then that terminal will be low and the other three terminals will be high. For example, when pointing south, only the south terminal is low, the west, east, and north will be high. The other four directions the compass can identify lie between the four cardinal directions at NE, SE, SW, and NW. To indicate when it is pointing in these directions, the compass will have two terminals low and two high. For example, if it is pointing NW then the north and west terminals will be low while the south and east terminals will be high. Therefore, either a single terminal is low or two consecutive terminals are low. There will never be three or four terminals low simulateously. An LED can be connected to each terminal to help in understanding the operation of the compass and in debugging. When one terminal points south, the corresponding LED will be on. When the compass points in a 45 degree direction, two LEDs will be on.
Each of the four terminals really consists of 3 leads for a total of 12 pins on the compass. Each terminal is simply a three terminal transistor that reacts to the magnetic field of the Earth. The leads are:
Figure 1: diagram of compass and the detail of connections to one of the four 3-lead terminals.
Try to answer the following questions with your compass:
The sonar range finder
The sonar range finder will be used to determine the distance to the closest object directly in front of it. The transducer of the sonar is the black perforated disk with a metal disk behind it. (Note: a transducer is a device that converts signals from one form to another, in our case, from electrical to sound and vice-versa.) The disk generates the sound and vibrates to the echo. The small board that accompanies the disk is its controller. It generates the sound given a rising edge on a digital input and detects the echo by providing a rising edge on a digital output. There is interesting analog circuitry on the controller board that charges up the transducer to the high voltages needed to both generate and sense ultrasound.
The sonar device sends out 16 pulses at 49.5 kHz that travel from the disk and reflect off of the objects in front of it. The first echo to return (from the closest object) is used to raise the output signal. The range finder is started by raising the INIT signal. When the echo returns the ECHO signal goes high. INIT has to stay high at least until ECHO goes high. The sonar board operates this way in the mode you will using (when both BINH and BLNK are low). See the controller board documentation for the other modes of operation it supports.
Make sure to be careful in handling the board. The device generates high voltages on the controller board and at the transducer leads (in the range of 200 to 400 volts). Touching the sonar circuit board while it is powered up and/or operating might give you an uncomfortable burn.
The interconnect to the sonar range finder board is (pin 1 is closest to
J1 on the sonar board):
purpose | gnd | BLNK | INIT | ECHO | BINH | Vdd |
pin / voltage | 1 / 0V | 2 / 0V | 4 / Input | 7 / Output | 8 / 0V | 9 / 5V |
The connections to the sonar transducer (see transducer documentation) are:
E1 on the sonar board --> (+) brass tap on black disk
E2 on the sonar board --> (-) black tap on black disk
The ECHO output is an open collector output like the terminals of the compass (see the figure below).
Figure 2: Schematic diagram for ECHO output including pull-up resistor size.
Try to follow procedure to make sure that your sonar is working properly. Connect INIT to high to start the range finding operation. You should hear a scratching, which is the transducer sending off the 16 pulses. In addition, ECHO goes high immediately. Reset the sonar range finder by making INIT low and ECHO should go low as well.
Your can find more documenation about the sonar range finder at:
The compass can easily be tested with hyperterminal using
MD <address of input port register>(MD is explained in the User Manual). When the compass is rotated, the value stored at that memory address should change.
You will have to write a small C program to test the sonar range finder. The program should measure the time between when the INIT signal goes high and when the ECHO signal goes high. Make several measurements to see if the readings make sense (i.e., try out objects or walls at different distances).
NW 3You can round off to the nearest foot.