PDA

View Full Version : ultrasonic sensor



PoTeToJB
- 28th March 2006, 20:25
now i try to design distance sensor for control speed motor.
i use ultrasonic sensor, PIC16F84A and comperator.
i use comperator for compare the voltage i set with voltage from the RX ultrasonic sensor...

but i cant mesure the voltage from ultasonic sensor..

what i know,
if distance small the voltage high
if distance long the voltage low.

i realy new in pic and ultrasonic sensor.

realy need help..

sorry for my bad engglis

Melanie
- 29th March 2006, 02:31
Measuring an Ultrasonic Receivers signal voltage is a unique approach although I suspect it is not a correct one as I can see many scenarios where this would cause problems.

The correct method is to measure the TIME between the leading edge of a Transmission Pulse and the leading edge of the Received Pulse. Since sound travels at around 331m/Second (with only slight adjustment for altitude and temperature), it comes to pass that you can achieve a resolution of around 0.331mm/uS. With a bit of decent code, a 4MHz PIC should be able to resolve distances as low as 2cm.

PoTeToJB
- 15th April 2006, 14:33
thank
Melanie

i cant understand..

-this is a programming for DC MOTOR CONTROLLER (my final project)
-i've run and test the programming but still have a problem at the circuit
-i think the circuit is ok, but the programming for sensor is not ok!
-below are my program




'PIC BASIC PRO FOR DC MOTOR CONTROLLER
'PIC16F84A

TRISA = %00000000
TRISB = %00000111

loop:

High PORTA.0 'this is to transmit the signal from sensor
Low PORTA.1



IF (PORTB.0=1) AND (PORTB.1=1) AND (PORTB.2=1) Then
GoSub motorfast
EndIF
IF (PORTB.0=1) AND (PORTB.1=1) AND (PORTB.2=0) Then
GoSub motormedium
EndIF
IF (PORTB.0=1) AND (PORTB.1=0) AND (PORTB.2=0) Then
GoSub motorslow
EndIF
IF (PORTB.0=1) AND (PORTB.1=1) AND (PORTB.2=1) Then
GoSub motorstop
EndIF
GoTo loop

motorfast:

High PORTB.7
LCDOut $FE, 1,"No Object Found"
LCDOut $FE, $C0,"MOTOR FAST"
Return

motormedium:

LCDOut $FE, 1,"Object Detect I"
LCDOut $FE, $C0,"MEDIUM SPEED"
High PORTB.7
Pause 2
Low PORTB.7
Pause 2

Return

motorslow:

LCDOut $FE, 1,"Object Detect II"
LCDOut $FE, $C0,"SLOW SPEED"
High PORTB.7
Pause 4
Low PORTB.7
Pause 4
Return

motorstop:

LCDOut $FE, 1," WARNING! "
LCDOut $FE, $C0,"SLOW SPEED"
Low PORTB.7
Return



-the problem is the ultrasonic sensor didn't function after the circuit is ON
-maybe it is cause by the programming and i'm not sure how to settle it
-i think the problem is at ultrasonic trasmitter programming
-can anybody help me to solve this...?

i put my circuit in attached file

dhouston
- 15th April 2006, 19:04
Measuring an Ultrasonic Receivers signal voltage is a unique approach although I suspect it is not a correct one as I can see many scenarios where this would cause problems.

The correct method is to measure the TIME between the leading edge of a Transmission Pulse and the leading edge of the Received Pulse. Since sound travels at around 331m/Second (with only slight adjustment for altitude and temperature), it comes to pass that you can achieve a resolution of around 0.331mm/uS. With a bit of decent code, a 4MHz PIC should be able to resolve distances as low as 2cm.

Has anybody tried using an ultrasonic receiver instead of a PIN diode with an Atmel U2538B, T2526 or T2527 chip? It might simplify processing.

ronjodu
- 16th April 2006, 17:29
I used the following code to test out a SRF-04 Ultrasonic sensor from Acroname with a 16f876 (I think, maybe an f84). I believe it worked fine. Results sent to a serial LCD or to Hyperterminal. I think it's on the lines of what Melanie is suggesting.
<code>
DEFINE LOADER_USED 1 'Only required if bootloader used to program PIC


DEFINE HSER_RCSTA 90h 'setup receive register
DEFINE HSER_TXSTA 20h 'setup transmit register
DEFINE HSER_BAUD 2400 'setup baud rate
'DEFINE HSER_SPBRG 25 'setup baud rate


' -----[ Variables ]-------------------------------------------------------

Dist VAR WORD 'setup variable to hold result of sonar conversion distance
fire VAR WORD 'setup variable to hold result of flame sensor
speed VAR WORD 'setup variable to hold result of next sensor

fire = 18 'dummy number for now
speed = 27 'dummy number for now

' -----[ Initialization ]--------------------------------------------------
'
portsetup:
PORTC = %00000000 ' all outputs off to start
TRISC = %00010000 ' All of Port c is outputs except RC4


' -----[ Main Code ]-------------------------------------------------------



main:
'Pause 10 'settle in time(may not be needed)
GoSub sr_sonar 'goto sonar code
GoSub hyperview
GoSub lcdview 'print on LCD and Hyperterminal

GoTo main 'Repeat forever
sr_sonar:

PORTC.4 = 0 'Be sure RC4 is low
PulsOut PORTC.4,2 ' 10us init pulse
PulsIn PORTC.5,1,Dist ' measure echo time
Dist = Dist / 15 ' convert to inches
Pause 100

Return


hyperview:


HSerout ["Distance to Object = ", DEC dist,13,10]
Pause 250
HSerout ["Magnitude of flame = ", DEC fire,13,10] 'output data to hyperterminal
Pause 250
Pause 250
HSerout ["Speed of Travel = ", DEC speed,13,10]

Return


lcdview

SerOut PORTB.6,0,[254,1] 'clear LCD screen
Pause 40
SerOut PORTB.6,8,[254,134,"FIRE"] 'List outputs to LCD
SerOut PORTB.6,8,[254,199,#fire]
SerOut PORTB.6,8,[254,128,"DATA"]
SerOut PORTB.6,8,[254,193,#Dist]
SerOut PORTB.6,8,[254,140,"SPED"]
SerOut PORTB.6,8,[254,204,#speed]
Pause 500

Return


End

</code>

It's been a few years since I've tried it. Hope it helps.

PoTeToJB
- 8th May 2006, 12:38
still problem

i add this program in my code

for transmit the signal
PORTA.4 = 0
PulsOut PORTA.4,2

for recieve i use amplifier for increase the voltage.
but stilll cant function.

can some one help me..

languer
- 8th May 2006, 20:38
I think you would be better off understanding the basic principle of SONAR detection before just launching at this. I believe your receive configuration is missing some bias on the Q2 & Q3 transistor (or you have some resistors values that are just too big).

Take a look at this (http://users.picbasic.org/projects/ultrasonic/ultrasonic_experiments.pdf), it is the simplest approach. Take time to read it, don't just copy and paste the schematic and code (or you'll be back here or 'there' asking more of the same questions).

ErnieM
- 8th May 2006, 22:40
Getting any circuit like this to work can be a HUGE effort, as you have analog, digital and code issues all running together, and usually, unless everything works, nothing works.

So take it in steps... and do please tell me you have an osciloscope. Without an oscilloscope there isn't much you can do with a non-working circuit but say a prayer.

So first, make sure the transmitter is getting a pulse train at 40 KHz. If not, make it so. Once you have that, look at what the reveiver is doing. Q2 collector should show you a burst of 40KHz pulses that are the echo; trigger the scope on the transmit burst and see how long the return burst takes.

Once you see that, you can adjust one of the pots (R17, R18 and R190 so it triggers on the "meat" of this burst. I don't know why there are 3 comparitors there, only one is needed to tell when the return happens.

I have done a similar circuit, I did not use comparitors, just a transistor between my receive amp to "square off" the return signal and use that to trigger an interupt, the ISR then read a timer to determin time of flight. Using interupts isn't essential but would be a bit more accurate then polling the port pins.

PoTeToJB
- 9th May 2006, 20:26
thank
now i understand

how i can pause 10us for transmit the signal.
what cristal oscletor.


realy need help