#include <WiFi.h> //Library Board ESP32
#include <ESP32Servo.h>
// Deklarasi Pin untuk Sensor
int sensor = 13; // Sensor PIR Masuk
int BUTTON_PIN = 12;
//Definisi Variable
int hitung = 0;
bool sensor_ir;
Servo servo;
// Koneksi WiFi
const char *ssid = "Wokwi-GUEST"; // SSID Wifi
const char *password = ""; // WiFi password
WiFiClient espClient;
void setup() {
servo.attach(14);
servo.write(0);
pinMode(BUTTON_PIN, INPUT);
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
}
void loop() {
sensor_ir = digitalRead(sensor);
if(digitalRead(BUTTON_PIN) == HIGH) {
servo.write(0);
hitung=0;
}
if(sensor_ir == 1) {
hitung = hitung + 1;
Serial.print(hitung);
Serial.println();
delay(1000);
}
if(hitung = 5 ){
servo.write(90);
}
}