#include <Servo.h>
Servo myServo;
const int pirPin = 8; // PIR Motion sensor pin
int servoPin = 6; // Servo pin
void setup() {
pinMode(pirPin, INPUT);
Serial1.begin(115200);
myServo.attach(6);
Serial1.println("====Smart Door====");
}
void loop() {
int pirValue = digitalRead(pirPin);
if (pirValue == HIGH) {
Serial1.println("Motion detected!");
openDoor();
delay(1000); // Wait for the door to open
} else {
closeDoor();
delay(1000);
}
delay(1000);
}
void openDoor() {
myServo.write(45); // Open the door (45 degrees)
Serial1.println("Door opened");
}
void closeDoor() {
myServo.write(90); // Close the door (back to the initial position)
Serial1.println("Door closed");
}