Chicken Coop Door - Arduino Based

21,918

157

56

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!

Recommendations

  • Sculpt & Carve Challenge

    Sculpt & Carve Challenge
  • Eggs Challenge

    Eggs Challenge
  • Fabric Challenge

    Fabric Challenge

56 Comments

0
mabartibin
mabartibin

5 months ago

Nice!

I built a similar looking thing for our chickens (twice, one for each coop) to control the lights. Dims up slowly in the morning (to avoid startling them) and dims down slowly in the evening (so they have time to ‘go to bed’) and also dims down when it’s bright outside. Even takes care of daylight saving time.

Controlling the hatch was an obvious next idea, but there’s often the odd hen who doesn’t want to go home yet and who will look very miserable the next morning if she’s locked out. We considered a camera with hen-recognition, microphone with cluck-recognition, RFID chips, weight sensors on the roost pole, etc., but we haven’t quite landed it yet.

Those who made it, don’t you have the problem of hens being locked out?

0
g.wanten
g.wanten

Reply 5 months ago

Chickens always go inside the coop when it’s getting dark. Chickens never stay outside. I’ve programmed a delay of 40 minutes on the official calculated sunset time, so they are always in the coop. Stupid simple and fool proof.

0
mabartibin
mabartibin

Reply 5 months ago

Ah. Makes sense. I’m in Norway you see, so for several months during summer it just doesn’t really get dark. And in the winter we have some Christmas lights draped around the enclosure so they get a little more light than they otherwise would.

I guess the solution would be to also dim down the outdoor LED lights gradually to simulate sunset and make them go in, and then close the hatch after that. And maybe forget about the automated hatch in summer.

Hacking Christmas LED lights for dimming, coordination between motor control and two separate light controls… sounds like a good project :-)

0
ulrik_s
ulrik_s

Question 8 months ago

Hi
I have made this project and it works good, the only problem is to set winter time with my RTC3231. I live in Sweden so we have +1 hour GMT.
How do I decide and set this option? Is it with true and false in line 108/109?

I have connected a bluetooth HC-06 on Rx/Tx to read the Monitor text on my mobile app.
That way I can see the status of the door and time on the Nano card from my house.

Thanks for a nice project . Regards Ulrik

0
g.wanten
g.wanten

Answer 8 months ago

Yes indeed, but honestly I don’t change to wintertime because chickens can’t read a clock and get confused when the door suddenly opens or close 1 hour later 😁
That’s why the sunset/sunrise calculation is build in.

0
ulrik_s
ulrik_s

Reply 8 months ago

Yes of course.
But one thing I don't understand. It closed/opened correctly on time when we had summer time. Then I monted The door a week later when we had Winter time. The time on Arduino RTC is correct but it closes/opens 1 hour later then it should? Perhaps I just have to change the time -1 hour on RTC3231.

0
g.wanten
g.wanten

Reply 8 months ago

First change this line from false to true: const bool setRTC = false;
Now you are going to set the RTC time.

Then you comment line:
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

and uncomment line:
//rtc.adjust(DateTime(2020, 7, 23, 7, 9, 20)); --> change values between ( ) to what you want.

After this, set everything back as before en change setRTC back to false

0
g.wanten
g.wanten

Reply 8 months ago

I think you synced the time from your nano with your pc again so that’s why time is now set on winter time. You can also set time manually. Need to check the code to see what line it is.

0
mschaefer84
mschaefer84

9 months ago

Hello, I just wanted to share a small error on the code to the author that might lead to defaults: On line 108/109 there is still the authors location :
sunrise = Kessel.sunrise(now.year(), now.month(), now.day(), true);
sunset = Kessel.sunset(now.year(), now.month(), now.day(), true);

You should replace Kessel by your location name that you put in on line 45 !

0
g.wanten
g.wanten

Reply 9 months ago

Indeed that’s my location. It’s actually not an error. Could only result in wrong open/closing trigger 😁
Or you can all move to Kessel to fix this issue 😂

0
djcdp123
djcdp123

Question 1 year ago

Heel erg mooi project! en met veel dank voor alle goede uitleg! Ik heb juist een probleempje. De deur blijft toe of gaat toe afhankelijk of het magneetje tegen het contact ligt of niet. Als ik de tijdzone aanpas naar -7 of een andere tijdzone waar het op dit moment klaar is dan nog blijft hij naar beneden gaan. Weet u wat ik soms verkeerd zou doen? Alvast bedankt!

0
g.wanten
g.wanten

Answer 1 year ago

Bedankt voor je comment. Altijd moeilijk om vanop afstand te zeggen. Wat zegt de serial monitor op dat moment?
Staat je schakelaar in auto en niet op hand gesloten?
Komen je 2 contacten goed binnen?

0
djcdp123
djcdp123

Reply 1 year ago

Bedankt voor je snelle reactie! De schakelaar staat nu uit (momenteel nog op een breadboard aan het testen en daar de 5V niet verbonden met de ingang) De serial monitor geeft wanneer het magneetje bij het onderste reed contact is weer dat de deur gesloten moet zijn en dat de deur ook beneden is. Als ik de magneet weg haal dan gaat hij direct over tot lowering. Om te testen of het bovenste reed contact werkt heb ik even zowel beneden als boven tegen de 2 reed contacten het magneetje gehouden, dan staat er dat de deur beneden moet zijn maar dat het deurtje geopend is) ik weet dat je normaal maar met 1 magneet werkt maar dit was gwn om te testen of de 2 contacten functioneren. (in de bijlage heb ik even de schakelaar aan gezet om te tonen dat deze werkt, ook heb ik de 2 magneten er eens bij gelegd i.p.v 1 magneet om aan te tonen dat de 2 reed contacten werken. alvast hartelijk bedankt!
laag en is toe.JPGlowering manual.JPGlowering.JPG
0
g.wanten
g.wanten

Reply 1 year ago

Je moet eens kijken wat de monitor zegt tijdens de dag met de onderste magneet geschakeld. Dan zou er moeten staan “door should be up” door raising.
Als dat het geval is en er gebeurt niets zou ik de motorsturing ff dubbelchecken.

Ps… het nylondraad heb ik inmiddels vervangen door staaldraad van 0.5mm.

0
djcdp123
djcdp123

Reply 1 year ago

Beste, omdat ik de fout niet kon achterhalen heb ik uw arduino code opnieuw gedownload om vanaf 0 te starten, nu zie ik dat de code is veranderd en nu kom ik devolgende fout tegen:

fout 2.JPG
0
g.wanten
g.wanten

Reply 1 year ago

Dit is een antwoord wat ik hier eerder in de commentaren heb gepost voor hetzelfde probleem…

First you need to set you coordinates and timezone.
You see line //define the location / timezone.
Below that line you need to type your place after the Dusk2Dawn and between ( ) your coordinates and timezone. You can find them in google maps. Go to your home location, right click “what’s here”.

Then in the loop section you see
Sunrise = Kessel.sunrise(now.year()...
Change Kessel to your place as defined after Dusk2Dawn in the beginning.
Do the same for line sunset =

0
g.wanten
g.wanten

Reply 1 year ago

Je moet Kessel vervangen door je eigen locatie en die variabele moet je declareren in de setup (yourcity)

0
escapade541
escapade541

1 year ago on Step 4

Hello,

I would like to power the assembly on battery or solar panel.

However, the consumption in standby (when the motor is not running) is too high: around 15mA for the Arduino (Promini 3.3V) and 40mA for the L298!!!

Has anyone tried putting the arduino in sleep mode and cutting power to the L298 with a transistor when the motor is not running?

It would obviously be necessary to wake up the arduino and restart the power supply to the L298 when the Automatic / Manual close button changes state, and when the opening or closing time of the door is reached.

It would therefore be necessary to use an RTC with a programmable output pin to wake up the Arduino (RTC3231?) but I do not really know how it is programmed especially since it is necessary to recover the time to calculate with DuskToDown ...

Can anyone help me?

Thank you
Bruno from France

0
escapade541
escapade541

Question 1 year ago on Step 5

Hello,
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