#include <Servo.h>
Servo myServo;
const int trig = 2;
const int echo = 3;
long duration;
int Jarak;
void setup() {
  // put your setup code here, to run once:
myServo.attach(5);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
Serial.begin(9600);
}

void loop() {
//Clear the trig pin for 2 microseconds
digitalWrite(trig, LOW);
delayMicroseconds(2);

//Set the trig pin on HIGH for 10 microseconds and then turn it LOW (OFF)
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echo, HIGH);
// Calculating the distance
Jarak = duration * 0.034 / 2;
// Prints the distance on the Serial Monitor
Serial.print("Jarak: ");
Serial.println(Jarak);

if(Jarak <=10) {
  myServo.write(180);
}
else {
  myServo.write(0);
}
}
$abcdeabcde151015202530354045505560fghijfghij