ultra sonic range meter

Bloody-orc

Senior Member
Hi there!
I'm planing to build a ultrasonic range meter for my robot.
I searching for easy schematics, that i could use with my pic(axe). Has anyone some good schematic?

aslo i would like to know, how is this programming done?
*pulseout
*reading?
*calculating the value into cm's(how do i do that?)
*sending data to lcd\PC(this is the part i know Wink )

any good links\tutorials?
 

hippy

Technical Support
Staff member
Are you wanting to build the entire module from an ultrasonic TX/RX pair upwards, or interface to a ready built module ?

There should be numerous articles available through Google which describe both, over a range of costs and with varying levels of performance. What's good or bad depends upon exactly what you are trying to do, what ranges you want and accuracy of measurement, and how much you are prepared to spend.

Range finding relies on giving a pulse of ultrasound and measuring the delay between a pulse being emitted and the reflection coming back. That time is converted to a distance using the speed it takes for an ultrasound pulse to propogate through air; distance=speed/time

Ulrasound travels a cm in about 30uS ( but depends on temperature ), so to measure the time between issuing the pulse and the returned reflection requires a reasonably fast processor or external timing mechanisms. A PICAXE couldn't do that by itself ( although a PICAXE could measure the gap between emiting and echo received ), which is why the SFR04/08/10 sensors are usually used. I'm sure I've seen PICAXE example code for this somewhere.

Most ultrasonic range finders don't use a single pulse but a 40kHz pulse train, which adds complexity.

If you want something which works simply and easily with a PICAXE I'd suggest a commercial module. If you want a DIY solution, there are numerous suggestions via Google, and perhaps the best approach is to build something simple and then enhance what you have. Perhaps the most important thing is understanding how the various systems work, their limitations, potential problems and why certain things were done one way and not another. All that probbaly only comes from experimenting and reading up on what others hae done.
 

Rickharris

Senior Member
The U. sonic modules available from Rev Ed work very well and are not too costly by the time you have purchased all the various parts to make one.

Reading the data sheet for that module will help you with both a diagram and information on programming.

It uses a seperate PIC to drive the Ultra Sonic RX/TX in bursts of 10 cycle of 30Khz.

It measures the time between Trig and receiving the signal back and provides a digital signal for the picaxe.

Edited by - rickharris on 6/22/2005 1:35:07 PM
 

BeanieBots

Moderator
The SFR04 as mentioned above is probably the simplest and cheapest option. The SFR08 has more features and communicates via I2C which has significant advantages if you wish to use lots of them at the same time but does cost significantly more. It also has options to return the distance in uS, cm or inches. The SFR10 is just a physically smaller version of the SFR08.
 

hippy

Technical Support
Staff member
This seems to be quite a good article describing a 'cheap and cheerful' system and the theory, based upon the Parallax BS1 which is similar to the PICAXE ...

http://www.eetasia.com/ARTICLES/2002MAR/2002MAR08_RFD_DA_AN.PDF

Looking at that, it might be possible to generate the 40kHz ( or whatever ) burst with an 08/M using PWM ( so no 555 needed ) and be able to get into a PULSIN before an echo is returned - I'd always assumed that to be between very unlikely to impossible, so I'm not always right

:)

Although some amplification will probably be needed for the receiver, it may be possible to simplify it.

Somewhere there is an example for a PICmicro using just a single TX pulse and a very simple ( or no ) amplifier, and it would be nice to hear if anyone has any practical experience of trying it this way. It might not be accurate for distance measuring, but could be good enough for imminent collision detection.

Edited by - hippy on 6/22/2005 4:56:22 PM
 

Bloody-orc

Senior Member
this is yes mostly for avoiding obsticles, but also i'm planing to make a mapmaker and this requires more accurancy
 

Rickharris

Senior Member
Mmmm Mapping - why not use some kind of feedback from the wheels such as a slotted disc or grey code disc. Then you have a direct reading of how you got there.

Mapping the surrounds with U/S as in an U/S radar isn't very effective from my experiments and what I see on the web. Doing it is Ok, Understanding with a micro it is something else.
 

Bloody-orc

Senior Member
anyway i'm using this schematic here:
<A href='http://www.eng.uah.edu/~wells/cpe437_sp_00/hrf/circuit_schematic.htm' Target=_Blank>External Web Link</a>
and code for it is here:
<A href='http://www.eng.uah.edu/~wells/cpe437_sp_00/hrf/code_listing.htm' Target=_Blank>External Web Link</a>
as i'm only using this u\s part of it and cant understand anything of this code, could someone give me hints, what i must do. what pulseouts and how the reading is done and the calculating to cm's.
 

hippy

Technical Support
Staff member
The best description of the circuit and operation is here ...

http://www.eng.uah.edu/~wells/cpe437_sp_00/hrf/theory_of_operation.htm

Basically it does as I suggested earlier, but using Assembly language rather than Basic. A 40kHz burst is sent, and then the PICmicro looks for an echoed return.

Can we clarify - Are you using a PICmicro or a PICAXE ?
 

Bloody-orc

Senior Member
I'm using picaxe 40X
The thisng i would want to know is, how is the 40kHz pulses sent out and hew are they recieved and how is the thing calculated. I now what to do but dont know how to do it :(

Edited by - bloody-orc on 6/23/2005 7:57:03 AM
 

hippy

Technical Support
Staff member
I'm not sure you've appreciated the magnitude of what you are asking for. It is along the lines of, &quot;I know what an atom is; how do I split one ?&quot;

The real problem is that unless someone has done what you want using the hardware you've chosen then there isn't a readily available solution or answer; at best only theory and ideas and you'll have to do some experimentation and design work.

As you want to drive the ultrasound TX directly from the PICAXE you need something to provide those pulses. A single pulse can be generated by PULSOUT, a burst of pulses by using PWM or by using PWMOUT. Having chosen the 40X you have the choice of using PULSOUT or PWMOUT.

It may be possible to use multiple PULSOUT's to generate a stream of pulses, but because of the speed of the PICAXE, there will be around a 250uS delay between them, and you could then be handling PULSOUT's when the echoed signal is returned.

To generate a burst using PWMOUT means setting it up to send the right frequency, then turning it off immediately afterwards, and again hoping that is all done before the echo is sent back.

To determine the range requires measuring the time between the pulse being sent and the echo received. As shown in the BS1 example, this can be done by using PULSIN with appropriate hardware.

This time is then converted to a range as described earlier - distance=speed/time. Because the PICAXE only uses integer maths, and the 'time' needs calibrating then this will require some fudging, along the lines of ...

- distance = time - K * M / N

The values used will depend upon the units of distance you want (cm), what values of time you get, and the equation could get complex in avoiding overflow. To start with, don't worry about distance, just concentrate on getting a time back which increases as the object reflecting is moved further away.

The PICmicro code isn't really relevant to a PICAXE solution because it operates in a time domain much smaller than the PICAXE can, and uses techniques not applicable to the PICAXE. The hardware for the PICmicro uses RA0 and RA1 to drive the ultrasound TX by using out of phase on each pin, which can't be done on the PICAXE. Unless you use and external driver, one leg will need to be tied to 0V and the other driven by the PICAXE. If using PWMOUT the pin used is predetermined by the pins which PWMOUT can use.

The first step is to build a PICAXE transmitter and the receiving hardware so you can check that ultrasound does pass between the two and not when blocked. That proves the hardware.

Then you'll have to experiment to try and make what you have work as you want. You'll probably need access to a scope to see what's going on. To use PULSIN as per the BS1 example code, you'll need a receiver which gives a waveform which can be used with PULSIN. If the circuit you've chosen doesn't work that way then I'm not sure how you will go about reading the signal and determining the time for the echo. If you don't know what signal the receiver gives in response to a TX burst, you aren't likely to get off the starting blocks.

If you are looking for a ready built solution which has all the answers to your questions, we are back to the suggestion that you use a ready built module which has example code for uses ( the SRF04 interface software is in the PICAXE 'samples' directory ), or something like the BS1 example which should work as described on a PICAXE. Porting a solution from a differenct device to a PICAXE is not as straight forward as may be imagined and relies upon having a depp understanding of how that solution works and ensuring it will work with a PICAXE. Unfortunately you are asking for the solution to a problem which no one on this forum has probably set about solving.

Perhaps someone who has used a PICAXE to do range finding other than using an SRF module will come up with a answer along the lines of, &quot;I did this ...&quot;, but otherwise you will be pretty much on your own.

One such example I've found is here ...

http://www.siliconchip.com.au/cms/A_103243/article.html
 
Top