Electronic Project-Help Please!

Thread Starter

dimah4x

Joined Jan 9, 2014
9
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?
 

Thread Starter

dimah4x

Joined Jan 9, 2014
9
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
 

wayneh

Joined Sep 9, 2010
17,496
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?
 

wayneh

Joined Sep 9, 2010
17,496
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.
 

Alberto

Joined Nov 7, 2008
169
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
 
Top