I have just started with programming for the arduino and was playing with my new ultrasound range finder. The code I have is as follows
digitalWrite(trigger_pin, LOW); delay(5); digitalWrite(trigger_pin, HIGH); delay(10); digitalWrite(trigger_pin, LOW); duration = pulseIn(echo_pin, HIGH); distance_mm = (duration/2)/2.91;
We set trigger pin to HIGH for 10 milliseconds following which we set trigger pin to LOW and call the pulseIn command to determine the time for the sound waves to bounce back.
From the documentation for pulseIn at http://arduino.cc/en/Reference/pulseIn the command pulseIn(echo_pin, HIGH) returns the width of the HIGH pulse in microseconds.
Aren't we trying to determine the length of time for which the echo_pin was set to LOW. ie. the time required for the pulse to return? Why do we measure the width of the HIGH pulse here?
Thanks in advance. Sachin