const int pin_pir = 27;
const int trig = 14;
const int echo = 12;
int jarak,durasi;
int detect;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(pin_pir, INPUT);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
detect = digitalRead(pin_pir);
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(2);
digitalWrite(trig, LOW);
durasi = pulseIn(echo,HIGH);
jarak = (durasi * 0.034/2);
Serial.print("detek : ");
Serial.println(detect);
Serial.print("jarak : ");
Serial.println(jarak);
delay(2000); // this speeds up the simulation
}