Super Simple Automatic Chicken Coop Door

Pet chickens like to run around and scratch up their yard during the day, but must be safely locked away at night to prevent predators from eating them. Most chicken-keepers accept the twice-daily chore of letting the hens out in the morning, and locking them up at night. This is a project to automate that task using an inexpensive sensor, an arduino microcontroller, and a linear actuator. As a bonus this project runs from a solar-charged battery!

This project is pretty hacky looking or you could say it has an agricultural feel to it, but it’s been running solid for over a month so I thought I would record it here. Bring on the bailing wire!


This door controller uses a 12V linear actuator with end stop switches to simplify the controls. The motor controller can keep trying to run the motor and the end stop switches automatically stop it when it reaches the travel limit. This allows the simplest control algorithm- depending on the light level measured, the motor is either opening, closing, or off:

if (lightLevel > daytime) Motor on in open direction else if (lightLevel < dark) Motor on in close direction else Motor off
Code language: JavaScript (javascript)

All the electronics are under the blue bucket!


My first attempt at the chicken door used an ESP32 camera module so that it would take a photo of the hens when it let them in and out. I used an internet time source and set the door to open and close at a specified time, and sleep for low power in between. Unfortunately the boards I had would not reliably wake up from sleep and connect to the internet, and they draw too much power to run constantly from the battery system I had, so I shelved this attempt and went with the simplest system I could imagine.


There is a photocell sensor, a resistor in series (forming a voltage divider), the arduino pro micro, and an L298 H-Bridge motor driver board. The voltage divider with the sensor is powered by IO pins just to keep the wiring simple.

A toggle switch in parallel with the sensor circuit allows you to force the door open or closed as needed.

The L298 is not rated for the max current that the actuator can pull, but in this application I never measured more than about 0.5A draw and that is fine. Use the jumper that comes with the L298 Module to tie the Enable pin high.

I teach a mechatronics class at Cal Maritime, and the sensor, controller, and motor driver are parts that we use in the course and so I have a handy supply.

Not shown in the schematic is the solar panel– this is in parallel with the battery and has its own internal charging circuit. Just connect red to red and black to black and put it in the sun!

I had a spare 20 Ah SLA 12V battery, I think you could go with a much smaller one though, 5-7 Ah would be plenty I imagine, it just has to make it through the night.

Once change to the circuit shown- rather than use the linear 5V regulator on the L298 board, which is rather power-hungry, I added a DC-DC converter to efficiently make the 5V power for the arduino and the L298. If you pull the jumper from the 5V regulator on the L298 module you can feed it 5V and everything remains happy.

I used an arduino pro micro clone for the controller board as it does not have a separate USB chip. This means when the main chip goes to sleep the whole board is asleep. The arduino runs its algorithm then sleeps for the maximum time (8 seconds) then wakes up and checks again. When sleeping, the pins stay active so the motor will keep running. If you use the sleep you won’t be able to reprogram the chip unless you short the reset pin to ground briefly when it is trying to upload the code. You can skip the low-power sleep mode by connecting IO pin 2 to IO pin 3 (useful for testing as the USB serial stays active), or by deleting that section of the code.

Basic Circuit
The actual coop door controller system. It sits on a shelf with a bucket on top


The linear actuator and the door are the basic mechanical system. Getting the linkage geometry correct so the door opens with the full travel takes some measuring and testing.

The pieces (bucket not shown)


Here is my code! You will need to set the threshold values for your preferences. There is a dim-light setting (darker than this and the door closes) and a bright-light setting (brighter than this and the door opens). In between the settings is a deadband where the door will stay in its current position– this keeps the door from opening and closing with every shadow when it is close to a transition.

// Simplest coop door controller // use pro micro (leonardo compatible) // check light level // open or close // sleep // By Mike Holden // 7/2021 // #include "LowPower.h" // // Pin defines #define lightPin A0 #define batPin A3 #define DIR1 9 // h-bridge dxn #define DIR2 8 // h-bridge dxn #define IOGND 15 // IO pin to gnd sensor (for ease of wiring) #define IOVCC 19 // IO pin to power sensor (for ease of wiring) #define IOSLP 3 // IO Pin to sleep or not (ground to not sleep) #define IOGNDS 2 // IO Pin to gnd IOSLP (ease of wiring) //----Threshold levels----// #define lightDim 50 //ADC counts. Threshold voltages. #define lightBright 200 void setup() { // put your setup code here, to run once: Serial.begin(115200); Serial1.begin(115200); pinMode(DIR1,OUTPUT); pinMode(DIR2,OUTPUT); pinMode(IOGND,OUTPUT); pinMode(IOVCC,OUTPUT); pinMode(IOSLP,INPUT_PULLUP); pinMode(IOGNDS,OUTPUT); delay(2000); Serial.println("Coop starting up, wait 10 seconds....."); Serial1.println("Coop starting up, wait 10 seconds..."); delay(9000); // to show serial port if needed } void loop() { // put your main code here, to run repeatedly: digitalWrite(IOVCC,HIGH); digitalWrite(IOGND,LOW); digitalWrite(IOGNDS,LOW); delay(10); int lightLevel=analogRead(lightPin); int batLevel = analogRead(batPin); if (lightLevel < lightDim) { // close digitalWrite(DIR1,1); digitalWrite(DIR2,0); } else { if (lightLevel > lightBright) { //open digitalWrite(DIR1,0); digitalWrite(DIR2,1); } else { // off digitalWrite(DIR1,0); digitalWrite(DIR2,0); } } Serial.print("Light: "); Serial.print(lightLevel); Serial1.print("Light: "); Serial1.print(lightLevel); Serial.print(", Battery: "); Serial.println((float)batLevel*15.0/1023.0); Serial1.print(", Battery: "); Serial1.println((float)batLevel*15.0/1023.0); digitalWrite(IOVCC,LOW); digitalWrite(IOGND,LOW); delay(10); if (digitalRead(IOSLP)) { // high voltage means sleep, short to gnd to skip this powerdown // Enter power down state for 8 s with ADC and BOD module disabled LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); // no reprogram without short reset to ground } }
Code language: PHP (php)

Debugging System

To find the correct light levels, and monitor the battery for a couple of days, I used an ESP8266 board to capture the serial prints and display them on a web page. This is a system I developed for my mechatronics class. I can add more here if you’re interested (send me an email). The battery voltage is measured with a voltage divider circuit, and the serial lines are connected from the arduino pro micro to the ESP8266 board.

Debugging System

Parts List

Affiliate Links from your favorite online overlords:

2 thoughts on “Super Simple Automatic Chicken Coop Door

  1. Peter Satoh says:

    This project is awesome! I would like to build this system for my chicken coop. I ordered these parts. I am really a beginner at Arduino. Do I have to do soldering the parts? Would you let me know how I can connect the DC 5V regulator to the system? Thank you for your help! Peter

    • Mike Holden says:

      I wish you success! I think soldering would be good to connect up the sensor and power, the motor controller has screw connections.

      The DC-DC converter takes 12V from the battery and makes 5V, with a common ground between them, so +/- from battery to DC-DC, then +5/- to arduino pins.

      My actuator jammed closed against some debris in the door, which broke the door and the motor. I got the motor working after taking it apart and putting it back together and made another door, but I’m considering going to a 16 inch actuator and a sliding door, so that the closed position isn’t jammed shut like the hinged door does. To get the hinged door tight there is a lot of load on the motor for the last little bit.

      Feel free to comment here with follow up questions or you can find my work email at Cal Maritime’s web page.

Leave a Reply

Your email address will not be published. Required fields are marked *