Ultrasonic Transducer (same as car sensors) How to use them?

OK I have now got a working system that uses the MaxSonar EZ1 sensors to output a voltage and I ADC that and display the distance in inches on a screen thats all fine.

My biggest problem is I need the sensors to be waterproof and weatherproof, and much cheaper than EZ1. I notice any cheap reverse parking sensor kits comes with 4 waterproof, weatherproof sensors already supplied with leads and unit to do the job.

My question is, what are these sensors (have 2 pins) are they just transducers, and where can I buy them from? and if so how do you use them, as I am still unclear.

I presume the sensor is just a transducer that I need to send a frequency down based on its frequency, then time how long it takes until a frequency comes back down. But I dont understand what pins you send the frequency up and when line they come back down on etc… I would of thought there is a nice tutorial on doing this entire thing but I cannot find one.

Possibly is there also a cheap driver perhaps that can drive a transducer for me?

No one?

I’m not sure exactly what sensors you’re referring to, but the “waterproof” types I’ve seen can be used for both transmit and receive with suitable circuitry. They are not as sensitive as the “open” types, ie, they will need more gain.

Try Google for example circuits.

Some examples of “waterproof” types:

http://jaycar.com.au/productView.asp?ID … rm=KEYWORD

http://au.mouser.com/ProductDetail/Kobi … R2ZOIvpdBq

http://au.mouser.com/ProductDetail/Kobi … Vz%252bQ7z

http://au.mouser.com/ProductDetail/Kobi … kXHSh%2f0t

http://au.mouser.com/ProductDetail/Kobi … BEHBlzqBGu

Yes they are effectively the types I am on about, with 2 pins. My problem is, what do I do with those 2 pins?

Do I connect one to ground and the other to a PWM generator pin of a PIC to send 40kHz (or the correct frequency) down the line to create the ultrasonic transmission? And if that is the case, what happens when the transducer is receiving a sound, how do I detect that over the 2 lines? Does the frequency just come back down the same line? Are they polarity or bi-polar devices? etc…

I cannot find out that info anywhere, about just sending and receiving sound using them. I know that I need to give a blanking period from sending to receiving so I dont get an echo of the transmission, and I know that I basically want to use a comparator or timer to work out the time from sending to receiving, and calculate that over the speed of sound etc… to get distance, thats not a problem. The only problem is, how to actually send/receive using the device itself?

It might be simpler to generate your own pulse instead of using the PWM in the PIC.

TX: Send a few cycles of 40KHz (or the freq of your transducers) by connecting the two transducer pin to two pins of the PIC, make them outputs, and drive them push-pull (out1=HIGH, out2=LOW and then out1=LOW, out2=HIGH).

RX: Take a coupling capacitor (.01uf or so) and connect one end to the input of your amplifier. Connect the other side of the capacitor to out1. On receive mode, make out1 an input and drive out1 to VSS (gnd). This essentially connects one end of the transducer to gnd and the other side to the amplifier via a coupling capacitor.

Sounds good. So to send a sound I just pulse the lines on/off presumably like this?

movlw b’00000010’

movwf PORTB

// Pause here to make the frequency?

movlw b’00000001’

movwf PORTB

// Pause here to make the frequency?

As an example to pulse RB0 and RB1 of a chip?

Then upon sending say 10 pulses of hi/lo, I would start a timer, and change to receiving…

Now to receive, I’d change RB0 to an input and should I have the cap always wired to the amp and out1 line, or do that only when I want to be in RX?

From that, what should I then expect to be coming in on RB0, and what should I expect to be going to my amp?

Sorry if these sound like dumb questions for those who already know, your help is much appreciated.

Each cycle (say 10 of them) is generated as you described. The period for a 40 KHz signal is 25 microseconds. In C, it would look like this:

for (i = 0;  i < 10; i++) {
  PORTB = b'00000010;
  DelayUs(12);
  PORTB = b'00000001;
  DelayUs(13);
}

The capacitor is always connected to the amplifier. The purpose of making RB0 an input is to get the PIC out of the way. If it were still an output, the incoming signal would be lost as the PIC will either drive to ground or pull it up to VDD.

I’m not sure it’s a good idea to drive the transmitter directly from a PIC. I’ve used a MOSFET to do this in the past. I’ve seen designs that use a MAX232 to boost the power - you can get something close to 20V Peak to Peak for significantly higher performance. That’s probably what I would do.

I have driven the transducer directly from the PIC without any issues and have gotten a range of 10-15 feet. I agree with you that using a MAX232 or a MOSFET driving a transformer would yield significantly better results. I see that the new Maxbotics sensors split the difference: they connect 8 I/O pins together in two groups of 4 pins, and then drive a transformer. It looks like their older design used a pair of pins in push-pull mode.

riden:
RX: Take a coupling capacitor (.01uf or so) and connect one end to the input of your amplifier. Connect the other side of the capacitor to out1. On receive mode, make out1 an input and drive out1 to VSS (gnd). This essentially connects one end of the transducer to gnd and the other side to the amplifier via a coupling capacitor.

In here did you mean one of these to be out2? I’m thinking you mean disable out1 by making it an input and just sending out2 to ground still as an output? so that the out2 is sending one pin to ground and the other pin is going to the amplifier?

Will get a design done tonight and post the schematic to see if I am doing it right.

Yes, I was being sloppy. :oops: Out2 (the one NOT connected to the cap) is the one that gets driven to GND.

OK ordered all my bits they will be here tomorrow.

Still not sure what will happen though - I get that sending a frequency will cause the sensor to transmit, and then turning one pin to an input gets it into receive mode, but still dont understand whats going to happen here.

Presumably, if one pin is input at the other to ground, when the sound bounces back, it would effectively send the same frequency back down the line, which can be read by my input pin somehow using PWM input?

If that is correct, whats the use of sending the frequency through an decoupler and amplifier? Where would the timing of the range of come into that without first going into the PIC to get the difference, and then outputting it back on another pin to the amplifier as a voltage based on the time?

Even though you are setting Out1 as an input, the PIC is not looking for the signal on that pin. You need to make Out1 an input because Out1 as an output will quelch the input return. The amplifier, driven by the capacitor on Out1 will amplify the weak return signal to a level where a comparator either as part of the amplifier or the comparator in the PIC will cross a threshold when the return signal is detected.

The steps involved are…

  1. Set Out1 as an output

  2. Start the timer (or record the current timer reading)

  3. Send 5 - 10 cycles of 40 KHz (25 us per cycle)

  4. Wait a short period of time for the ringing to die on the transducer

  5. Make Out1 an input, drive Out2 to GND

  6. Wait for the comparator to fire

7 Stop the timer or read current the timer reading

Ralph,

Thanks for that think I understand a lot better now! Makes sense.

Will get to work over the weekend and see how I go.

Good luck and let us know how it goes. I have a single transducer, short range, sensor project that has been on the back burner for over a year now. It is designed to use the absolute minimum number of parts at the expense of shorter range. Perhaps your successes with your project will inspire me to move the project up my list a little bit. Just need more time in the day/week. :slight_smile:

Just doing the proteus design for the amplifier now. Not used amps before so just tring to get the LM324 to behave as I want.

I am using a non-inverting setup with the negative feedback R1 as 2K, and the inverted input R2 as 1K to give (R1+R2)/R2 = 2+1 / 1 = 1:3 ratio, so whatever voltage is put in the input, I get approx 3x that on the output.

It seems to work as if I put 0.500047v on the input I get 1.50575v output.

My question is… what am I trying to amplify as the feedback from the transducer? What voltage should I be expecting back from sending 10 40Mhz pulses at 3V? And is the voltage back relative to the distance also?

What I was thinking is do I need an amplifier as the PIC12F675 that I plan to use has an ADC that can pick up millivolts anyway, so would it not detect the voltage coming back, or do I want the signal coming back to be an average voltage (smoothed by the capacitor going to the amp presumably) that increases as each pulse is received, until it receives say at least 7 of the 10 pulses to create a certain voltage level which I class as a valid echo?

Because of the sampling delay, you will get better results using a comparator instead of the ADC in the PIC. Typically the amplifier drives a comparator (either as part of the external electronics or a comparator in the PIC). Ultrasonic rangers work by looking for the beginning of the pulse to come back. Amplifying the input from the transducer and then applying it to a comparator will cause the comparator level to change when the pulse returns, which in turn is the signal for the PIC to stop its timer.

Yes I’m up to that point, I have set up the comparator with a reference voltage of 1.5v. I time from sending the pulse, and monitor the comparator COUT bit to be set. The CIn waiting to go above 1.5v is coming from the output of my amp, which will amplify the line of the transducer with the .01uF cap on it waiting to receive the pulse back.

My question is, if I am pulsing the line out (transmitting) with 3v 40Mhz, what voltage should I expect back that will be going into my amp, so I know what to amplify it by to get it above 1.5v? Or am I just doing a unity gain to amplify the signal not the volts, and I should expect approx 3v back?

Also, do I need to worry about the amp sending the voltage over 3v, and if so whats the common practice to handle that, or will it not matter if I limit the current and let the PIC internally clamp the volts?

I have done all of the code now so in theory it should work to send a pulse, wait to settle, and detect the receive, and measures distance. The distance is then stored in a variable called distanceReading with each bit equalling 1 inch. My final problem is, how do I actually output a voltage from the PIC so that it can be read in by the host? It should be simple as I have a single variable from 0 to 256 so the voltage should be 0 to 2.56v

The voltage output must remain at its voltage while sampling is taking place, not just be pulsed, but I have no idea how to do a DAC instead of ADC. The EZ1 clearly does this without anything other than what I am using (a PIC and an amp or 2) so it must be possible.