// PIR Motion Senor attached to LED (Replacement for DC motor) by Ashwin Jayan
#include <WiFi.h>
#include <ESP32Servo.h> //Inlcudes the servo library
const char *ssid = "Wokwi-GUEST"; // SSID Wifi
const char *password = ""; // WiFi password
WiFiClient espClient;
Servo servo;
void setup() {
Serial.begin(115200);
pinMode(35, INPUT); //Checks the status of the motion sensor
servo.attach(32); //Takes the servo input pin as 10
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() {
int input = digitalRead(35); //Reads the value of the 8 pin
Serial.println(input); //Prodcues if it is high or low on the terminal
if(input == 1) { //Checks if the motion sensor has been tripped
int position = 0; //Makes current position of servo as 0
servo.write(100); //Makes the servo motor move by 100 degrees
delay(1000);
}
if(input == 0){ //If not trippped
servo.write(0);//Returns the servo back to original position
delay(1000);
}
delay(1800); //Delay between the motion sensor and servo
}