The ultrasonic distance sensor sends out sound waves and waits for the echo. It then calculates the distance by using the time it took for that sound wave to return to the sensor, we need to set the threshold value. In this example it is 100 millimeters. This is the threshold between far and near. The example program uses a while loop to keep the motor spinning until the sensor reads less than 100 millimeters. at less than 100 the condition will become false and the loop will exit then the motors will stop.
The distance sensor can also detect different signals, it can detect the strongest second strongest and the reflected value. In this example program we display the values on the screen directly from the sensor I'd be careful using these values though they are not very reliable in my opinion. Do very useful commands for the distance sensor, or the set distance minimum range and the set distance maximum range. We can use these commands to ignore values outside the range we want to detect. Doing this will make our programs more reliable. The example program only prints the values on the screen.
But we could set the minimum and maximum range in any obstacle detection detection program that uses the sensor