A hands-on embedded build: an ultrasonic rangefinder that's more accurate than the textbook version because it corrects the speed of sound for the current temperature and humidity, then prints the distance to an LCD in both units, live.
How it works
✓The HC-SR04 emits an ultrasonic pulse and the Arduino times the echo; distance = speed of sound × time ÷ 2.
✓Range is capped at 400 cm; the reading refreshes continuously in the main loop.
Why it's more accurate
✓The speed of sound isn't constant — it shifts with air temperature and humidity.
✓A DHT22 measures both, and the sketch computes speed of sound as 331.4 + 0.6·T + 0.0124·H, so the distance tracks real conditions rather than a hard-coded 343 m/s.
Signal quality & output
✓Uses NewPing's ping_median over 10 samples to smooth out noise and outliers.
✓Prints the result to a 16×2 LCD in both centimeters and inches on each cycle.