#define TRIGGER 13
#define ECHO 12
#define LED 7 

void setup() {
  // put your setup code here, to run once:
  pinMode(TRIGGER, OUTPUT);
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
}
int jarak;
long waktu;

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(TRIGGER, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIGGER, LOW);

  waktu =pulseIn(ECHO, HIGH);
  jarak = waktu / 58;
  if(jarak < 50) {
    digitalWrite(LED, HIGH);
  } else{
    digitalWrite(LED, LOW);
  }
  //jarak = 343 *(waktu / 1000.0 /2.0 /10.0);
  Serial.println(jarak);
delay(100);
}