PIR Sensor Based Automatic Pet Door

Project Overview

This project creates an automatic pet door that opens when your pet approaches. A PIR sensor detects your pet’s presence, and a servo motor unlocks and opens the door. After your pet passes through, the door closes automatically.

Difficulty: Intermediate
Estimated time: 3-4 hours
Estimated cost: $35-50

How It Works

A PIR sensor mounted near the pet door detects your pet’s approach. When motion is detected, the Arduino activates a servo motor that unlocks and opens the door. After a set delay, the servo returns to the closed position. An optional RFID reader can identify your pet to prevent other animals from entering.

Materials Needed

  • Arduino Uno or Nano (1)
  • HC-SR501 PIR sensor (1)
  • Servo motor (MG995 for larger doors, SG90 for lightweight)
  • Pet door frame (existing or custom built)
  • Jumper wires
  • Power supply (5V 2A or battery pack)
  • Optional: RFID reader module (RC522) and RFID tag for pet collar

Circuit Diagram

Connection Table

VCC

5V

GND

GND

OUT

Digital Pin 2

Red (VCC)

5V

Brown (GND)

GND

Orange (Signal)

Digital Pin 9

SDA

Digital Pin 10

SCK

Digital Pin 13

MOSI

Digital Pin 11

MISO

Digital Pin 12

Arduino Code (Basic Version)

// Automatic Pet Door with PIR Sensor
#include <Servo.h>

Servo doorServo;

const int pirPin = 2;
const int servoPin = 9;

const int closedPos = 0;
const int openPos = 90;

unsigned long lastTriggerTime = 0;
const unsigned long openDuration = 5000;
bool doorOpen = false;

void setup() {
  pinMode(pirPin, INPUT);
  doorServo.attach(servoPin);
  doorServo.write(closedPos);
  
  delay(60000);
}

void openDoor() {
  doorServo.write(openPos);
  doorOpen = true;
  lastTriggerTime = millis();
}

void closeDoor() {
  doorServo.write(closedPos);
  doorOpen = false;
}

void loop() {
  bool motion = digitalRead(pirPin) == HIGH;
  
  if (motion && !doorOpen) {
    openDoor();
  }
  
  if (doorOpen && (millis() - lastTriggerTime > openDuration)) {
    closeDoor();
  }
  
  delay(100);
}

Arduino Code (RFID Version)

// Automatic Pet Door with PIR and RFID
#include <Servo.h>
#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN 5
#define SS_PIN 10

Servo doorServo;
MFRC522 mfrc522(SS_PIN, RST_PIN);

const int pirPin = 2;
const int servoPin = 9;

const int closedPos = 0;
const int openPos = 90;

// Store your pet's RFID tag UID here
byte petUID[] = {0xAA, 0xBB, 0xCC, 0xDD};

unsigned long lastTriggerTime = 0;
const unsigned long openDuration = 5000;
bool doorOpen = false;

void setup() {
  pinMode(pirPin, INPUT);
  doorServo.attach(servoPin);
  doorServo.write(closedPos);
  
  SPI.begin();
  mfrc522.PCD_Init();
  
  delay(60000);
}

bool isAuthorized() {
  if (!mfrc522.PICC_IsNewCardPresent()) return false;
  if (!mfrc522.PICC_ReadCardSerial()) return false;
  
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    if (mfrc522.uid.uidByte[i] != petUID[i]) {
      mfrc522.PICC_HaltA();
      return false;
    }
  }
  mfrc522.PICC_HaltA();
  return true;
}

void openDoor() {
  doorServo.write(openPos);
  doorOpen = true;
  lastTriggerTime = millis();
}

void closeDoor() {
  doorServo.write(closedPos);
  doorOpen = false;
}

void loop() {
  bool motion = digitalRead(pirPin) == HIGH;
  
  if (motion && !doorOpen && isAuthorized()) {
    openDoor();
  }
  
  if (doorOpen && (millis() - lastTriggerTime > openDuration)) {
    closeDoor();
  }
  
  delay(100);
}

Mechanical Assembly

  1. Mount the servo motor on the pet door frame.
  2. Attach a linkage rod from the servo horn to the door latch.
  3. Install the PIR sensor at pet height (0.3-0.5m) near the door.
  4. If using RFID, attach the RFID tag to your pet’s collar.

Installation Steps

  1. Assemble the circuit on a breadboard and test.
  2. Adjust servo positions based on your door mechanism.
  3. Mount the sensor at the correct height for your pet.
  4. If using RFID, read your pet’s tag UID and update the code.
  5. Enclose electronics in a waterproof box near the door.

Project Extensions

  • Add a buzzer to alert when the door opens
  • Add an LED to indicate door status
  • Add Wi-Fi to receive notifications when your pet enters/exits
  • Add a second PIR sensor to detect direction (in/out)
  • Add a door position sensor to detect if door is stuck

Conclusion

This automatic pet door gives your pet freedom to come and go while keeping unwanted animals out.

Leave a Reply

Your email address will not be published. Required fields are marked *

Component Pin Arduino Pin
PIR Sensor PIR Sensor PIR Sensor Servo Motor Servo Motor Servo Motor RC522 RFID (optional) RC522 RFID RC522 RFID RC522 RFID