#define ECHO_PIN 2
#define TRIG_PIN 3
float X=1.006;

void setup() {
  Serial.begin(115200);
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
}

void loop() {
  // Generate Ultrasonic Signal
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);

  // Read Ultrasonic Signal
  int duration = pulseIn(ECHO_PIN, HIGH);
  float distance = duration * 0.034 * X / 2;
  Serial.print("Jarak: ");
  Serial.print(distance);
  //Serial.println(distance);
  Serial.println(" CM");
  delay(100);
}