#include <Servo.h>
Servo myServo;
const int servoPin = 9;
const int pirSensor = 2;
const int ledPin = 13;
const int buzzerPin = 8;
int pirState = LOW;
int val = 0;
void setup() {
myServo.attach(servoPin);
pinMode(pirSensor, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
val = digitalRead(pirSensor);
if (val == HIGH) {
digitalWrite(ledPin, HIGH);
tone(buzzerPin, 1000);
myServo.write(90); // Put the servo in the open position (adjust the angle as needed)
delay(5000); // Delay for 5 seconds
myServo.write(0); // Put the servo back to the closed position
} else {
digitalWrite(ledPin, LOW);
noTone(buzzerPin);
}
}