Arduino LCD Project for Measuring Distance

73,726

65

41

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.

4 People Made This Project!

Recommendations

  • Pets Challenge

    Pets Challenge
  • Fandom Contest

    Fandom Contest
  • Classroom Science Contest

    Classroom Science Contest

41 Discussions

0
None
GeetanshuGasim.nasco

Reply 10 months ago

Upto 5 meters...but it can generally measures upto 3meters with great precision!

0
None
derbhaile.boyle

Question 5 weeks ago

hi could you send me the code for this please ?

0
None
haroldg1995

Question 7 weeks ago on Step 3

instead of wire, can we use the pins?

0
None
kachhias

1 year ago

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?

1 reply
0
None
xxxTGPxxx

Question 2 months ago

My LCD display isn't showing anything how do I fix this?

0
None
Mati27a

3 months ago

I do not work the LCD backlight

0
None
Mati27a

Question 3 months ago

He need a resistor?

0
None
Monoboy

9 months ago

o/p is coming randomly

/*

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

//URL:

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);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

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
0
None
sidster

1 year ago

Thanks really helpful nice