Electronic Project-Help Please!

Discussion in 'The Projects Forum' started by dimah4x, May 23, 2014.

  1. dimah4x

    Thread Starter New Member

    Jan 9, 2014
    9
    0
    I am working on a RC car that can be controlled via phone with the DTMF decoder and i have decided to add a distance measuring system to prevent me from bumping into obstacles

    I have bought the HC-SR04 ultrasonic sensors and I really don't understand how to work with them or how to code them since i am working with the AT89c5131 processor on a developers board since they didn't allow me to use an arduino and there for i cannot use the pulse in function, let alone that I don't know how to work with the sensor at all

    can anyone explain to me how to measure distance with it? (i.e. move to other direction when there is something 50cm away from the sensor)

    and how am i supposed to code it?
    can anyone give me an example code?
     
  2. dimah4x

    Thread Starter New Member

    Jan 9, 2014
    9
    0
    for the working with the sensor i was thinking of setting an xtal of lets say 1MHZ to the trigger of the sensor so that it will be sync'd with all the sensors and i would be able to measure the distance in cm a lot easier since each pulse is 1uS
     
  3. wayneh

    Expert

    Sep 9, 2010
    12,137
    3,054
    What's wrong with the owner's manual?
     
  4. dimah4x

    Thread Starter New Member

    Jan 9, 2014
    9
    0
    it doesn't give me the info i need for it
     
  5. wayneh

    Expert

    Sep 9, 2010
    12,137
    3,054
    And you think someone here knows more about it than the guy that wrote the manual?

    The manual says the device needs a pulse of at least 10µS to initiate a test, and then the output pulse will be from 150µS to as long as 38ms. So i don't follow your comments about a crystal oscillator. Are you suggesting pulsing at 1MHz while the echo pulse is high, so that you can count those 1MHz pulses?
     
  6. dimah4x

    Thread Starter New Member

    Jan 9, 2014
    9
    0
    i didnt understand your question...
     
  7. wayneh

    Expert

    Sep 9, 2010
    12,137
    3,054
    I was wondering what you meant to accomplish with the 1MHz crystal oscillator you mentioned in #2.
     
  8. dimah4x

    Thread Starter New Member

    Jan 9, 2014
    9
    0
    setting a new clock for the trigger
    or maybe i need to set the pulse when i want instead of every 1uS?
     
  9. wayneh

    Expert

    Sep 9, 2010
    12,137
    3,054
    You've lost me, sorry.

    The detector needs a pulse of at least 10µS to start a measurement cycle. I would expect this to come from your controller. After the trigger ends, the sensor does its thing and, when complete, will send a pulse. The sensor's output requires you to then time this pulse lasting up to 38ms. I would expect your controller to do this task also, to measure the time one of its input pins is held high.

    I don't see how you're planning to use the 1MHz crystal in conjunction with that.
     
  10. Alberto

    Active Member

    Nov 7, 2008
    169
    36
    To have the sensor working properly you should use the timer Function of your AT processor. You need to trigger the sensor with a high Pulse (minimum time 10 micro seconds) This trigger must be considered as your zero time base. After you have triggered your sensor, it will respond with the output high as soon the echo sound has been received. The time elapsed from the initial trigger (your time zero) to the time you see the output of the sensor high, is the value needed to calculate the distance, as per the user manual formula. The more accurate you are in measuring the time elapsed between the two events, the more accurate will be the distance calculated. Hence you need to start your timer when you trigger the sensor and stop the timer when the interrupt sense the high output of the sensor, and you are done with the elapsed time.

    Cheers

    Alberto
     
  11. absf

    Senior Member

    Dec 29, 2010
    1,493
    372
    Here is an example on Arduino using SR04 to determine distance. You should be able to apply the concept and translate the program to your 89S51 system if you're using C language.

    Arduino SR04 application


    Allen
     
  12. enggricha

    Member

    May 17, 2014
    62
    1
Loading...