Arduino Ultrasonic Sensor LCD Distance Measurement

21,105

45

9

Introduction: Arduino Ultrasonic Sensor LCD Distance Measurement

About: #MURAT DURAN #Maker #Mechanical Engineer #Proje Hocam

Project material

1- Arduino UNO

2- HC-SR04 Ultrasonik Sensor

3- LCD display

4- Breadboard

Code

#include
LiquidCrystal LCD(10, 9, 5, 4, 3, 2); int trigPin=13; //Sensor Trip pin connected to Arduino pin 13 int echoPin=11; //Sensor Echo pin connected to Arduino pin 11 int myCounter=0; //declare your variable myCounter and set to 0 int servoControlPin=6; //Servo control line is connected to pin 6 float pingTime; //time for ping to travel from sensor to target and return float targetDistance; //Distance to Target in inches float speedOfSound=776.5; //Speed of sound in miles per hour when temp is 77 degrees. void setup() { Serial.begin(9600); 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() { digitalWrite(trigPin, LOW); //Set trigger pin low delayMicroseconds(2000); //Let signal settle digitalWrite(trigPin, HIGH); //Set trigPin high delayMicroseconds(15); //Delay in high state digitalWrite(trigPin, LOW); //ping has now been sent delayMicroseconds(10); //Delay in high state pingTime = pulseIn(echoPin, HIGH); //pingTime is presented in microceconds pingTime=pingTime/1000000; //convert pingTime to seconds by dividing by 1000000 (microseconds in a second) pingTime=pingTime/3600; //convert pingtime to hourse by dividing by 3600 (seconds in an hour) targetDistance= speedOfSound * pingTime; //This will be in miles, since speed of sound was miles per hour targetDistance=targetDistance/2; //Remember ping travels to target and back from target, so you must divide by 2 for actual target distance. targetDistance= targetDistance*63360; //Convert miles to inches by multipling by 63360 (inches per mile) 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(targetDistance); //Print measured distance LCD.print(" inches"); //Print your units. delay(250); //pause to let things settle }


Project code detail : http://www.projehocam.com/ultrasonik-sensor-lcd-mesafe-olcumu/

2 People Made This Project!

Recommendations

  • Game Design: Student Design Challenge

    Game Design: Student Design Challenge
  • Make It Bridge

    Make It Bridge
  • Big and Small Contest

    Big and Small Contest

9 Comments

0
VaibhavN7
VaibhavN7

6 years ago

whats that blue colored thing ? Is it a preset ?

If yes ,then whats the value?

0
Alkon Tech
Alkon Tech

Reply 1 year ago

Yes, it's a preset. It's value is 10k.

0
nareshk82
nareshk82

5 years ago

hey! how to do this without using potentiometer in uno board

0
murgendrag
murgendrag

6 years ago

Arduino: 1.8.0 (Windows 8.1), Board: "Arduino/Genuino Uno"

F:\arduino-1.0.5-r2\ultrasonic_sensor\ultrasonic_sensor.ino: In function 'void setup()':

ultrasonic_sensor:16: error: 'echoPin' was not declared in this scope

pinMode(echoPin, INPUT);

^

F:\arduino-1.0.5-r2\ultrasonic_sensor\ultrasonic_sensor.ino: In function 'void loop()':

ultrasonic_sensor:35: error: 'echoPin' was not declared in this scope

duration = pulseIn(echoPin, HIGH);

^

exit status 1
'echoPin' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

please provide some solution to this problem

0
Knights12
Knights12

7 years ago

Give me some Detailed Description about the LCD Display shown in the above pic.. I need to find it here in INDIA.. Name the Specification of that LCD !

0
VISHWAJEETK6
VISHWAJEETK6

Reply 7 years ago

amazon India has a large variety of arduino accessories including this LCD but the shipping charges are nearly equal to the product ?

0
hrx1016 THE INSANE
hrx1016 THE INSANE

Reply 7 years ago

It's a 1602 LCD display..

That means 16 columns 2 rows
Equals sixteen characters × two lines
Equals 32 characters in total

Here... I live in India...

Hey! Check-out Excel Tech 16x2 LCD Display on Snapdeal at http://m.snapdeal.com/product/Excel+Tech+16x2+LCD+Display/620291504441?&utm_campaign=AppShare_productShare&viewinapp=1

0
Knights12
Knights12

Reply 7 years ago

Thanks a Lot!

1
Nader Parsi
Nader Parsi

7 years ago

hi Murat

How can I change to metric unit for distance measuring ?