Is this what you need?
// motion detector senses something then a door opens
const int MOTION_PIN = 2;
const byte LED_PIN = 13; // LED pin - active-high
const byte BUTTON_PIN = 12;
#include <Servo.h>
Servo servo1;
void setup()
{
Serial.begin(9600);
// The PIR sensor's output signal is an open-collector,
// so a pull-up resistor is required:
pinMode(MOTION_PIN, INPUT_PULLUP);
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
servo1.attach(9);
}
void loop()
{
int proximity = digitalRead(MOTION_PIN);
if (proximity == LOW) // If the sensor's output goes low, motion is detected
{
Serial.println("Motion detected!");
openDoor();
holdDoor();
closeDoor();
holdDoor();
// wait for pressed button to open door from insided then
int button_state = digitalRead(BUTTON_PIN);
if (button_state == LOW) // If the button press
{
openDoor();
holdDoor();
closeDoor();
holdDoor();
}
}
else
{
digitalWrite(LED_PIN, LOW);
Serial.println("No Motion Detected");
}
}
void holdDoor(){
servo1.write(90);
delay(5000);
}
void openDoor(){
servo1.write(0);
delay(6000);
}
void closeDoor(){
servo1.write(180);
delay(6000);
}