Try a pulseIn() measurement

Try a pulseIn() measurement

animation
electronics
  1. Try a pulseIn() measurement (try on Wokwi):

    duration_us = pulseIn(ECHO_PIN, HIGH);  // Measures pulse width
    distance_cm = duration_us / 58.3;       // Convert to distance

    The call does not establish 12.5 ns capture resolution or 1 cm accuracy. Test with known pulse widths and distances, and account for timeout, software timing, sensor error and temperature.

Back to the chapter