Arduino LCD Project for Measuring Distance

104,797

76

66

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.

4 People Made This Project!

Recommendations

  • Pocket-Sized Speed Challenge

    Pocket-Sized Speed Challenge
  • Audio Challenge 2020

    Audio Challenge 2020
  • Maps Challenge

    Maps Challenge

66 Discussions

3
WeirdDood
WeirdDood

5 months ago

Here is the code:

/*
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
}

0
booom 123
booom 123

Reply 7 days ago

THANK YOU

1
aviadbenari
aviadbenari

Reply 3 months ago

I just tried this code and it tells me 'trigpin was not declared in this scope'. What can I do to fix it and what does it mean?
thanks

0
GeetanshuG
GeetanshuG

Reply 1 year ago

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

0
benielito03
benielito03

Reply 5 months ago

how can i make it to ft. instead of cm???

0
booom 123
booom 123

Reply 7 days ago

1. you find cm then you change it to ft

0
reinissmilga33
reinissmilga33

Question 6 weeks ago on Step 3

helo can somonebody plz tale me what langauge is neded?

0
vxg1018
vxg1018

Answer 6 weeks ago

THE LANGUAGE IS ENGLISH

0
vxg1018
vxg1018

Question 6 weeks ago

PLEASE TELL ME WHAT THE ACTAUL CODE IS? PLEASE PLEASE PLEASE

0
Vedant Bhalgama
Vedant Bhalgama

2 months ago

How to use 10k preset for controlling brightness

2
rui.m.s.diz
rui.m.s.diz

Question 4 months ago

It is always showing 0 Cm, how do I solve this? please...

3
260089
260089

Question 6 months ago

can you put the code on here?

0
WeirdDood
WeirdDood

Answer 5 months ago

/*
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
260089
260089

6 months ago on Step 3

Its easy to just copy and paste the code.

0
Aaryan Kumar
Aaryan Kumar

Question 8 months ago on Introduction

Can u give me the codes for Arduino LCD Project for Measuring Distance

0
SaugandhS1
SaugandhS1

Reply 10 months ago

Sir I'm unable to find this code