#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define trigPin 2
#define echoPin 4
long waktu;
int jarak;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
waktu = pulseIn(echoPin, HIGH);
jarak= waktu*0.034/2;
Serial.print("Jarak: ");
Serial.println(jarak);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Jarak: " + String(jarak) + " cm");
delay(200);
}