# Servo-Controlled IoT Doggie Door

<img src="doggie-door-perspective.png" width="40%" />
<img src="photo.png" width="40%" />
<br style="clear:both">

## Materials

- Hobby servo
- Small pointy screws (apx 4mm head, 5mm length, 2mm thread, coarse)
- [Medium sized PetSafe Wall Entry doggie door](https://www.petsafe.com/product/wall-entry-pet-door/?sku=ZPA00-16201&collection-location=/shop/dog/doors/)
- Arduino Ethernet
- 9v Power Supply within reach of the door
- Ethernet cable within reach of the door
- 5v voltage regulator and breadboard/wires
- 2x Medium-sized limit switches
- 3D Printer
- About 2.5 feet of ball-chain (like ceiling fan pull chain)
- A thin sturdy piece of metal to disable the door latch
- Appropriate cable management

## Printing

Print the following files:
- [[doggie-door.stl]]
- 2x [[parametric_ball_pulley-improved-with-flares.stl]]
- [[limit-switch-mount-sideways.stl]]
- [[limit-switch-mount-sideways-right.stl]]
- [[limit-switch-flag-and-chain-catch-printable.stl]]
- [[LBracket_Parametric_rev9.stl]]
- [[Futaba_3001_Servo_Mount.stl]]

The other files are just for posterity.

## Assembly

<img src="doggie-door-top.png" />

Refer to the doggie-door.scad file or screenshots above for assembly.

- Solder jumper wires to the limit switches: they should be Normally Closed so that the Arduino knows that they're connected (fails safe if they get disconnected)
- Attach the parts of the doggie-door.stl together
- Attach the Servo Mount to the wide short mounting block at the top facing left
- Attach the servo to the servo mount
- Attach the LBracket to the tall narrow mounting block at the top also facing left
- Attach the limit switches to the left and right limit switch mounts: each one attaches with two screws on the back of the switch, so pay attention to which mounting direction makes sense
- Attach the limit switch mounts to the backboard using the provided pilot holes
- Attach the ball pulleys to the servo and to the LBracket
- Attach the limit switch flag and chain catch to the bottom-right corner of the doggie door, just above the corner radius and snugly so the flag can't rotate

## Programming

- Flash your Arduino Ethernet with doggie-door.ino
- Look in your router's DHCP logs or use an IP scanner for the MAC: DE:AD:BE:EF:FA:DE
- Go to the Arduino's IP in your browser: http://192.168.1.100
- It should display a status page with buttons

## Wiring

- Use a breadboard to wire up your voltage regulator to deliver power to the servo:

```
         [  7805 ]
          |  |  |
        +9v  G  +5v
---------IN  |  OUT----- Servo +
             +---------- Servo -
```

- Wire the servo's control pin to Arduino pin 9
- Wire the limit switch common pins to Arduino Ground
- Wire the limit switch NC pins to Arduino 2 (top) and 3 (bottom)

## Testing

- With the chain unattached, try the Up and Down buttons on the web interface (or via serial, if preferred) and ensure that the servo works and motion stops promptly when the limit switches are hit.
- The side of the chain closest to the wall should move up until the top limit switch is touched (really any limit switch, but that's ok) and importantly should refuse to continue up as long as the top switch is engaged. It should be able to move downwards. Repeat this test for the opposite direction and switch.
- Attach the chain to the door but leave everything on a clear table so the door can slide freely without damage. Try again while gently guiding the door up and down.

## Installation

- Wire the 9v power and an ethernet cable to the door's location.
- Insert a thin sturdy piece of material in the door's latch so it never fully latches.
- Unscrew the right-hand side screws of the doggie door and use them to install the doggie door control assembly. You might need to install the door before installing the control assembly to avoid interference.
- Ensure that the chain is tight: slack will cause the pulleys to skip and fail to move the door.

## Usage

- Either use the buttons on the Arduino's webpage
OR
- Create a RESTful Command entry in HomeAssistant or similar:

```configuration.yaml
rest_command:
  doggie-door-up:
    url: http://192.168.1.100/?u
  doggie-door-down:
    url: http://192.168.1.100/?d
  doggie-door-status:
    url: http://192.168.1.100/??
```

  - Restart HomeAssistant and create buttons or automations to the `rest.doggie-door-*` services.

## TODO

- Screw holes for the chain mount
- Safety wall, mount holes and cable management for Arduino
- Drill out the centers of the pulleys for rotation and attachment