#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define echoPin 2
#define trigPin 3
LiquidCrystal_I2C lcd(0x27 , 16 , 2);
long duration;
int distance;
void setup() {
lcd.init();
lcd.clear();
lcd.backlight();
lcd.setCursor(0,0);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.03423 / 2;
lcd.print("Distance: ");
lcd.setCursor(10,0);
lcd.print(distance);
lcd.println(" cm");
}