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.