limiting range of PING))) sensor

Hi folks,
the PING))) ultrasonic range finder measures distances from 3cm to 3meters. But I`d have to limit its range from 3cm to 60cm.
Thus I want the program to wait for a maximum duration of 3496 microseconds (=60cm) before automatically going LOW again.
How could I start a timecount in microseconds each time the PING))) goes HIGH??? This would allow me to go LOW after the desired duration.

As far as Im concerned *pulseIn(pin, HIGH)* wont work, as pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing. So untouched it always outputs the sensor's maximum range, as it needs an echo to stop timing and else gives the sensor's maximum range.

Any ideas?

The pulseIn() function supports an optional third argument which is a timeout in microseconds. Would that help? :wink:

http://arduino.cc/en/Reference/PulseIn

-br

http://entropymouse.com

Hi billroy,
good thinkig hear, I checked that before posting my question and unfortunately the answer is no.
timeout waits the number of microseconds for the pulse to start, in other words: timeout returns 0 if no pulse started before the timeout. Thus it counts the time before the sensor goes HIGH, but I`d like to count the time in microseonds the moment the sensor goes HIGH until it reaches 60 cm or receives an echo before that.
???

You have the source of pulseIn - it should be simple to write what you want.

Hi AWOL,
sorry for asking, but I didn`t fully understand your reply.
Did you mean I should rewrite/modify the pulseIn() function?
If yes, how can I get its source code?
Never rewrote a function before, but actually sounds like a good idea.

You could have a hardware solution to the problem, too. Just put some big flat object at 60 centimeters from the sensor.

The wiring_pulse.c file contains the pulseIn function. That file is in \hardware\arduino\cores\arduino.