Skip to content
MCU Atlas
ESP32ESP32-C3

Automatic chicken coop door: open at sunrise, lock at dusk, with an ESP32

An XIAO ESP32-C3 running ESPHome computes sunrise and sunset on-device, winches the coop door open each morning and lets it gravity-latch at dusk — predator-safe without the twice-daily trudge.

Difficulty:IntermediateSource available

What it is

An XIAO ESP32-C3 running ESPHome opens the coop door at actual sunrise and locks it at dusk with a gravity-fall latch — predator-safe automation without the twice-daily trudge.

What you need

How hard

Intermediate: the electronics are beginner-friendly, but the build adds outdoor mains wiring (GFCI, to local code) and a mechanical door, winch and latch you fabricate and verify yourself.

Photos

MCU Atlas's own wiring map for the coop door: the XIAO ESP32-C3 drives the L298N H-bridge motor lines on D4/GPIO6 (IN1) and D5/GPIO7 (IN2), interlocked in firmware; the top reed (open limit) reads D2/GPIO4 and the bottom reed (latched limit) D3/GPIO5, both with internal pull-ups; the weatherproof override button sits on D9/GPIO10. Strapping pins GPIO2, 8 and 9 are deliberately left unconnected. Hand-authored by MCU Atlas from our validated build spec — not a maker image.
The mechanism's safety asymmetry: the gearmotor and spool only winch the door up; closing releases the cable so the door falls by gravity into a positive mechanical latch that holds it shut with zero cable tension. The motor can never drive the door down onto a bird, and the closed door stays latched with no power at all. Hand-authored by MCU Atlas — not a maker image.

Photos: MCU Atlas (original diagram)

Key Facts

  • Opens at actual sunrise, locks at dusk — sunrise and sunset computed on the ESP32-C3 itself from your latitude and longitude (ESPHome sun component); seasons handled automatically, weather irrelevant
  • Motor only lifts: the 12 V gearmotor winches the door up; closing is gravity into a positive mechanical latch — the motor can never drive the door down onto a bird
  • Two reed switches confirm fully-open and fully-latched; LOCKED is published only after the bottom reed is stable for a full second
  • Firmware force-stops the motor after 10 s of travel no matter what; an obstruction gets exactly one retry, then a fault and stop
  • Sensor loss fails safe: an unplugged or miswired reed aborts motion; the recovery path closes and locks the door
  • Runs standalone if Home Assistant goes down (only the clock drifts); the weatherproof override button works with no network; one phone switch disables auto-opening
  • Core electronics about $50 in 2026-11-15 catalog prices (XIAO ESP32-C3, 12 V gearmotor, L298N, LM2596 buck, 50 W supply, two reed contacts) — roughly a quarter of a ~$200 commercial smart coop door
  • Original MCU Atlas ESPHome config — compile-verified 2026-11-15, behaviors follow a 12-of-12-scenario validated safety state machine; config-verified, not hardware-tested

About This Project

A raccoon only needs one evening. Every night the flock must be locked in; every morning let back out — twice a day, forever. A thumb-sized ESP32-C3 board that costs less than a bag of feed does it for you: the door opens at actual sunrise and locks itself at dusk with a latch no raccoon can push open. The core electronics come to roughly a quarter of what a commercial smart coop door costs, and you can fix, tune and extend them yourself.

Why this build

Backyard-chicken keepers are one of the most active corners of home automation DIY — the question “How would you build a smart door for a chicken coop?” has drawn years of replies, and a 2025 ESPHome build earned a Hackaday feature. This page follows Jeff Sandberg's documented design, rebuilt from scratch by MCU Atlas — our own wiring, firmware and safety engineering.

The reason to go beyond a store-bought unit is the trigger logic. Commercial light-sensor doors react to daylight level, and heavy overcast triggers them early — the commercial unit this design replaced locked hens out on stormy days. Clock-programmed units need seasonal reprogramming on a dim on-device display. This build computes sunrise and sunset on the ESP32 itself from your latitude and longitude, so seasons are handled automatically and weather doesn't matter. Time sync comes from Home Assistant, but if Home Assistant goes down the door keeps running on its own — only its clock slowly drifts. The feature the original author wanted most is standard: one switch on your phone disables auto-opening — lawn treatment, deep freeze, a medicated flock kept in.

How the door works

A Seeed XIAO ESP32-C3 runs ESPHome firmware and drives a 12 V gearmotor through an H-bridge. The motor spins a winch spool that pulls a light cable to raise the door; to close, it simply releases cable and the door falls by gravity into a latch it engages itself. That asymmetry is the heart of the design's animal safety: the motor can only lift the door — it can never drive it down onto a bird. Two magnetic reed switches confirm the fully-open and fully-latched positions.

Wiring it up

Our pin map is an MCU Atlas design, and it deliberately avoids the ESP32-C3's strapping pins (GPIO2, 8, 9), which a switch or sensor pulling them at reset can disturb. The two motor lines (D4/GPIO6 and D5/GPIO7 to the H-bridge's IN1 and IN2) are interlocked in firmware — both directions can never drive at once. The top reed, the open limit, sits on D2/GPIO4; the bottom reed, the latched limit, on D3/GPIO5; each has one leg to ground and the internal pull-up enabled. The weatherproof override button on D9/GPIO10 toggles the door with no network at all.

Power: mains — GFCI-protected and installed to local code outdoors — feeds the 12 V 50 W supply; 12 V goes to the H-bridge and to a buck converter set to 5.0 V for the logic rail. Set the buck output before connecting the board, and never power the XIAO from the H-bridge's onboard regulator: the source build documented intermittent sags from those converters and fixed them with a dedicated buck. Don't undersize the supply either — the original author's cheap “30 W” adapter capped at 15.6 W and caused brownout reboots until a 50 W unit went in. All grounds common; every cable enters through a gland, bottom entry preferred, with a weep hole at the enclosure's lowest point. The full pin table and wiring figure are on this page, and the build steps walk each connection.

The firmware

The configuration is written from scratch by MCU Atlas — the behaviors follow our validated design (twelve simulated safety scenarios, all passing), and the file passes ESPHome's schema check and compile. It is config-verified, not hardware-tested — treat the first week as commissioning. Key behaviors: sunrise opens the door (30-minute default delay) only if auto-open is on; sunset closes it unconditionally; the motor is force-stopped after 10 s no matter what; and “locked” is reported only after the bottom reed is stable for a full second. The complete YAML is linked in the Learn section, served verbatim.

Animal safety — read before you build

Crush protection is mechanical, not just programmed. The motor only winches the door up; the door closes by gravity and simply rests on anything beneath it. Firmware adds a second layer: the motor is force-stopped 10 seconds into any travel that doesn't reach an endstop, and an obstruction at closing time gets exactly one retry before the system faults and stops.

“Locked” means latched. The locked state is published only after the bottom reed has been stable for a full second — the door seated in its latch. An obstruction or a flapping sensor ends in a fault, never a false “locked”.

Power failure doesn't endanger the flock. The closed door is held by its mechanical latch with zero power, and a clevis-pin quick-release lets any human drop the door with the system dead. To keep it open by hand, pin the door in its rails — never rely on motor power to hold a door open.

Sensors that misbehave fail safe. An unplugged or miswired reed aborts motion; at night or with unknown time, the door's recovery path is to close and lock. The system's no-power, no-sensor resting state is latched shut.

Mains power is real electrical work. Outdoor mains must be GFCI-protected and installed to your local code; size any battery or solar variant from your motor's datasheet stall current, not guesses.

Credits and licences

Inspired by Jeff Sandberg's chicken-coop door build writeup (pdx.su) and his MIT-licensed ESPHome configuration (paradox460/HomeAssistantConfig); also by the budget eggcess build (sjev/eggcess) and the standalone ESP32-COOP project (ESP32-COOP/ESP32-COOP-DOC).

The eggcess and ESP32-COOP repositories carry no licence, so nothing from them (code, diagrams, 3D-printable files, photos) is reproduced here — they are linked as inspiration only. The prose, wiring, pin map, firmware and any diagrams on this page are original to MCU Atlas. Facts, specifications and prices are cited to their sources. MCU Atlas is not affiliated with any maker or retailer linked above.

Automatic chicken coop door: open at sunrise, lock at dusk, with an ESP32

How to Build It

Fabricate the door and latch, mount the winch and reed sensors, wire the XIAO ESP32-C3 and H-bridge, then flash our ESPHome config and verify the safety behaviors before trusting the schedule.

Parts Needed

  • Seeed XIAO ESP32-C3
  • 12 V gearmotor (100 RPM, 37 mm gearbox) and an L298N-class dual H-bridge
  • LM2596-class buck converter (12 V to 5 V) and a 12 V 50 W supply (Mean Well LRS-50-12 class)
  • 2 magnetic reed contacts (door/window type)
  • Weatherproof momentary override button
  • Sliding door panel, side channels, positive latch, winch spool, light cable with clevis pin, IP65-class enclosure with cable glands

Steps

  1. 1

    Build the door and rails

    A rigid panel sliding in side channels, ending its travel in a positive mechanical latch that holds the door closed without any cable tension — the cable never holds the door shut. Keep the door light: ply is fine.

  2. 2

    Mount the winch

    Mount the motor and spool above the door opening; attach the cable to the door through a clevis-pin quick release so any human can drop the door with the system dead.

  3. 3

    Place the reed sensors

    Magnet on the door edge, sensors on the rail at full-open and full-closed. Position the bottom sensor so contact means the door is seated in its latch, not merely low.

  4. 4

    Mount the enclosure

    Electronics box above the door opening, out of pecking and water range. Cables enter through glands (bottom entry preferred) with a weep hole at the enclosure's lowest point.

  5. 5

    Wire the logic

    Full pin map (MCU Atlas design, avoiding the ESP32-C3 strapping pins GPIO2/8/9): D4/GPIO6 to L298N IN1 (motor up) and D5/GPIO7 to IN2 (motor down) — the firmware interlock forbids both at once. D2/GPIO4 is the top reed (open limit) and D3/GPIO5 the bottom reed (close limit), each with one leg to the pin and the other to GND. D9/GPIO10 is the override button to GND. See the wiring figure on the project page.

  6. 6

    Wire the power

    Outdoor mains must be GFCI-protected and installed to local code. 12 V feeds the L298N and the buck converter; remove the L298N's onboard 5 V-regulator jumper and never power the XIAO from it. Set the buck output to 5.0 V BEFORE connecting the XIAO. Use a real 50 W-class supply — the source build's cheap '30 W' adapter capped at 15.6 W and caused brownout reboots. All grounds common.

  7. 7

    Flash and calibrate

    Install ESPHome, set your latitude and longitude plus the open/close delays, and exercise the door with the override button before trusting the schedule. The complete YAML is linked in the project page's Learn section — served verbatim, compile-verified.

  8. 8

    Verify like you mean it

    No gap of 20 mm (3/4 in) or larger anywhere around the locked door — our conservative design gate, not an external standard; check your own predator-control guidance. Push the locked door by hand: the latch, not the cable, must resist. Run a 20-cycle soak test with zero unexpected reboots.

  9. 9

    Commission for a week

    The firmware is config-verified, not hardware-tested — treat the first week as commissioning. Watch the door through a few sunrises and sunsets, and keep the override button path fresh in your muscle memory.

Bill of Materials

Parts list

8 parts · 3 linked

Heads up: some Buy links are affiliate links. If you buy through one, MCU Atlas may earn a small commission at no extra cost to you. It never changes which parts we list. How this works

1× Seeed Studio XIAO ESP32-C3

Thumb-size ESP32-C3 host; the config's board target is seeed_xiao_esp32c3. $5.99 at Seeed Studio (checked 2026-11-15).

1× 12 V gearmotor, 100 RPM, 37 mm gearbox

UNLINKED — no catalog match for this motor class. $14.99 (Amazon, checked 2026-11-15). Size any battery or solar variant from the datasheet stall current, not guesses.

No verified link — check the original project

1× L298N dual H-bridge module

L298N-class dual H-bridge, $7.39 (Amazon, checked 2026-11-15). Remove the onboard 5 V-regulator jumper — never power the XIAO from it.

No verified link — check the original project

1× LM2596 buck converter (12 V → 5 V)

Mini 5 V buck, about $1.10 (Amazon, checked 2026-11-15). LM2596-class — set the output to 5.0 V BEFORE connecting the XIAO.

1× Mean Well LRS-50-12 (12 V 50 W supply)

UNLINKED — we catalog no 12 V PSU of this class. $12.00 at DigiKey (checked 2026-11-15). Deliberately oversized: the source build's cheap “30 W” adapter capped at 15.6 W and caused brownout reboots.

No verified link — check the original project

2× Magnetic reed contacts (door/window type)

One at full-open, one at full-latched. $3.95 each at Adafruit (checked 2026-11-15).

1× Weatherproof momentary override button

UNLINKED — panel-mount momentary from any electronics catalog, roughly $3–6 (checked 2026-11-15).

No verified link — check the original project

1× Door panel, slide channels, latch, winch spool, cable + clevis pin, enclosure

UNLINKED — hardware-store and 3D-printed parts, roughly $10–25 (checked 2026-11-15). The latch must hold the door closed with zero cable tension; the cable attaches through a clevis-pin quick release.

No verified link — check the original project
Download CSV

Related Projects

Motorize dumb roller blinds with an ESP32 and a stepper
Illustration
ESP32
An ESP32 and a cheap 28BYJ-48 stepper motorize ordinary roller blinds from a web UI or MQTT, with Home Assistant cover integration. Low-voltage DC only.
Beginner·Code
5 parts listed
ratgdo: local Wi-Fi control for Chamberlain and LiftMaster garage doors
Illustration
ESP32ESP8266
A small control board that wires to your garage door opener and gives local ESPHome, HomeKit or MQTT control, including Security+ 2.0 openers.
Beginner·Code
2 parts listed
ESP32 pool controller: automated filtration and solar heating over MQTT
Illustration
ESP32
Turn an ESP32, a relay module and two temperature probes into a set-and-forget pool controller: automated filtration, solar heating and MQTT for Home Assistant.
Intermediate·Code
8 parts listed