← All Projects

Arduino Ultrasonic Distance Meter

127 viewsMarch 5, 2026
ArduinoHC-SR04LCDUltrasonicBeginner

A simple yet practical distance measurement tool using an Arduino Uno and an HC-SR04 ultrasonic sensor. The measured distance is displayed on a 16×2 LCD and simultaneously output to the Serial Monitor for logging.

Components & Supplies

×1Arduino Uno R3
×1HC-SR04 Ultrasonic Sensor
×116x2 LCD Display (HD44780)
×110kΩ Potentiometer
×1220Ω Resistor
×1Breadboard
×10Jumper Wires (M-M)

Circuit Connections

ComponentPinPinComponent
UNOGNDGNDLCD I2C

How It Works

The HC-SR04 ultrasonic sensor emits a 40kHz pulse and measures the time it takes for the echo to return. Using the speed of sound (343 m/s), we calculate the distance to the nearest object. This project is ideal for beginners learning about sensor interfacing and I/O on the Arduino platform.

The result is displayed on both a standard HD44780-compatible 16×2 LCD and the Arduino Serial Monitor, making it easy to debug and log measurements.

Tips for Accuracy

Key considerations for accurate readings:

  • Keep the sensor surface perpendicular to the target for optimal reflection.
  • The HC-SR04 works reliably between 2cm and 400cm.
  • Soft or angled surfaces may absorb the pulse rather than reflect it.
  • Use a 10μs HIGH pulse on the TRIG pin to initiate measurement.
arduinoArduino Sketch
#include <LiquidCrystal.h>

// LCD pins: RS, EN, D4, D5, D6, D7
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int trigPin = 9;
const int echoPin = 10;

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  lcd.print("Distance Meter");
  delay(1500);
}

void loop() {
  // Send ultrasonic pulse
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Read echo duration
  long duration = pulseIn(echoPin, HIGH);
  float distance = (duration * 0.0343) / 2.0;

  // Display on LCD
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Distance:");
  lcd.setCursor(0, 1);
  if (distance < 2 || distance > 400) {
    lcd.print("Out of range");
  } else {
    lcd.print(distance, 1);
    lcd.print(" cm");
  }

  // Log to Serial Monitor
  Serial.print("Distance: ");
  Serial.print(distance, 1);
  Serial.println(" cm");

  delay(500);
}