Introduction: Automatic Cat Door (prototype)

Picture of Automatic Cat Door (prototype)

I live with a bunch of cats and they're allowed to go outside through a cat door. However, they like to go outside a lot which not only gets the cat door dirty easily, but it also makes a lot of sound when they go through. I decided I could try and make an automatic cat door prototype to solve both these problems and prevent me from waking up in the night!

Step 1: Preparing to Build the Prototype

Picture of Preparing to Build the Prototype

You'll need a selection of items for this project. Here's what I used:

  • Arduino UNO
  • Micro servo motor
  • Breadboard
  • 10 wires
  • Ultrasonic sensor (HC-SR04)

Optional:

  • 3 LEDs to display the current status of the cat door (maybe the cat could learn and understand these)
  • 3 resistors (10k ohm / 5% tolerance)

Step 2: Setting Up the Breadboard Wiring

Picture of Setting Up the Breadboard Wiring

Let's connect everything up first. We will start with the wiring for the power, ground and LEDs.

Step 3: Adding Resistors and LEDs on the Board

Picture of Adding Resistors and LEDs on the Board

Next up we will add the resistors and LEDs to the board.

Step 4: Preparing the Ultrasonic Sensor

Picture of Preparing the Ultrasonic Sensor

Add wiring for the ultrasonic sensor and connect the sensor to the board.

Step 5: Add the Servo Motor to the Board

Picture of Add the Servo Motor to the Board

Lastly we'll add the servo motor to the board. All that's left to do is code and finalize the cat door system!

Step 6: Building the Code

Picture of Building the Code

To make the cat door detect things, display the status and rotate the servo we need to build some code!

#include 
#define ledRed 2
#define ledYellow 3
#define ledGreen 4
#define pinEcho 12
#define pinTrig 13
const int MAX_DISTANCE = 10;
Servo servo;
bool isOpen;
bool isOpening;
void setup() 
{
    Serial.begin(9600);
    pinMode(ledRed, OUTPUT);
    pinMode(ledYellow, OUTPUT);
    pinMode(ledGreen, OUTPUT);
    pinMode(pinTrig, OUTPUT);
    pinMode(pinEcho, INPUT);
    servo.attach(9);
    
    isOpen = false;
    isOpening = false;
}
void loop() 
{
    if (getDistance() <= MAX_DISTANCE)
    {
        digitalWrite(ledGreen, LOW);
        digitalWrite(ledYellow, HIGH);
        digitalWrite(ledRed, LOW);
        
        Serial.println("Checking if someone stays here.");
        delay(3000);
        if (getDistance() <= MAX_DISTANCE)
        {
            digitalWrite(ledGreen, HIGH);
            digitalWrite(ledYellow, LOW);
            digitalWrite(ledRed, LOW);
            
            Serial.println("Someone still here... Checking if gate is open...");
            if (!isOpen)
            {
                Serial.println("Gate is closed. Opening gate.");
                
                servo.write(180);
            
                delay(3000);
                Serial.println("Opened gate.");
            
                isOpen = true;
            }
            else
            {
                Serial.println("Gate is still open. Waiting for someone to leave.");
                delay(3000);
            }
        }
        else
        {
            Serial.println("Someone has left. Ignoring.");
        }
    }
    else
    {
        digitalWrite(ledGreen, LOW);
        digitalWrite(ledYellow, LOW);
        digitalWrite(ledRed, HIGH);
        
        // Serial.println("No one here. Attempting to close gate.");
      
        if (isOpen)
        {
            Serial.println("Gate is opened. Closing gate.");
            servo.write(90);
            delay(3000);
            Serial.println("Gate is closed.");
            
            isOpen = false;
        }
    }
}
int getDistance()
{
    long duration;
    int distance;
    digitalWrite(pinTrig, LOW);
    delayMicroseconds(2);
    digitalWrite(pinTrig, HIGH);
    delayMicroseconds(10);
    digitalWrite(pinTrig, LOW);
    duration = pulseIn(pinEcho, HIGH);
    distance = duration * 0.034 / 2;
    return distance;
} 

Upload it to your Arduino and test it out!

Step 7: Optional: Finishing Up Your Project

Now that you're set with the basic structure of the project you're free to apply it to any cat door or create your own! I created my prototype with some cardboard to see if this would work (which it indeed does!).

Thank you for viewing this Instructable. If you have any cats, make sure to try it out!

Comments

Swansong (author)2017-08-14

That's neat :) What do you plan to build the final project with?

About This Instructable

354views

6favorites

License:

More by HKUstudent:Automatic Cat Door (prototype)
Add instructable to: