Arduino LCD Project for Measuring Distance


Introduction: Arduino LCD Project for Measuring Distance

About: I like to learn different languages I speak Arabic, French and English very well. I spend more time reading about new computer science technologies specially IoT, Static Analysis and Data Mining, Middleware ...

Hello :)

May be you don't know how to use an ultrasonic sensor to measure the distance with an LCD display, so in this instructable I decided to make you happy and help you getting started. This sensor is very popular among the Arduino Geeks. In this project the ultrasonic sensor read and write the distance between the sensor and the object in front of it in the LCD display, It’s really simple.

My goal is to help you understand how this sensor works and then you can use this example in your own projects.

Step 1: Parts Required

- Arduino UNO R3

- 1x HC-SR04 Ultrasonic Sensor

- 1x LCD Display (I made this project with JHD162A)

- Some wires

Step 2: Connect the Components

Connect the components and wires as shown in this schematic.

Step 3: Upload the Code

Upload the sketch to your Arduino and watch the measurement.

For more projects about the HC-SR04 ultrasonic ranging sensor visit my GitHub repository
Good luck.

3 People Made This Project!


  • Water Contest

    Water Contest
  • Oil Contest

    Oil Contest
  • Clocks Contest

    Clocks Contest

28 Discussions

I implemented this code ass you show above with 16x2 lcd and ultrasonic sensor with arduino but in that code distance dosent show 0-cm if i put my object very next to sensor so how it is possible to show distance 0 cm and also how to print distance in float value?


HC-SR04 Ultrasonic Sensor with LCD dispaly

HC-SR04 Ultrasonic Sensor

VCC to Arduino 5V

GND to Arduino GND

Echo to Arduino pin 12

Trig to Arduino pin 13

LCD Display (I used JHD162A)

VSS to Arduino GND

VCC to Arduino 5V

VEE to Arduino GND

RS to Arduino pin 11

R/W to Arduino pin 10

E to Arduino pin 9

DB4 to Arduino pin 2

DB5 to Arduino pin 3

DB6 to Arduino pin 4

DB7 to Arduino pin 5

LED+ to Arduino 5V

LED- to Arduino GND

Modified by Ahmed Djebali (June 1, 2015).


#include <LiquidCrystal.h> //Load Liquid Crystal Library

LiquidCrystal LCD(11,10,9,2,3,4,5); //Create Liquid Crystal Object called LCD

#define trigPin 13 //Sensor Echo pin connected to Arduino pin 13

#define echoPin 12 //Sensor Trip pin connected to Arduino pin 12

//Simple program just for testing the HC-SR04 Ultrasonic Sensor with LCD dispaly


void setup()


pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

LCD.begin(16,2); //Tell Arduino to start your 16 column 2 row LCD

LCD.setCursor(0,0); //Set LCD cursor to upper left corner, column 0, row 0

LCD.print("Target Distance:"); //Print Message on First Row


void loop() {

long duration, distance;

digitalWrite(trigPin, LOW);


digitalWrite(trigPin, HIGH);


digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration/2) / 29.1;

LCD.setCursor(0,1); //Set cursor to first column of second row

LCD.print(" "); //Print blanks to clear the row

LCD.setCursor(0,1); //Set Cursor again to first column of second row

LCD.print(distance); //Print measured distance

LCD.print(" cm"); //Print your units.

delay(250); //pause to let things settle


1 reply

Thanks really helpful nice

thanks great help

bro!! i uploaded the program on my arduino uno but still the distance is 0cm its not changing at all !! please help me i think my sensor is not working its different from yours..thanks in advance bro

Very nice Sir but plz give the code

add in a potentiometer to control the contrast: plug the wiper (the middle pin) to the 3rd pin on the lcd and plugging the other two pins to 5v and GND​

what is the code of this project

XD LOL The code is the sheet of paper thingy.

Must be kind of old the schematic is 404

Would u like to share with me,,
Thanks in advance..:)

Would u like to share with me,,
Thanks in advance..:)

Would u like to share with me,,
Thanks in advance..:)

Where is the code????