Project 2 - Measuring the distance of an object using ultrasonic sensor and also smoothen the sensor data using moving average filter
how to measure distance using ultrasonic sensor
To measure the distance the sound has travelled we use the formula: Distance = (Time x SpeedOfSound) / 2.
The "2" is in the formula because the sound has to travel back and forth.
First the sound travels away from the sensor, and then it bounces off of a surface and returns back.
The easy way to read the distance as centimeters is to use the formula: Centimeters = ((Microseconds / 2) / 29).
For example, if it takes 100µs (microseconds) for the ultrasonic sound to bounce back, then the distance is ((100 / 2) / 29) centimeters or about 1.7 centimeters.