Discover how a tiny sensor can make your Raspberry Pi 'see' how far things are without eyes!
Why DistanceSensor (ultrasonic) in Raspberry Pi? - Purpose & Use Cases
Imagine you want to measure how far an object is from your Raspberry Pi using just a ruler and your eyes.
You have to stand still, guess the distance, and write it down every time the object moves.
This manual way is slow and not accurate.
It's easy to make mistakes, and you can't measure distances quickly or repeatedly without errors.
The DistanceSensor (ultrasonic) automatically sends sound waves and listens for echoes to measure distance precisely.
This lets your Raspberry Pi know the exact distance without any guessing or manual measuring.
print('Guess the distance and type it in:') distance = input()
from gpiozero import DistanceSensor sensor = DistanceSensor(echo=17, trigger=4) distance = sensor.distance print(f'Distance: {distance:.2f} meters')
You can build smart projects that react to objects nearby, like robots that avoid obstacles or automatic doors that open when you approach.
Think of an automatic faucet that turns on when your hands come close--this uses ultrasonic sensors to detect your hands without touching anything.
Manual distance measuring is slow and error-prone.
Ultrasonic DistanceSensor automates and improves accuracy.
This opens up many interactive and smart device possibilities.