const int TRIG_PIN = 12;
const int ECHO_PIN = 11;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
long durasi , jarak;
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
durasi = pulseIn(ECHO_PIN,HIGH);
jarak = durasi/58.8;
Serial.print("Hasil Pengukuran Ultrasonik : ");
Serial.print(jarak);
Serial.println("cm");
delay(1000);
}