Sonar Sensor for the MiniBots 1999 
[ Homepage ][ Send me mail ] © Kam Leang

1  Introduction
Sonar sensors are very useful for robot projects, but the price of commerically available systems such as the Polaroid Modules ($50) can put a dent in your pocket. The following article introduces a cheaper alternative to range finding with acceptable performance, though not as robust and reliable as the Polaroid Modules, but hey, you get what you pay for! The circuit is simple and can easily be constructed for about $15.00. The information I'm about to present will be short and to the point and will require some patience on your part if you're going to build it. The circuit diagrams below show both the transmitter and receiver system for the sonar ranging system.

2  Theory of Operation
This is a simple system. The transmitter emits an ultrasonic signal (40kHz). The 555 timer chip of the transmitter provides the driving 40kHz signal. Every time the reset pin (pin4) of the 555 timer goes high, a resulting signal of 40kHz on pin 3 is used to drive the ultrasonic transducer. Then, the receiver simply listens for the return echo after it bounces off an object. The small echo signal, when detected, is amplified 1000 times using a standard operational amplifier (LM741 op-amp). The signal is then fed into a tone decoder (LM567) set to lock onto a 40kHz signal. The output of the tone decoder is HIGH when no echo is heard and swings LOW when an echo is detected. The output from the tone decoder can now be fed into a microcontroller or some other type of IC to determine when an echo was received.  To help minimize false triggering, the output is fed into a voltage comparator set to trigger at the appropriate level. The LED at the output of the comparator acts as a visual indicator when an echo is detected (very useful when debugging).   The typical range of this system is from a few inches to 5-6 feet, depending on the quality of the components, shielding, and most important, tuning.

3  Construction
Follow the schematic above and build a prototype of it on a solderless bread-board.  Most of the parts are available from Radio Shack except the LM567 tone decoder and the 40kHz ultrasonic transducer.  You can substitute other parts such as the op-amp and the voltage comparator for other models if you wish, but try to get the best quality parts.  I chose to use the cheapest and the performance was satisfactory, but higher quality components might make a difference--so experiment!  The transducers can be purchased from Hosfelt Electronics for about $3.50 (part number on the schematic).  The LM567 tone decoder is available from JDR Microdevices or similiar supplier for about $1.00.

Build the transmitter section first. Using an oscilloscope or frequency counter, set pin 4 HIGH and adjust R1--trim potentiometer-- until you get a 40kHz signal on pin 3 of the 555 timer chip. Try to use a trim pot for R1 because it will allow higher resolution in terms of adjustments. One thing to note: add plenty of bypass capacitors on the power supply.  Minimize the effects of noise as much as possible.  I used 100uF, 0.01uF and 0.001uF by-pss caps on the power supply.

Next, build the receiver circuit.    The schematic is straight forward.  Again, use trim pots for R2 and R3.  Add bybass caps where appropriate.  Once the receiver is completed, tuning is required. Again, using an oscilloscope, adjust R2 until the signal on pin 5 of the LM567 is 40kHz. The frequency measured on pin 5 indicates the lock-on frequency of the tone decoder. Next, adjust R3 such that the voltage on pin 3 of the LM311 is at about 2.5 volts. This voltage level causes the output of the LM311 to only swing LOW when the output from the tone decoder is less than 2.5 volts. In the end, you'll have to fine tune this value, but this is a start.

4  Putting it All Together and Testing
Finally, take both transducers (transmitter and receiver) and wrap them with some rubber or similiar material to help damp out crosstalk and place them facing the same direction, but at about 1" inch apart (refer to the Minibot figures above). If everything is tuned properly, you should notice the LED light up when you place an object in front of the transducers (i.e. wave your hand in front of them). By tuning R1, R2 and R3, you can adjust the sensitivity and range of your new ranging system. The best debugging technique I've used for this system is to watch the output signal of the LM567 (pin 8) and LM311 (pin 7). If you use a digital oscilloscope, you should be able to capture the time it takes for the transmitted signal to return (echo) and freeze it to determine the lag time. The diagram below shows what the signals should look like. Study the signals and make sure you know what's happening before you attempt to debug, otherwise it's like hearding cats!

5  Software
I've included sample ASM code for the sonar sensor for the 68HC11E2 (BotBoard).  Unzip the file sonar.zip and compile it to .s19 format.  I used Rapid to compile the programs and it supports header (*.h) file reference (see cod), so you might have to tailor the sample code accordingly.  The main program is sontst.asm.  The rest of the files are referenced by sontst.asm.  The sonar routine (sonar.h) is a bit inefficient but works.  Being a mechanical engineer, I lack the ability to write good software, therefore hack my way, but you get the idea!  I'm sure that a more efficient and compact form can be written, so play around with it.  Pin connections between the sonar sensor and Botboard are included in sontst.asm, so read it carefully, otherwise you're in for a world of cat hearding bliss.  Please update me if you find errors or have a better solution.  Thanks and Good Luck!!!

Download sonar.zip

6  Acknowledgements
I'd like to thank everybody out there over the Net and all the robotics builders who have provided information in one form or another to make this howto article possible.  Thanks and happy robot building!!