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
| Component |
Pin |
Arduino Pin |
PIR Sensor |
VCC
5V
PIR Sensor |
GND
GND
PIR Sensor |
OUT
Digital Pin 2
Servo Motor |
Red (VCC)
5V
Servo Motor |
Brown (GND)
GND
Servo Motor |
Orange (Signal)
Digital Pin 9
RC522 RFID (optional) |
SDA
Digital Pin 10
RC522 RFID |
SCK
Digital Pin 13
RC522 RFID |
MOSI
Digital Pin 11
RC522 RFID |
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
- Mount the servo motor on the pet door frame.
- Attach a linkage rod from the servo horn to the door latch.
- Install the PIR sensor at pet height (0.3-0.5m) near the door.
- If using RFID, attach the RFID tag to your pet’s collar.
Installation Steps
- Assemble the circuit on a breadboard and test.
- Adjust servo positions based on your door mechanism.
- Mount the sensor at the correct height for your pet.
- If using RFID, read your pet’s tag UID and update the code.
- 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.