#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x27, 16, 2);

const int trigPin = 6;
const int echoPin = 7;
int buzzer=8;

long duration;
int distanceCm, distanceInch;

void setup() {
lcd.begin(12,2);

pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}

void loop(){
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin,LOW);

  duration = pulseIn(echoPin, HIGH);
  distanceCm=duration*0.034/2;
  distanceInch = duration*0.0133/2;

  lcd.setCursor(0,0);
  lcd.print("Distance");
  lcd.print("cm");
  delay(10);
  lcd.setCursor(0,1);
  lcd.print("Distance:");
  lcd.print(distanceInch);
  lcd.print("inch");
  delay(10);

  if(distanceCm <=50){

    tone(buzzer,1030);
    delay(400);
    noTone(8);
    delay(100);

  }

}