#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 23, en = 22, d4 = 21, d5 = 19, d6 = 18, d7 = 5;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int trig = 12;
const int echo = 14;
long duration;
int distance;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16,2);
pinMode(trig, OUTPUT);
pinMode(echo, OUTPUT);
}
void loop() {
lcd.setCursor(0,0);
digitalWrite(trig, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
// Reads the echoPin, returns the sound wave travel time in microsec.
duration = pulseIn(echo, HIGH);
// Calculating the distance
distance= duration*(0.034/2);
// Prints the distance on the Serial Monitor
lcd.print("Distance: ");
lcd.print(distance);
lcd.println("cm");
delay(500);
}