// include the library code:
#include <LiquidCrystal.h>
 
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#define echoPin 7 //connect echo pin of ultrasonic sensor
#define trigPin 6 //connect trigger pin of ultrasonic sensor
#define buzzer 8 //connect buzzer pin of uultrasonic sensor
long duration;  // declare variables to hold duration and distance
int distance;

void setup() {
  pinMode(trigPin,OUTPUT); //set trigPin as output pin of Arduino
  pinMode(echoPin,INPUT);  //set echoPin as output pin of Arduino
  pinMode(buzzer, OUTPUT); //set buzzer as outout pin of Arduino
  lcd.begin(16, 2);
  lcd.clear();
}

void loop() {
  digitalWrite(trigPin,LOW); //generate square wave at trigger pin
  delayMicroseconds(2);
  digitalWrite(trigPin,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin,LOW);
  digitalWrite(buzzer, HIGH);
  delay(1000);
  digitalWrite(buzzer, LOW);
  delay(1000); 
  
  duration=pulseIn(echoPin,HIGH);//calculation of distance of obstacle
  distance=(duration*0.0343/2);
  lcd.setCursor(0,0);
  lcd.print("Distance : "); //print distance on the LCD
  lcd.print(distance);
  lcd.println(" cm ");
  delay(1000);
}