My DIY Arduino automatic coop door opener

Discussion in 'Coop & Run - Design, Construction, & Maintenance' started by vasko, Jan 17, 2014.

  1. vasko

    vasko Hatching

    Jan 17, 2014
    Hello guys. I've built an automated door using an arduino controller and a clock for controlling it. I converted a former pig house for the hens a while ago, but it has the disadvantage that it is quite small. I wanted to let the chicks roam free in the daylight and still be protected at night and I had some spare time to do it. The materials used are pretty basic, I've used some printed parts form my 3D printer, but they are nothing so much special and I think you can find a way to substitute them.

    So here is what I did.

    I started with the electrical stuff. Here is the parts list along with estimated costs:
    arduino 10-20$
    motor driver 6$
    clock 6$
    geared motor ~ 5-10$
    wires-connectors etc ~ 10$
    2 end stops - 1$
    aluminum rails - 10$
    printed parts - reel and rail holders
    total - 50-60$

    Basically I just needed to wire them together. The clock and motor driver wiring is pretty straightforward, the buttons are using a 10K pullup resistor and their normal state is closed. When they are clicked they open the circuit which is better for the emergency case when one of the buttons disconnects (maybe the rooster ate it). Then the program will think the button is pressed and the motor will not run without stopping. If you want I can provide you with the exact wiring on my setup, but you can use other parts and modify slightly the program and it will still work. Also you can check out the following picture:
    Note that I used a geared motor, as it can lift a not-so-light door and also keep it in the up position when no power is applied to the motor. The reel is printed, you don't really care of its diameter, you just want to be able to roll the whole cord on it and mount it well to the motor.

    This is the source code I am using:
    #include <Wire.h>
    #include <Rtc_Pcf8563.h>
    #include <Time.h>

    #define POS_UNKNOWN 0
    #define POS_TOP 1
    #define POS_BOT 2

    int MOTOR_A_EN_PIN = 6;
    int MOTOR_A_IN1_PIN = 7;
    int MOTOR_A_IN2_PIN = 8;
    int MOTOR_A_SPEED = 255;
    int TOP_BUT_PIN = 9;
    int BOT_BUT_PIN = 10;
    //init the real time clock
    Rtc_Pcf8563 rtc;

    int pos = POS_UNKNOWN;
    int desiredPos = POS_BOT;

    // Time represents just hour/min and time = hour * 60 + min
    int raiseTime = 430; // 7:10
    int lowerTime = 1130; // 18:50

    //int raiseTime = 678; // 7:10
    //int lowerTime = 679; // 18:50

    void setup()

    pinMode(MOTOR_A_EN_PIN, OUTPUT);
    pinMode(MOTOR_A_IN1_PIN, OUTPUT);
    pinMode(MOTOR_A_IN2_PIN, OUTPUT);

    pinMode(TOP_BUT_PIN, INPUT);
    pinMode(BOT_BUT_PIN, INPUT);

    // //clear out the registers
    // rtc.initClock();
    // //set a time to start with.
    // //day, weekday, month, century(1=1900, 0=2000), year(0-99)
    // rtc.setDate(14, 1, 1, 0, 14);
    // //hr, min, sec
    // rtc.setTime(3, 54, 0);

    void loop()
    desiredPos = calcDesiredPos();
    if (desiredPos == pos) {

    if (desiredPos == POS_BOT) {
    while (!reachedBot()) {
    pos = POS_BOT;
    } else if (desiredPos == POS_TOP) {
    while (!reachedTop()) {
    pos = POS_TOP;


    void runMotor(boolean dir) {
    digitalWrite(MOTOR_A_IN1_PIN, dir ? HIGH : LOW);
    digitalWrite(MOTOR_A_IN2_PIN, dir ? LOW : HIGH);
    digitalWrite(MOTOR_A_EN_PIN, MOTOR_A_SPEED);

    void stopMotor() {
    digitalWrite(MOTOR_A_IN1_PIN, LOW);
    digitalWrite(MOTOR_A_IN2_PIN, LOW);
    digitalWrite(MOTOR_A_EN_PIN, 0);

    boolean reachedTop() {
    return digitalRead(TOP_BUT_PIN) == LOW;

    boolean reachedBot() {
    return digitalRead(BOT_BUT_PIN) == LOW;

    int calcDesiredPos() {
    int timeNow = hour() * 60 + minute();
    if (raiseTime <= timeNow && timeNow < lowerTime) {
    return POS_TOP;
    return POS_BOT;

    void syncTime() {
    setTime(rtc.getHour(), rtc.getMinute(), rtc.getSecond(),
    rtc.getDay(), rtc.getMonth(), rtc.getYear());

    The parts were assembled into a former cheese container (I happen to like them a lot as they provide more or less safe environment and also a mounting option which you will see below.

    I bought some extruded aluminum in an E shape. It has two channels which is handy as I used one of them to secure it to the frame of the door and the other to slide the door in.
    They were 1 meter long so I've cut them in half. I didn't want to use 2 rods as you can still let the door stick out of it by 5 cm for example. Also I will not tolerate fat chicks.
    For the mounting I've printed some parts which connect to the rails with bolts and have another hole for screwing to the door frame. I cut the door approximately 30x30cm in the frame where I mounted the rails with the door plate inside. I've also cut a hole for the motor reel.
    I really didn't want the motor to move so you can see the result. Not that pretty, but effective I hope.

    For the plate I intended to use acrylic sheet, but then found some eternit plates lying around that I shaped using pliers. I think the acrylic would be a better way to go as the door became a bit heavy.
    On the top and bottom I've added the limit switches and basically it was done. On the following picture, the door is reversed.
    I've also moved the upper limit switch so it opens more and its opened quite a lot now as even the rooster has no trouble going in and out. Here is an old picture of him laying an egg:

    And then the phone battery was dead and I couldn't take any more pictures. The mounted pictures are TBD. If you like it I can do a video of it in action.

    It took me about 2 days to finish, but I enjoyed doing it. When you think of the cost its not too little. But the good thing is that it's extensible. You can easily add for example a water sourse with a solenoid for always fresh water (remember you can reuse the clock). Or maybe opening windows to correct temperature. You can basically do anything you imagine.
    2 people like this.
  2. 12chickenlover3

    12chickenlover3 Chirping

    Jan 27, 2013
    Cool! I can tell it took a lot of time and effort![​IMG]
  3. rossmon89

    rossmon89 Hatching

    Jun 25, 2014
    Hey Vasko,

    Couple questions:
    1- Could you post the wiring diagram? Thanks!
    2- What is the part that you use to mount the boards to the plastic container? Are they just little spacers on a bolt?
    3- How different is the programming and process for the nano Arduino than a Mega?

  4. dd6905

    dd6905 Hatching

    Oct 21, 2014
    Hi. I was looking into making something using the Arduino that not only could handle the automatic door
    (but also adjust the door closing hours to the local sunrise/sunset hours via light sensors),
    would handle turning on supplemental lighting, and possible turn on a heater for the automatic
    watering system if it got near freezing and your page was the only one I found so far.

    Thanks for providing the source code. It should help get things going quicker.

    I was thinking of other things that the Arduino could be used for.
    With the Arduino, I could imaging doing crazy things like notify me
    if the doors closed and not all my chickens are inside the coop or put on some motion sensors and notify
    me if some big animal is attacking the coop.

    I wanted to hook up some light sensors and wifi and so I could download the sunset and sunrise times
    and be able to select a lighting program such as 14 hour of light per day.
    One of my chickens, a leghorn, stopped egg production completely a week
    days ago. She was good for one egg every day without fail so I was thinking of making a solar powered
    red LED lighting unit that would sense sunset and
    turn the LED lights on an hour before actual sunset, give the chickens their 14 hours of light, and instead of just turning the lights off,
    slowly dim the lights over the course of maybe 60-90 minutes. This would give make the chickens feel like it
    was naturally getting dark and give them time to get to the coop. The Arduino could easily accommodate
    an algorithm to adjust morning light as well. The timers I saw on the market would just turn lights on and off, so you would have
    to increase time in the morning hours, but they wouldn't be smart enough to adjust themselves for local sunrise and sunset to
    save electricity. I was eventually going to put on some solar panels and be totally green about it, but doesn't mean I have
    to waste electricity because it is free. This energy savings would be good for people who want to just plug in power from the grid.
  5. Hokum Coco

    Hokum Coco Crowing

    Dec 6, 2012
    New Brunswick,Canada
  6. tcstoehr

    tcstoehr Songster

    Mar 25, 2014
    Canby, Oregon
    Very interesting. I'd be interested in working on something like this myself. I have decades of experience developing C/C++ software but precious little training in electronics. I'm guessing your source code could contain a table of information on what to do for each day of the year. So for any independent day of the year your door could open or close by:
    1) Light sensor
    2) Time of day
    3) Not at all

    Looks like your preliminary design is hard-coded for the door to open at a single time.

    The parts you linked to don't appear to be the parts you used. The clock board was for a Raspberry Pi and the Arduino board looks like some other part.
    Can you provide a link for the geared motor?

    I wonder how these electronic components are rated for a chicken coop environment. Meaning rain-free but possibly high humidity and quite cold.
  7. rfeyer

    rfeyer In the Brooder

    Apr 12, 2014
    Johnstown New York

    great idea - currently using an adoption of NYcue's water pump method for the coop door (not as heavy), but nee an electrical motor method for the Run door.

    A couple of questions: I am used to WebComponent PCI and RaspberryPi MP's. Is the Ardunio controllable over internet? (does it have a LAN connection port)?

    Also, is the motor reversible and has it proven strong enough? If so, could you give a link to where the motor is obtainable?


  8. tcstoehr

    tcstoehr Songster

    Mar 25, 2014
    Canby, Oregon
    Arduino is basically a microcontroller, with a surrounding ecosystem. It's the ecosystem that makes it useful.
    So, no, the Arduino has no LAN capability by itself. But there are LAN modules you can obtain and free libraries available for communication through the Atmel microcontroller's serial I/O pins. So, yes, the Arduino does have LAN capability.
    Using a fully fledged Linux computer like a Raspberry Pi would make more sense than taking the low-level Arduino and accumulating all the functionality you need and piling it on top. But people do it and you can too.
    If you like tinkering with resistors and transistors and rat-nest wiring and programming tons of low-level interfaces, maybe it's for you.
    I have to say, it is pretty fun, but it's not easy. Here's what I came up with just to open and close a relay for my chicken door. It has a pre-programmed open and close time for each individual day of the year. I could have used a light sensor but I really wanted exact time control. It should run for several years on three AA batteries. I did it mostly for the learning and fun of it, but it will soon be installed in the chicken coop.


    Boring details for interested parties. The green board at the bottom is a "latching" relay, meaning it will hold its position even when power is cut. So I only supply it with power for 1/10 of one second each day. Only when I need to open or close the relay. Otherwise it would eat up the battery in a couple days. The riser card at the upper left is a standard DS3231 time-keeping board. It has it's own battery which will last for years, but it does need external power to talk to the microcontroller. So I similarly route power to it only momentarily twice a day to check on the time. The large black chip in the center is an Atmel Atmega328 microcontroller, which is the heart of many an Arduino board. I use an Arduino setup to compile and load programs into this microcontroller, but not an actual Arduino board with all of its power-hungry components. This way I can keep the microcontoller in a ultra-low-power sleep state for 99.99 percent of the day and only wake it up a couple times a day when it needs to operate the relay which in turn operates the chicken pop-hole door. Using an actual Arduino board would consume too much power. Sounds like fun... doesn't it?
  9. rfeyer

    rfeyer In the Brooder

    Apr 12, 2014
    Johnstown New York
    Fantastic! Not boring at all. I also started diving into RP1 and the WebControll PCI (which currently I prefer - has it's own PCI language and needs no other interface and is LAN capable with 8IO's and 8 Analog oututs as well as an inherent temp sensor supplying 8 ONE WIRE thermostats and one humidity sensor, all built in - don't remember the exact cost, something around $30.00?)

    I may contact you again, if you do not mind, on this thread. Currently I am researching the best (for the buck) 12VDC resversable motors, sprockets, and chains.
    I already have DTDP swithes (currently used aas limiters/ shut off's for the water driven door).

    Fun it is!

    BTW, the temp sensors are in the coop, Run, outside, and inside the two water buckets which I am monitoring with WGET statements with the RPi via Linux (and I am a newbie to all of this).

  10. Damntitan

    Damntitan Hatching

    Jan 28, 2015
    i would love to get the wiring diagram for that! it seems like avoiding the Arduino specific boards could cut the cost in half. since it is the same chip it should work with the same source code right?
    I am more of a distribution engineer so i don't keep up with control/relay gear.
    but with a diagram i could build the chicken coop of the future!

BackYard Chickens is proudly sponsored by: