Intro: Chicken Coop Controller V2 Software Update
Pictures of the previous Arduino Chicken Coop Controller and its new cousin (top).
Over the last 18 months I have been using my Arduino based Chicken Coop Controller to great success with even a few folks out there ready to build their own versions. Since that time I have had a couple of door malfunctions (jamming) and one mechanical malfunction where the connector from the motor to the spindle broke and required glueing (because the door jammed!)
During this time I have had many followers and many thanks to all those who have commented and were keen to understand more about the project. For those who are interested in building this controller I would suggest you read the original instructable which covers the whole project from inception to operation. This Instructable will only cover the electronics and the code.
The instructable brings together a number of ideas that I wanted to originally include and others have asked me to build into the future design. Thanks to all who have urged me to bring out the v2 - sorry for the long wait.
Just to remind you the main features of the original ACCC were:
- Based on the Arduino architecture for easy prototyping and adaptation to your coop requirements
- Uses common parts easily found at you local DIY/hardware store/shop such as cheap electric screwdrivers
- Uses a real time clock (RTC) to maintain time even when the device is temporary disconnected from power
- Adjusts the opening and closing times of the door according to the current month - you can set it to your own timezones
- Provides a manual override just in case one of your lovely darlings misses sunset!
- Provides a min and max temperature reading inside the coop from midnight so you can keep an eye on your brood's welll-being
- A display which can be switched on and off to read out the current ACCC status and will not disturb your feathered friends sleep at night
Most of the electronic components were sourced from eBay and I estimated (2012) the electronics would cost around £35
Step 1: The New Requirements
At the end of the previous project there were a couple of rough edges I wanted to smooth out:
- Entering the up and down times for the door was done during programming and I found this needed to be adjusted during the course of the year which meant taking my MacBook into the coop and wiring it up to the Arduino which isn't much fun in the height of winter or summer
- The up and down times for the door needed to be calculated in minutes from midnight which meant you had to do a quick mental calculation to realise 390 on the display meant 6.30 (390/60)!
- I though I was pretty pleased with the amount of information I managed to squeeze in the 2 row x 20 character display. However you needed to concentrate to read-off the display as it displayed current then minimum and then maximum readings within about 3 seconds!
- The system could only cope with one time setting without summer time savings (BST) which wasn't much of a problem as long as you remembered in the summer the coop clock was always going to be an hour behind BST for the UK
Some design suggestions I didn't take on. I drew the line at given the ladies under floor heating suggested by one of my fellow instructable colleagues!!
I suppose I have taken a 'suck it and see' approach in the evolution of the design which has been good and a couple of things came to light in normal day-to-day operation:
- It was difficult to tell from my lounge window, while I had a beer in my hand, whether the door had gone down. In particular, if it had gone down successfully
- When I did get a fault I found the motor ran the battery flat because it kept on spinning or even worst was stalled because the rope around the spindle was tight. This almost led to a motor driver burning out
- If the controller missed the door closed trigger when the door was going down then the motor will continue until it has unraveled all the string and would then proceed to pull the door up! Something to avoid when you are plague with foxes
- I really wanted to adjust the door up and down times without the use of the MacBook and to use something more simpler than the keyboard in the original design
- When I originally built the electronics I did most of it myself but since then the building blocks for an Arduino are very cheap so I decide to to use some modules such as RTC (Real Time Clock) £3 and a small Arduino development board £4. Hopefully then others might be brave and take the plunge.
Step 2: Design Changes
The first major design change was the introduction of a menu driven system using one of the available systems for the Arduino. I went for the Phi_Prompt system as I found it was very well structured, adaptable and supported a number of screen and input types, including rotary. It didn't take me long to work out how to migrate my existing code into the structure. More on about the code in the next step.
I decided to substitute the 2 row display screen for a 4 row x 20 character display. The interface uses the standard 4bit interface - although those folks who have 2 row screens with built in keyboard still can use the code but will need to adapt a few parameters so you can scroll up and down to display all 4 rows. I have programmed the back light to stay on for a set period when it enters 'run mode'. That way you can check the times are correct and the temperature probe is working ok before walking away from the coop.
Instead of the keyboard I decide to go for a rotary switch with very basic debouncing circuitry interfaced to an Arduino development board called a Xino. I bought some right angled connector pins and used those instead of the supplied straight ones so I I could hook up the other modules from the side. That meant I can use push hoods to connect the components and modules. Again these leads with hoods are readily available on the internet.
While I had the door out I moved a few things around and created an easily accessible enclosure for the electronics with a door. Specifically I moved the motor driver board into the housing so I could easily access it if I had too. I decide also to up rate the microswitches to something more robust as I had a couple of switch fails mainly due to the weather and cold extremes we have had recently.
Step 3: The Electronics
As I have mentioned before I decided to use modules wherever possible and to make it easier for folks to do it themselves.
I have attached the schematic on how I wired the individual modules. Please note that various pull-up resistors for the probe and switched haven't been included but I have attached the previous schematic for v1 so you can understand how they are connected.
The key modules I used were:
- Xeno Arduino prototyping board (£3.70) which you can add an ATMega328 chip(£3.00) or the Arduino Uno (£18)
- ATMel programmer (£5.00) which can load the boot loader and program for you
- MicroSwitch with Roller Actuator (Micro Switch) (£1.50) x 2off
- Female to Female Jumper Wires Ribbon Cable (£1.50)
- 6V 8Ah AGM Sealed Lead Acid Rechargeable Battery (£16.00)
- Trickle Charger - make your own (£3.00)
- 5 Pin Digital Push Button Switch Rotary Encoder/ Momentary Push Switch (£2.00)
- Tiny RTC (£3.00)
- HD44780 2004 20x4 White Characters LCD Display Module (£6.00)
- L298N Dual H Bridge Stepper Motor Driver Controller Board (£5.00)
Step 4: Menu Driven - Code
As previously mentioned I used a LCD menu system library produced by Dr Lui - this library is called PHI_Prompt. The reason for this choice is that I wanted the ability to use a simple rotary switch to select certain variables within the program and change them to a prefixed range. For example for each month I can now manually set the up and down door times using the menu system.
I am not going to go in to too much depth in terms of explaining the code just the new features - everything else is similar to the previous code in the first version.
When you open Chicken_Coop_Controller_v2 you are presented with five tabs:
The main labels definitions used within the code are here including the character mapping required by the menu system. If you were to decide to opt out using a rotary switch you could use the previous LCD keyboard (analogue restore network) instead. If you read the PHI manual it explains how you can change the input and output without to much modification to the code - very cleaver.
Global variables and libraries are also defined here. The program is initialised and then the top_menu() function is called to start the system which automatically goes into 'run mode'.
This is were the bulk of the control logic sits when the 'RunController' menu options is selected. The default values for the door up and down times are set. This version now works in hours and minutes - so times are set hour, minute rather than total minutes which I know did confuse folks. In this section I have also added the logic (SetFlashOn) which causes an LED to come on when the door closes correctly and flashes when there is a problem when closing and opening
Here is where the structure and configuration for the Coop_menu sits:
- Run Controller
- Set Time/Date
- Set Door Time
- Door Up
- Door Down
- Door Parameters
For each menu selection there is a local call function which then calls on the Coop_Control functions. This section is relatively straightforward - well I hope!
I have added a failsafe feature to the door down and up options which keeps track of how long these functions have been running. If they go beyond the set parameter (MotorFailSafe) then the motor is shut down.
This code has been significantly modified so that it works with the DS1307 library. I have also added British Summer Time (BST) conversion logic. At the top of this code I have created 7 years of when the clocks go forward and backward. When the code goes to print the time it checks whether it needs to add an hour on Standard Greenwich Mean Time (GMT). This code also prints the door close and open times and sets the current time for use elsewhere in the code.
Within this code you can also set the Coop time and date using the menu input code. You are force to set time first by rotating and clicking the hour and then minute.
This code is very similar to the previous code in original controller. It reads a OneWired temperature probe and converts into a centigrade reading, then displayed and then compared with previous readings to see if it is a minimum or maximum reading. If so it is stored. The minimum and maximum readers are also then displayed
I have updated the software to run with the new Arduino 1.6.6 environment. I get one warning when it compiles but everything seems to be ok. If you have any problems drop me a line.
Step 5: In Operation
I have managed to cram all the electronics into the door assembly so there is very little for the ladies to peck at. The backlight for the display automatically turns off which can be set from one of the menu options.
In practice the rotary switch works fine but does suffer from the occasional de-bouncing which can be cured with a few resistors and capacitors. I have included a link to a good instructable for those who want pinpoint accuracy as they rotate through the menus and options.
The reality is I seldom take the the controller out of 'run mode' unless I want to stop my little lovelies from coming into the coop while I am doing something.
I have a thin cable coming out of the controller going to the roof where I have used a bright white 5mm LED as the door close signal and fault alarm. I sealed it in with a generous blob of silicon so to keep the damp from the pins.
I must admit I have found the options to change the down and uptime's on the fly a real time saver and the fact that it now displays the time in hours and mins is very helpful. Also it automatically adjusts for British Summer Time which means I know longer get confused as to whether the clock is right is another plus.
Probably the best feature is the flashing LED which one of my followers 'Larry' suggested is a real must. I can just peak out of my window to know if the door went down safely. When there might be a problem it flashes at me to make sure I come to the bottom of the garden to inspect which usually is a missed close door sensor trigger but because of the failsafe for the motors means the door stays down.
As ever I am happy to answer questions and I do hope you have enjoyed this instructable and it helps to stimulate your creative juices to help keep safe your feathered friends.