Introduction: HC-SR04 + LCD + Arduino: Ultrasonic Rangefinder Display

About: I love to make projects based on microcontrollers including robots and IoT technologies. Absolutely, truly, madly, deeply in love with planes. I also dabble in the art of Origami and play chess in my spare ti…

Hello World!

This is Unicorn Clockworks and here, we are going to make an Ultrasonic measuring tool with a display. This HC-SR04 ultrasonic emitter and receiver can measure anywhere from 2cm to 200cm or 1inch to 13 feet, while being accurate up to 3mm. Since it uses ultrasonic waves are a non-contact form of measuring distances, it is perfect for applications like home renovation for measuring the distance to the ceiling or to the wall without having to grab your measuring tape!

Like my previous posts, this is compatible with any microcontrollers with Arduino core support, without any modifications to the code or circuit.

Step 1: Materials

  • Arduino or any Arduino-compatible microcontrollers
  • HC-SR04 Ultrasonic Sensor
  • LCD display
  • Potentiometer
  • Jumper Wires
  • Breadboard

Step 2: LCD Connections

I've written a complete generalized Instructable on this recently, so you can check this out:

Alternatively, read on and I still show you everything in detail here:


  • Connect the Brown wire (pin 16) to the GND pin on the Arduino
  • Connect the Red wire (pin 15) to the 3.3V VCC pin on the Arduino
  • Connect the Orange, Yellow, Green, Blue (pins 14-11) to pins 2 to 5 on the Arduino


  • Connect the White wire (pin 1 on the LCD) to the common ground (pin 16)
  • Connect the Grey wire (pin 2 on the LCD) to the common VCC source (pin 15)
  • Connect the Purple wire to the signal pin of the potentiometer (pin 2 on the potentiometer)


  • Connect the Purple wire (pin 1 on the potentiometer) to the common ground (pin 16)
  • Connect the Grey wire (pin 3 on the potentiometer) to the common VCC source (pin 15)


  • Connect the Yellow wire (pin 4 on the LCD) to pin 12 on the Arduino
  • Connect the Black wire (pin 5 on the LCD) to the common ground (pin 1 on the potentiometer or pin 16 on the LCD, either works)
  • Connect the Green wire (pin 6 on the LCD) to pin 11 on the Arduino

Step 3: Ultrasonic Connections

  • Connect the Red wire from the VCC pin of the ultrasonic sensor (pin 1) to any common VCC source (like pin 3 of the potentiometer or pin 2 of the LCD)
  • Connect the Black wire from the GND pin of the ultrasonic sensor (pin 4) to any common ground (like pin 16 of the LCD or pin 1 of the potentiometer)


  • Connect the Blue wire from the trigger pin(send) of the ultrasonic sensor (pin 2) to pin 9 on the Arduino
  • Connect the Brown wire form the echo(receive) pin of the ultrasonic sensor (pin 3) to pin 10 on the Arduino

Step 4: Code

#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);
const int trigPin = 9;
const int echoPin = 10;
long duration;
int distanceCm, distanceInch;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
void loop() {
digitalWrite(trigPin, LOW);
digitalWrite(trigPin, HIGH);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm= duration*0.034/2;
distanceInch = duration*0.0133/2;
lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.print("Distance: "); // Prints string "Distance" on the LCD
lcd.print(distanceCm); // Prints the distance value from the sensor
lcd.print("  cm");
lcd.print("Distance: ");

Step 5: It's Done!