Message #4281 - comp.robotics Date: 04-07-93 18:01 From: Michael Fulbright To: All Subject:: Ultrasonic Rangefinders - My personal experience ------------------------------------------------------------------------------- I have built a working ultrasonic rangefinder for a few bucks and I thought I'd share my experiences. I also have some questions which hopefully someone can answer. I got most of my ideas from the book 'Robotics Bonanza: 99 Inexpensive...' which most readers have probably seen. The ingredients for my rangefinder were 1 Pair of Ultrasonic transducers (an transmitter and a receiver) 1 NE555 timer chip 1 NE567 Tone detector 2 741 op amps Various capacitors and resistors. The toughie was finding ultrasonic transducers. All Electronics had a set with a Panasonic transmitter and receiver for $2, so I bought a couple. I drive the transmitter directly from the output of the 555, which is set to run at approximately 40 khz. I have a pot hooked up so I can fine tune the frequency. The duty cycle of the 555 output is pretty close to 50%. Setting up the transmitter is pretty straightforward, but since I can hear above 15-17khz its impossible to know if anything is really happening at this point. The receiving part of the rangefinder is composed of an ultrasonic mike which is AC coupled to a 741 op amp set up as an amplifier with a gain of approximately 100. The output from this 741 is amplified by another 741, but by a smaller gain. This output is fed to the 567 tone decoder via a pot so I can control the amplitude of the signal going into the 567. The 567 is set for 40 khz, so I can detect when the signal from the transmitter is being received. At this point I have a question - is there a better (though similarly inexpensive) way to achieve a high gain (>1000) than by chaining two amplifiers one after the other? I know if I set up one op amp with a gain of 10000, for example, I will most likely have oscillation problems. My circuits are almost straight out of the Bonanza book, so if you dont have this book and you are interested I can try to make an ASCII version. I found it fairly easy to tune the circuit. I just set up the transmitter and receiver facing each other and tuned the 567 until its output dropped to 0V, indicating that it had locked in. Be sure to put a pullup resistor to +V on the output of the 567. The ultrasonic mike I used apparently has the best response near 38khz, so I adjusted my circuit to work at that freq. I discovered that the circuitry described so far makes a good motion detector. This relies on the fact that the lock-in freq range of the 567 is depends upon in the amplitude of the incoming signal. The lower the amplitude the tighter the lockin range. If the frequency of the incoming signal strays too far from the frequency the 567 is tuned to the the output from the 567 goes from 0V to +V (assuming you have a pullup resistor). To make a motion detector one first needs to lower the amplitude of the signal going into the 567 until one loses lock in. I accomplished this by using a pot between the amplifier stage and the 567 input. When you have lost locking turn the pot back until you achieve lockin again. The way I set things up is shown below: ___ | \ <- Transmitter | | | / --- ___ | \ <- Receiver | | | / --- If anything is withing a few feet in front of the xmitter then the 567 should achieve lockin. Now move your hand towards and away from the xmitter. The frequency of the reflected signal will be Doppler shifted away from the frequency the 567 is tuned for and the 567 will lose lockin. When adjusted correctly I found this to be a very sensitive detector, and it only costs a few bucks to build. Back to rangefinder. In order to measure distance I need to turn on the 555 for a brief interval, then monitor the 567 output to see when the reflected signal returns. Sound travels about 13,030 inches per sec, so to measure something a couple of inches away one needs to be able to monitor the 567 output at least 13000 times a sec. And the output pulse needs to be short so you can detect multiple reflectors. If the pulse were a second long, say, then the returning signal from the closest reflector would drown out reflections from farther away objects. But the output pulse needs to be long enough so that the 567 can achieve locking, which takes of order 10 cycles. At 40khz, 10 cycles take .25 msec. I chose to use the parallel port on my 386 to control the 555 and monitor the 567 output. In a robot with an embedded controller one just needs a digital output and input. I hooked the RESET pin (pin 4) on the 555 to a TTL output from my LPT1 port on my 386. If this pin is set to GND then the 555 output (pin 3) is set to GND. BTW, if you try this be sure that you are running the 555 off of +5V and GND, not some other voltage like +12V or +9V. You may need some interface circuitry between the output on the parallel port and the 555 if that is the case. If pin 4 is brought up to +5V then the 555 oscillates at whatever frequency you've set it for. So I turn the 555 on for a few hundred microseconds, then turn it off. I monitor the output from the 567 with one of the input lines on LPT1. Be sure to use a pullup resistor on the 567 output. When the 38khz signal is received by the 567 the output will go from +5V to GND. Currently I poll this input and store the readings into an array, but one could tie the 567 output to a line on the parallel port which can trigger an interrupt. Currently I plot the output of the 567 versus time. Since sound travels 13,030 inches per second under standard atmospheric conditions, I can make my plot have distance on one axis and 567 output as the other. To calibrate this one needs to time how long one reading from the 567 takes. I did this by timing how long it took to take 2e6 readings, which was 5.5 seconds. BTW, this is all done with MSC 5.1, no asm so far. The results - the current setup can easily detect walls, chairs, trash cans, cats, feet, etc out to 5 feet with little trouble. I estimate the accuracy to be to a few inches. Part of the problem seems to be in how the 567 works - it appears to take several cycles before it locks in. At 40khz one cycle corresponds to about a 1/3 of an inch, so if it takes a couple of cycles to lock in this corresponds to 1 inch or more. The problem I'm having is that if I point the rangefinder at a wall and take continuous readings, the distance to the wall jitters around by a an inch or 2. I'm wondering, however, if this has to do with how I turn the 555 on and off. I don't have an oscope, so maybe someone can tell me - does the 555 have alot a strong transient response when it it turned on, or does it take less than 1 cycle for its output to stablelize? If it takes a few cycles to get started then this may explain why sometimes the 567 locks in earlier than others. To take things one step further, I mounted the xmitter/receiver pair on a platform attached to a 100k pot. The pot is hooked up to the game port on my PC so I can read its angular position with an accuracy of 3 deg or so. I then rotate the platform (by hand currently, by a stepper motor in the future) to different angles and get a set of readings at that angle. This way I can sweep out a map of obstacles somewhat like a radar screen. One problem is the field of view of the setup is somewhat large, so the angular resolution leaves something to be desired. A few observations - unless the reflecting object subtends a large angle in front of the xmitter, you can usually get multiple reflections. This is encouraging to me, as I think it should be possible to make a map of nearby objects out to 5 feet, say, and navigate based on this info. Also, since it only takes a few msec to take a reading in a given direction, one should be able to map out 180 degrees fairly quickly. Since the field of view of the receiver is large (around 60 deg), there is not much point in scanning in 1 deg steps. So it shouldnt take more the 5-10 sec to scan a 180 360 sweep. The main problem I'm having is that I get echoes from 1-6 inches and I don't think they are real. Either the transmitter peizo element keeps oscillating a fraction of a msec after I turn off the 555, or the 555 doesnt stop immediately. I have the ultrasonic xmitter and receiver mounted right beside each other. How are things arranged in commercial units? Is there some sort of sound absorbing material between the two? I'd like to be able to detect objects less than 6 inches away, although the LED proximity detector I plan on using should detect these objects. Again, I have no oscope so I can't really see what is going on with the 555 output. Any help here is welcomed. Finally, I have set up several receivers and xmitters and driven them all with one 555 and decoded the output with one 567 circuit. This is nice since you only have to tune one circuit. The catch is you canonly use one transmitter/receiver pair at a time. I switch the various xmitter/receiver pairs to this circuitry with an analog multiplexer. One has to be sure that the multiplexer can handle the 555 output current to the xmitter, a transistor driver may be needed. With this setup I can add sensors all over my robot for $2 each (the cost of the pair from All Electronics). This post is longer than most but I was so excited over how easy it was to add ultrasonic rangefinding to my robot I thought others would be interested. I havent seen any writeups on the net on this subject so hopefully this will help interested people. If you have any experience with rangefinders I'd be curious to have any comments on my design. And if you want to know more about what I've done send email. Once I get things in a 'final' form I'll post a schematic and parts list, as well as more detailed instructions. Michael Fulbright msf@as.arizona.edu