Temperature-Compensated Rangefinder — Engineering_
FileEditViewGoFavoritesHelp
UpAddress:C:\Projects\hardware\ultrasonic-rangefinder
Drawing RNG-009 · Entry 09 · 2024

Temperature-Compensated Rangefinder

Embedded Systems · Personal project
Complete

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.

Specifications

Microcontroller:Arduino Uno
Ranging:HC-SR04 (≤ 400 cm)
Compensation:DHT22 temp + humidity
Speed of sound:331.4 + 0.6·T + 0.0124·H
Filtering:10-sample median ping
Display:16×2 LCD — cm & inches
Sketch size:3.3 KB (10% of Uno flash)
Tools:Arduino UnoC++ (Arduino)HC-SR04DHT2216×2 LCD

Figures

The build — breadboard, sensors, and live LCD readout
Fig. 1The build — breadboard, sensors, and live LCD readout
Complete · Builder, scale 1:1 (breadboard)Embedded Systems