Skip to content
Intermediate 2.5 hours

Ultrasonic Distance Meter with Arduino and OLED

By Amit1379
July 13, 2026

The HC-SR04 sends a burst of ultrasonic sound and measures the time for the echo to return. Since sound travels at ~343 m/s, distance = (time × 343) / 2. This project wraps that measurement in a portable handheld device with an OLED display showing the current distance, a hold-reading button, and a simple bar graph showing distance graphically.

What You’ll Need

  • Arduino Nano (compact form factor suits a handheld build)
  • HC-SR04 ultrasonic sensor
  • SSD1306 0.96″ OLED display (I2C)
  • Push button + 10 kΩ pull-down resistor
  • 9 V battery + battery holder
  • Small project enclosure (3D-printed or plastic project box)
  • Breadboard for testing, stripboard for final build

Step-by-Step Instructions

  1. Install libraries: Install “Adafruit SSD1306” and “Adafruit GFX Library” via Library Manager.
  2. Wire HC-SR04: VCC → 5 V, GND → GND, Trig → pin 9, Echo → pin 10.
  3. Wire OLED: SDA → A4, SCL → A5, VCC → 3.3 V or 5 V, GND → GND.
  4. Write distance measurement: Pulse Trig pin HIGH for 10 µs, then read Echo pin duration with pulseIn(). Distance (cm) = duration / 58.2. Average 5 readings to reduce noise.
  5. Display output: Show distance in large text on OLED top half. Draw a horizontal bar (0–400 cm mapped to display width) on lower half. Show “HOLD” overlay when button is pressed.
  6. Hold mode: When button pressed, freeze the displayed value. Press again to resume live readings.
  7. Build final version: Solder onto stripboard, mount in enclosure with HC-SR04 poking out the front and OLED flush with a window cut in the lid.

Safety Notes

  • Ultrasonic pulses are inaudible and completely safe — no precautions needed for the sensor itself.
  • When cutting project box openings, work carefully with a craft knife or rotary tool.

Tips & Troubleshooting

  • Accuracy degrades on soft, angled, or very small surfaces — works best on flat, hard surfaces facing the sensor directly.
  • Readings below 2 cm return garbage values — add a check and display “TOO CLOSE” instead.
  • Add a piezo buzzer that beeps faster as the target gets closer for a parking-sensor style experience.

Leave a Comment

Your email address will not be published. Required fields are marked *