An automated hen-house control system built around an ESP32-S3. The system controls a guillotine-style chicken door powered by a geared motor, providing automatic opening and closing while incorporating multiple safety features to protect the hens and the mechanism.
The controller also provides environmental monitoring, automatic lighting, an OLED user interface, event logging, Wi-Fi time synchronisation and long-term temperature/humidity recording.
- π Automatic guillotine-style door
- βοΈ Geared motor drive with OPEN/CLOSE control
- π Sunrise/sunset based scheduling
- π Separate GMT and BST schedules
- π‘οΈ Inside and outside temperature/humidity monitoring
- βοΈ Cold-weather morning opening delay
- π‘ Automatic evening coop lighting
- π΄ Progressive night/bedtime warning LEDs
- π‘οΈ Door obstruction detection and recovery
- πͺ Limit-switch monitoring and motor timeout protection
- π Fault detection and lockout system
- π Audible fault alarm
- π 14-day environmental history
- π 100-entry event log
- π°οΈ DS3231 RTC with NTP time synchronisation
- πΆ Wi-Fi monitoring and automatic reconnection
- π₯οΈ 128Γ64 SH1106 1.3" OLED display
- ποΈ Rotary encoder user interface
- πΎ Persistent settings and data storage
- π Watchdog protection for unattended operation
The hen house uses a vertical guillotine-style door driven by a geared motor.
The motor is controlled in both directions to raise and lower the door, with dedicated limit switches confirming the fully open and fully closed positions.
The door controller uses a state-machine architecture rather than simply running the motor for a predetermined time.
- Separate OPEN and CLOSED limit switches
- Motor direction interlock
- 50 ms direction-change safety delay
- motor timeout
- Door position detection at startup
- Automatic homing if the door position is unknown
- Limit-switch conflict detection
- Closing obstruction detection
- Automatic reopening after an obstruction
- Times chicken-release period
- Maximum obstruction retries
- Fault and lockout states
- Manual fault reset
If the door encounters an obstruction while closing, the door automatically reopens to allow the Chicken to clear the area before attempting to close again.
Door operation can be configured around sunrise and sunset, or fixed open times.
Separate settings are available for:
- GMT / winter
- BST / summer
The controller automatically detects UK daylight-saving time and selects the appropriate schedule.
The fixed opening times can be disabled to allow the door to operate relative to sunrise instead.
An external waterproof SHT30 temperature/humidity sensor monitors the outside temperature.
If the outside temperature is below the configured threshold when the morning door opening is due, the system can delay opening.
If the temperature rises above the threshold during the delay, the door can open immediately.
A manual override is also available to allow the door to open regardless of the outside temperature.
A dedicated blue LED indicates when the outside temperature is below the configured cold threshold.
Two Sensirion SHT3x-family sensors are used.
| Sensor | Location | IΒ²C Address |
|---|---|---|
| SHT31 | Inside hen house | 0x45 |
| SHT30 | Outside | 0x44 |
The sensors monitor:
- Temperature
- Relative humidity
- Daily minimum temperature
- Daily maximum temperature
- Daily minimum humidity
- Daily maximum humidity
- Time of recorded extremes
Approximately 14 days of environmental history is retained for both inside and outside measurements.
Data is stored using the ESP32 Preferences system so that it survives power loss.
The controller operates the hen-house light automatically around sunset.
The evening chicken homing system uses two LEDs to provide a visual indication as closing time approaches.
The homing sequence progressively increases the flashing rate as the door-closing time gets closer.
Once the door is confirmed fully closed, the LEDs enter night mode and alternate throughout the night.
The coop light can also be operated manually using the rotary encoder.
A 128Γ64 SH1106 OLED provides information and limited control without requiring a computer or web interface.
The rotary encoder is used for navigation and manual control.
- Main Status
- Today's Schedule
- Inside Environment
- Outside Environment
- Manual Controls
- Event History
- Wi-Fi Status
- System Time
The display normally refreshes only when required to reduce unnecessary IΒ²C activity.
The OLED also enters power-save mode after a period of inactivity.
The controller maintains a circular 100-entry event history with time stamps.
Events include:
- Automatic door opening
- Automatic door closing
- Manual door operation
- Light operation
- Cold-weather delays
- Obstruction detection
- Door timeouts
- Homing operations
- Faults
- Wi-Fi events
- Sensor faults
- System resets
This provides a useful history when diagnosing the system or checking its operation.
The system uses two time sources:
NTP via Wi-Fi
DS3231 RTC
When Wi-Fi is available, the ESP32 synchronises its clock using NTP and updates the DS3231.
If Wi-Fi is unavailable, the RTC provides a backup time source so that automatic door operation can continue.
UK GMT/BST daylight-saving rules are handled automatically.
Wi-Fi is primarily used for:
- NTP time synchronisation
- Connection monitoring
- Automatic reconnection
- Signal-strength monitoring
- IP-address display
The controller is designed so that normal hen-house automation does not depend on a permanent Wi-Fi connection.
ESP32-S3 WROOM-1 / N16R8
1.3" 128Γ64 SH1106 OLED
- Sensirion SHT31 β inside
- Sensirion SHT30 β outside (waterproof)
DS3231
- Guillotine-style vertical door
- Geared DC motor
- Motor driver
- OPEN limit switch (reed switch)
- CLOSED limit switch (reed switch)
- KY-040 rotary encoder
| Function | GPIO |
|---|---|
| IΒ²C SDA | 8 |
| IΒ²C SCL | 9 |
| Rotary Encoder CLK | 4 |
| Rotary Encoder DT | 5 |
| Encoder Button | 18 |
| Door Motor OPEN | 41 |
| Door Motor CLOSE | 42 |
| Door OPEN Limit | 15 |
| Door CLOSED Limit | 16 |
| Coop Light | 17 |
| Green Status LED | 6 |
| Red Fault LED | 7 |
| Night LED 1 | 11 |
| Night LED 2 | 12 |
| Cold Temperature LED | 13 |
All IΒ²C devices share the same bus at 100 kHz.
Because the system controls a physical door containing live animals, safety is a major part of the design.
The controller does not rely on a single timing mechanism to determine door position.
Instead it combines:
Limit switches + motor timeout + state machine + obstruction detection + recovery + fault lockout
The system also performs a door-position check during startup and will attempt to home the door if its position cannot be established.
Current Version: V2.14
The project has evolved through several revisions, including the transition from a DHT22 sensor to the SHT3x family and the addition of the external temperature sensor and cold-weather door protection. Additional refinements and tweaks to get as close to a plug and play install as i can.
- SHT31 inside sensor
- SHT30 outside sensor
- Dual IΒ²C sensor support
- Outside environmental monitoring
- Cold-weather opening delay
- Temperature-based delay cancellation
- Persistent environmental history
- Improved event logging
- Environmental log maintenance functions
The OLED, DS3231 and both temperature sensors share the same IΒ²C bus.
Reliable physical wiring is important for IΒ²C operation. In testing, intermittent display problems were ultimately traced to unreliable fly-lead connections between the ESP32-S3 and OLED. Replacing the leads and soldering the connections resolved the problem.
This is worth considering when reproducing the hardware, particularly where longer or flexible wiring is used.
This is a personal DIY automation project.
A motorised animal door should be thoroughly tested under real operating conditions before being left unattended. Particular attention should be given to the mechanical door design, limit switches, obstruction detection, motor drive system and emergency/fault conditions.
Hen House Automation β ESP32-S3
Automatic door β’ Environmental monitoring β’ Lighting β’ Safety β’ Data logging