#include <Servo.h>
int pirPin = 2; // pin to read the PIR sensor
int photoPin = A0; // pin to read the photoresistor
int ledPin = 11; // pin to control the LED
int buzzerPin = 12; // pin to control the buzzer
int servoPin = 9; // pin to control the servo motor
Servo myServo;
void setup() {
pinMode(pirPin, INPUT);
pinMode(photoPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
myServo.attach(servoPin);
}
void loop() {
// read PIR sensor
int pirValue = digitalRead(pirPin);
if (pirValue == HIGH) {
digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);
delay(500);
digitalWrite(buzzerPin, LOW);
myServo.write(90); // unlock the door
} else {
digitalWrite(ledPin, LOW);
digitalWrite(buzzerPin, LOW);
myServo.write(0); // lock the door
}
// read photoresistor
int photoValue = analogRead(photoPin);
Serial.print("Light level: ");
Serial.println(photoValue);
if (photoValue > 500) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
delay(2000);
}