Let's Make Robots!

Cheap Sonar

One of the most important parts of a robot is it's sensors. If it cannot sense it's surroundings then it cannot respond. Unfortunately good sensors are usually expensive. For this reason I am always experimenting with cheaper home made alternatives such as my light up antenna, conductive foam touch sensor, IR obstacle detector and my not so successful laser range finder.

I have found that IR sensors are not the most reliable as they are affected too much by daylight. Sonar is more reliable but still has problems with soft objects such as curtains.

When Dagu added their asuro sonar to the components it got some attention because of it's low price. Dagu had already sent me 2 to experiment with but the design had extremly limited range and was not easy to interface with picaxe processors.

Dagu has asked me to design a cheap sonar that will address these problems especially as the cost of currently available sonars makes them poor choices for mass producing LMR robots.

I have succeeded in creating a sonar based on the LM324 quad op-amp which is a relatively cheap IC ($0.25 US from futurlec), a few capacitors and a handfull of resistors.

So far it can detect a broom handle at up to a meter and a dvd case at about 2 meters. A wall at over 3 meters. The schematic below is my design so far. Only the reciever has been tested as I was using a transmitter from a previous version.


For those wishing to build their own I am using prices from Futurlec as a guide since they are cheap and deliver world wide. A pair of long range ultrasonic transducers will set you back $3.90 US. The rest of the components including the IC less than $3 US (use metal film resistor and polyester film capacitors as they are more accurate). A circuit board is the only other thing you'll need. Prototype boards cost about $1.50 to $2 US but can be cut down to make several sonars. If your really on a tight budget then use cardboard.



I was expecting to have this all finished today after everything was going so well with the reciever. But Fate is a fickle mistress and today she stuck her foot out as I went by and laughed as I fell :(

Part of the problem was I didn't have the timing capacitor I needed and I tried working with different values. I also suspect that having components pushed into a breadboard is not as reliable as components soldered into a PCB. I'll sleep on it and try again tomorrow.

Sorry CTC, you'll have to wait a little longer. Perhaps Fate will be in a better mood tomorrow.


After much trial end error I succeded in getting my fourth amplifier to drive the output transducer at 40Khz but due to limitations of the LM324 I could not get the output past 3Vp-p so I have now used a slightly improved versions of my original transducer driver at the cost of an extra IC (also 25c US from Futurlec). This now gives me almost the full 5V of the supply peak to peak and the frequency is less dependant on the supply voltage for better reliability.


I will test this new design tomorrow when I get a 74HC00.



Well my car had a bad leak in the power steering and is only just back on the road. I've just got the 74HC00 and haven't had a chance to test it yet. Some may prefer to use a 555 timer instead. It doesn't really matter. You could even drive the transducer directly via PWM from the processor.

I only added the oscillator because for picaxe users, the PWM commands use the same timer used for servo commands and because only certain pins can be used for PWM. I figure if it is easy to use with picaxe and it's slow basic language then it is easy to use with any processor and any language.

When I have it working with a picaxe then I will post video and code.




I am still finding ways of improving the design so be patient. I am happy with the range overall and am focusing on eliminating noise for a more reliable reading.


The 120pF capacitors in parallel with the feedback resistors help filter out the noise. I am still experimenting with the design at this point. The first video shows this circuit working but with only one of the three filter capacitors. I'll have to get more caps.




40LT12_spec.pdf290.75 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
I've been busy lately and haven't had time for the final test with a picaxe. So far I've only had it working on the oscilloscope. Without seeing your program I can't say why except that the signal is very quick, an object 3m away bounces the signal back in about 20mS so unless you use the pulsin command then your code will be too slow to read it. Picaxe basic is extremely slow.
You know when you get married you have to give all your groom's men a small present. Well, you are not getting married but a substantial life change indeed. It only seems fair with some of us "originals" around here that we have been/will be and continue to be your wingmen. So I say, stay with this marrage theory... Once you get to china, send us all a sample or two or five, would ya? --Just as a small token to prove that we are all not going to loose touch... I mean, not that any of us are cheap bastards looking for freebies or anything.. Really it's all about the Great Life Journey and friendship...  ...Really.

I'll still be on LMR every day. As for freebies, wait and see or better still dress those chicks in paper robot outfits and video them :P


I might as well sell off my camera now! Any takers?
Dress up as a robot and robot dance :P

oh ok i see. i dont have a picaxe though. im using a 16f84 at 4Mhz. i use it for all my programming and it has yet to let me down.

on the output of the receiver, the voltage decreases the closer you get, is that what it should do? because im if so then im not sure what you mean by ...."The last stage of the reciever is a comparator that give a digital output so that you will get a brief positive pulse that is extended slightly by the diode and capacitor on the output."....i understand the diode cap combination. but not the brief positive pulse part.

I have to assume you are trying to measure the output with a multi-meter. This is pointless as the sonar does not work this way.

The comparator compares the signal from the reciever to a voltage that is set just above the noise level. When the initial burst or an echo is detected the signal jumps above the noise level and the comparitor generates a positive going pulse.

Your processor must generate a high output for about 300uS (enough for about 12 pulses @ 40KHz) and then immediately change the pin to an input and time from when the input drops low to when it goes high again. This will be the time from the initial burst of sound to the first echo. At this point the I/O pin should be set to low output to prevent the echos from triggering more burst otherwise you may get false readings. Allow a minimum of 50mS between readings so that echos from previous burst don't trigger false readings.

The diode/capacitor combination on the input/output helps sustain the driver while your processor changes the pin from output to input so that your input will initially be high and also converts a series of 40KHz pulses into a single pulse to prevent the processor confusing the 2.5uS gap between40KHz pulses for the gap between burst and echo.


i just realised that im not sure how you would measure distance with these sensors.

if i want to measure distance, do i convert the voltage change in the output in to digital for my pic? or does my pic calculate the time difference between the sent and received pulse?

and is it different for just obstical detection?


when you send a brief pulse to your oscillator (300-400uS) the reciever picks this up. The last stage of the reciever is a comparator that give a digital output so that you will get a brief positive pulse that is extended slightly by the diode and capacitor on the output.

By then timing how long it takes for the echo to return at which point a second pulse is generated you can measure the distance. With picaxe chips this is easy to do using the pulsout and pulsin commands.

The expensive ready made sonars have a processor on board that does this timing for you.

I get up to 3M range so far with this circuit depending on the object size and composition. It can pick up a DVD case at nearly 2m.

 hey by the way thanx for writing this up. im also working on designing and building my own cheap versions of the circuits that work almost just as well.

ive just tested your reciever circuit. i made a 555 40Khz transmitter with 1 msec pulses and tested it facing a wall.

the reciever works quite well. its maximum range is about 2.8 m and its minimum range is around 28cm. any closer and the voltages start going a bit crazy. although ive noticed that on standstill, the voltages vary about + - 0,2V.

 ive also design my own reciever circuit. my range is not as great and its not as sensitive to yours. it only really picks up large objects and basically works best in the 60cm to 1,7m range. still working out the kinks in it.

p.s. the 555 timers cost R1,30 here in south africa. thats about 18 american cents if i convert it.