ultrasonic sensor


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2006
    Location
    johor,Malaysia
    Posts
    57

    Default ultrasonic sensor

    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

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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.

  3. #3
    Join Date
    Feb 2006
    Location
    johor,Malaysia
    Posts
    57


    Did you find this post helpful? Yes | No

    Default

    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
    Attached Images Attached Images  
    Last edited by PoTeToJB; - 15th April 2006 at 14:37.

  4. #4
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie
    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.

  5. #5
    Join Date
    Dec 2003
    Location
    Storrs, Ct.
    Posts
    91


    Did you find this post helpful? Yes | No

    Default ultrasonic distance sensor

    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.

  6. #6
    Join Date
    Feb 2006
    Location
    johor,Malaysia
    Posts
    57


    Did you find this post helpful? Yes | No

    Default

    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..

  7. #7
    Join Date
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Wink

    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, 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).

  8. #8
    Join Date
    Jul 2005
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    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.

  9. #9
    Join Date
    Feb 2006
    Location
    johor,Malaysia
    Posts
    57


    Did you find this post helpful? Yes | No

    Default

    thank
    now i understand

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


    realy need help

Similar Threads

  1. Need a cheap touch sensor idea.. here it is
    By mister_e in forum Code Examples
    Replies: 20
    Last Post: - 16th April 2016, 22:42
  2. Ultrasonic distance sensor with PIC16F84A
    By MrRoboto in forum mel PIC BASIC
    Replies: 3
    Last Post: - 29th June 2009, 09:01
  3. PICBASIC PRO-coding for wireless sensor node
    By syazila in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th February 2009, 00:05
  4. Water Level Detection using Ultrasonic Sensor
    By Balachandar in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th November 2007, 04:59
  5. sensor ultrasonic 8051&PIC
    By hd_uni_pro in forum Schematics
    Replies: 1
    Last Post: - 13th September 2006, 12:58

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts