Chicken Coop Door - Arduino Based




Introduction: Chicken Coop Door - Arduino Based

First of all, my native language is Dutch so apologize for possible spelling mistakes. If something isn't clear just leave a message at the comments.

This is my first arduino project.
As my wife was tired of opening the coopdoor manually every day again we considered to buy a chickenguard but they are quite expensive for what it needs to do (about 150 euro / 175 dollar).
official website

We all want our chickens to be safe at night so that's where creativity pops up. There's work to be done.
The first design was based on an arduino nano with an LDR but tat was not accurate.
On github I found an unfinished sketch where Dusk2Dawn library was used. I've used this as a base to start building.

Step 1: Parts List

All used parts are purchased by aliexpress

  • ABS plastic case IP65 (158mm x 90mm x 60mm)
  • 1x LED
  • Some wire, 10K resistors, 220 Ohm resistor
  • Soldering Iron
  • Glue gun
Total material cost about 20 dollar.
Just saved myself 150 dollar by building my own coop door controller and had lots of fun when creating it.

Step 2: Schematics

When all parts from Aliexpress finally arrived (yeah, it takes quite some patience) the fun stuff begins.
As you can see on the schematics the motor is controlled by the L298N driver board. This board has 2 channels (you can connect 2 motors on the board). In this project you only need 1 channel. Power the driver board with a 12V power supply. I've used the 5V connection on the driver board to power the Arduino.
I've used 2 inputs on the driver board (2 Arduino outputs) to enable the motor turning clockwise/ counter clockwise.

The MC38 magnet switches are connected with a 10K resistor to an Arduino input.

The manual down switch is also connected to an input by a 10K resistor.

The red led is connected by a 220 Ohm resistor to an output of the Arduino.
When the door is closed, the red led goes on.

RTC DS1307 connections to nano:

  • VCC - 5V
  • GND - GND
  • SDA - pin A4
  • SCL - pin A5

Please refer to the manual of your Arduino if you use another version than a nano.

Heat up your soldering iron and start connecting all things together.
Mount all the parts into the case. I've used a glue gun to fix the PCB and motor driver. Also secured the jumper wires with some glue.

Make sure that you test everything before assembling the parts into the case.

Step 3: Building the Hardware

I've used 4mm concrete forming plywood for the door. They slide into 2 aluminum U profiles.
The door is attached to the wooden spool with some nylon wire (fishing line).
The spool is connected to the 8mm shaft. I've used a drill to make the inner diameter of the spool matching the shaft diameter.

The motor is mounted in the ABS case (drill a hole in the side of the case).
The switch is mounted on the other side.

Glue the magnet on the upper side of the door. It's also possible to use 2 small screws. Make sure these are not too long :-)
Mount the 2 magnet switches on the coop (1 on the top, 1 one the bottom)

Step 4: Arduino Code

As this is my first real Arduino project I assume that the code isn't perfect according to the coding guidelines, but it's working and it does what I expect.

Feel free to use the code and adapt to your own needs.
Please leave a message in the comments and share me your project based on this code.

Line 38:
when setRTC = true, your pc time is synchronized with the RTC when uploading sketch.
After uploading change setRTC = false and upload sketch again.

Line 41:
If you use another RTC than 1307 (eg, 3231) change this line

line 45:
Change yourcity to the city where you live and fill in your coordinates and timezone.
I don't think they have chickens but for example lets get the coordinates of the white house in washington DC...
(use google maps, right click "what's here")

Dusk2Dawn washington(38.897885, -77036541 ,-5);

Line 139:
This is the sunset/sunrise calculation to define if the door should be up or down.
As you can see there are 2 numbers used in the calculation (+30). This is a delay on the sunrise/sunset.
My chickens go in a few minutes after official sunet time. Feel free to change this delay to your needs.

When the switch is operated the door goes down and stays down until you put it back into normal condition.

Step 5:

Possible modifications for version 2:

  • ESP8266 based version
  • wifi connection
  • Controlled by smartphone app
  • webcam
  • ...

Safe and happy chickens.

1 Person Made This Project!


  • Make it Real Student Design Challenge #3

    Make it Real Student Design Challenge #3
  • Furniture Contest

    Furniture Contest
  • Arduino Contest

    Arduino Contest



Tip 18 days ago

I’ve replaced The nylon wire with a thin steelwire to prevent waer.

US $0.11 | 5 Meter 0.6mm 0.8mm 1mm 1.2mm 1.5mm 2mm 304 Steel Wire Rope Cable Clothesline Rustproof 304 Stainless Steel 7*7


Question 6 weeks ago

Hi. Thank you for sharing this ! I tried to follow all instructions and so far my trial setup is acting quite normally (motor running clockwise or counter-clockwise when manually setting up the date/time). But there is a serious issue : when I put the magnet close to one of the sensors, the power goes OFF. I have to move the magnet away in order to get the circuit back on, or sometimes plug out/in the power source... Any idea ? Thanks, Thomas


Answer 5 weeks ago

How much current is your psu?
Make sure there is no short circuit on The magnet switch connections. Test The setup without magnet switch and use a jumper wire.


Question 4 months ago on Step 5

I have a problem with the seconds format displayed on 6 digits! (circled in red on the
image) which results in shifts of more than 15 minutes in 24 hours (PC time
circled in blue).
I am using an Arduino pro mini.
When I test the RTC with the RTC3231 example program, the display
is correct and I only see a 2 second lag in a month.
Perhaps a conflict between the DuskToDawn and RTC3231 libraries.
Which RTC3231 library
are you using?
Thank you for your reply.
Bruno from France

Sans titre2.jpg

Answer 4 months ago

Btw, is your Battery ok?
I assume You changed your sketch to rtc3231 and not ds1307?


6 months ago

Thanks for this instruction. Last year i built a Door using a Photoresistor, but unfortunately the chicken are always too late.... Now I will upgrade a timer... Hopefully!


Reply 6 months ago

Good luck!


Question 8 months ago on Step 2

Hello everybody !
Again here ...
I've been checking my connections for a week, dismantling, reassembling, ...
And all the time the message "Couldn't find RTC" ...
Sometimes a message that talks about the setup ... then the code that seems to be running and the engine running ...
What does it come from ? Code or bad connection?
I'm trying to figure out what the code is doing but I can't find everything.
What exactly does the switch do? Stop or reverse direction?
Thank you for those who will enlighten me!
Good Sunday !


Answer 8 months ago


The switch is to put The system on auto (open, close based on sunset/sunrise) or manual closed (to keep The chickens inside, or out depending on where they are 😄)I will send you a PM with My name so you can send me Facebook Messenger.


10 months ago

For fun maybe you could add a buzzer and train the chickens to come in and go out.
Sound the buzzer, wait 10 seconds and then open the door. Same for closing.

Just for fun!


Reply 8 months ago

That's a great idea, but the next thing you know a fox with a piezo and a battery will pied piper your birds out of town...


Question 9 months ago on Introduction

Hallo Geert !
Nice project, I was looking for such an idea for some years ...
Ik vraag me af waarom je een AAN / UIT / AAN-schakelaar hebt gekozen als ik er maar twee draden op zie. Kunt u het mij uitleggen? (Ik ben geen elektricien of elektronica-ingenieur, maar ik wil alleen leren).
(why did you choose a 3 contacts switch ? I only see 2 wires connected to it ...)
Dominique L. Repair Café Annevoie - Profondeville - Mettet (BE)


Answer 9 months ago

Hi, It was just a spare switch That was lying around. Nothing special. Only needed 2 wires.
Hand closed or automatic.


Reply 9 months ago

Thanks ! Dank je !


10 months ago

Hi. Very nice. Thanks for sharing.
There is a very nice way to enable/disable serial for debugging. It has the big advantage of completely disable Serial comunication:
#define DEBUG false // flag to turn on/off debugging
#define Serial if(DEBUG)Serial


Reply 10 months ago



Question 10 months ago on Step 3

Hi, I was wondering how you keep the door up during the day? Do you have the motor stalling all day or do you have a latching mechanism?


Answer 10 months ago

The coopdoor is made from concrete formwood (very light and weather resistant)
The motor is a geared motor and when it’s not enabled almost impossible to rotate. So when not activated the door just stays open. Very simple. I really like those 12v geared motors.


10 months ago on Step 5

Great Project. I really like your design, very simple but lots of parts. I made one of these with a linear actuator which has builtin limit switches. BUT my Grand Daughter's neighbors complained about the chickens and we had to cancel the project. I found another helpful library on the Arduino IDE. flex_DST. You put in the DST rules (fill in the blanks, very easy with examples) and use this to calculate the DST variable in the dawn2dusk calculation. Saves having to reprogram twice a year.
I appreciate your time and effort to put this into and Instructable and share it with the rest of us. Good Job and Thanks.