Over the last few years my family has been keeping ex-battery hens - they are about 18 months old and have lived their entire lives within a caged environment. As much as we love these little bundles of joys and eggs it can be a drudge getting up in the early morning letting them out to roam the garden because the sun is up and bright at 5.00am!!
It would be great if we could have an automated door that could open just after sun rise and close half an hour after sunset where hopefully they are all cosying up to each other in the coop. Sadly there have been times we have forgotten to lock them safely away and discover the horrible consequences when a fox has attacked and killed some of them.
This instructable brings together a number of ideas I have seen on the web to create an Arduino Chicken Coop Controller (ACCC) to automate a chicken coop door and where possible I will give direct credit to those people designs/code I have adapted to create this personal sleep saving device. Many thanks to those who have shared their great ideas which has spawned this device.
The main features of the ACCC:
Most of the electronic components were sourced from eBay and I estimate the whole device excluding the wood was under f30
Step 1: Building the door
The door is based around a design by Clint Fisher which I discovered on YouTube. This is a brilliant design as it actually locks in your precious darlings regardless how scrupulous the local fox or other vermin are in trying to prise open the door. You could use a simpler design of just a sliding up and down sheet of ply. It is up to you on how complicated you want the door - just don't make it out of solid steel as the motor will struggle to lift it.
Clint didn't actually provide the plans on his YouTube link so I set about to recreate them and I have attached a PDF file which you can scale to your needs. I hope from the series of pictures and my video file you can see how the door assembles and works.
Use brass screws/stainless steel bolts where possible and treat the ply with a suitable wood preserve - I wouldn't use a vanish as this might over time cause the workings to foul. When fixing the perspex cover use brass screw cups to spread the load and will hopefully stop the cover from shattering.
I found loosely fitting the door lock levers ensured they worked even if they were damp from the outside weather. I made two doors to test. One has been in manual use to see how it would stand the damp and cold english weather - which it did! So hats off to you Clint it is a very practical design.
I have taken loads of pictures so you can see from all angles the design and how it is constructed and assembled. I haven't commented on every picture as I think it is reasonably self explanatory - well I hope!
Step 2: Motor Assembly
I wanted to source a motor and gear assembly that was under f10-15 which isn't easy. I came across a cheap electric screw driver for less than f6 and when I stripped it discovered I had all the components I needed. Including a:
I mounted my motor on some formed wooden support pieces and left plenty of space for the motor controller and regulators. I housed the motor assembly so no moving parts would be pecked by my feathered friends - my coop isn't a tall shed. The pulley is an old wooden cotton real but any real would suffice - make sure you can drill a hole through it for the chord. As the real would only be moving for a few seconds up and down I didn't go overboard on bearings and tried to keep things simple.
I attached the real to the motor via a screw bit and some very strong double bubble glue- it goes rock hard when cured.
Step 3: Testing The Door
I am sure there are better ways to mount everything but I must say the assembly has been working now for over 3 months and seems to be holding up well.
Step 4: Power - Arduino, Motor and Battery
The original intention was to use the RK Education Technology Solutions RK L298 H-bridge board. This little board can deliver 2A per channel - it is a 2 channel H-Bridge. It also has a handy 5V regulator which can be powered off the same battery as the DC motor.
In testing I found that the motor was producing far too much noise and was severely affecting the arduino through its regulated supply. Fortunately the PCB is designed in such a way that I could separate the regulator section and feed it directly with a 9V plug power supply which immediately resolved my noise issues. I have also read elsewhere folks not recommending using the same battery for the motor and arduino.
Again this H-Bridge could be scratch built or bought as an arduino shield but do make sure the power output cables are robust enough to take the high current. I wanted to keep the heavy current unregulated circuits away from the arduino so this is why I went for this option. It is all nicely tucked behind an airy box which hides the sealed lead acid battery.
I sourced a simple and intelligent trickle charge circuit to keep the 6V battery topped up. This I managed to mount all the components on a small square of vero board. The preset pot needs to be set to provide 7.2V on the charger output (no battery attached) and will charge the battery up to 0.5A which is usually the maximum charge manufacturers recommend for 6V batteries. The motor can withstand short burst of 6-7V and in fact really helps when pulling up the door assembly.
All regulators and power amps I placed heat sinks on as the:
Step 5: Building the Arduino Electronics
You can short circuit the work involved by choosing some excellent Arduino prototyping boards which provides RTC and connectors for probes. Do check out eBay or other distributors. The basic digital electronics needs to provide:
Step 6: Testing the Logic
The code has some natural latency so by the time it stops the motor the door will be well and truly fully up or down! Once you are happy the micros switches working fine and in place do put an additional screw through the perspex holder to stop any future movement.
I found that producing a simple wooden cover for the bottom microswitch stopped the occasional failure when the door closed. I suspect my feathered friends took a liking to the wires and connectors and also thought it was a good target for their daily movements!!
Step 7: The code is the glue
I used the latest Arduino IDE 1.0 which I must say has been brilliant especially as you can now programme using the ISP programmer and not have to worry about USB dongles or circuitry. One thing I would say you still need to burn the boot loader onto your blank ATmega328 chip otherwise debugging becomes a bit of a challenge as the Arduino environment hasn't been set up properly!!!
The code I have compiled is 8,346 bytes in size so you can use the ATmega168 chip if you have a few kicking around.
Arduino.h - the standard and very large library
DS1302.h - Real time clock library
LCD4Bit_mod.h - Library supplied to support the LCD/Keyboard - very similar to the Standard library
OneWire.h - Provides communication to the temperature probe
Pinout Allocation and Global Variables:
This is where you need to set your own sunset and sunrise depending on your location. We have summer savings here in the UK but I decided to keep my system on GMT which means when I look at the clock in the summer saving time period it is an hour behind so the sunset and sunrise times need to be set accordingly.
In the code you will notice a commented out routine 'set_time()' to set the RTC. This should be uncommented for the first time programming so the clock can be set. Comment it out and reprogramme the ATmega328 again this way if the board is reset or further changes to the code are made the RTC always has the correct time.
You need to experiment on setting the RTC in sync with the laptop time. I discovered on a Mac environment you need to allow 40 seconds for compiling and uploading to make sure the times where exactly synced.
As you can see from the code I have created a state motor variable which ensures actions are completed before the main loop code goes back on itself.
Step 8: Installing into the Coop
Make sure the battery is nicely tucked away from the reach of the hens and the 9V input cable is securely attached to the door which is behind the motor housing.
I would reset the door and check the time is correct and the right sunset and sunrise minutes are displayed for that month. At the time of taking the photo's we were in March which meant the time section would display:
Actual Time Sunset Sunrise
Coop ^Coop vCoop
15:30 1140 345
Note - 1140/60 = 19:00 and 345/60 = 05:45
I left the sunrise and sunset times in mins from 12.00pm as it made a clear display distinction and was easier to translate to an opening and closing time. I was being a little lazy!!
Step 9: What would I improve?
Reflecting over the build there are some improvements I will do over the next few months and no doubt publish ACCC v2.0: