This spring three lovely chicks joined our family, Betty, Penny, and Ginger. Ginger discovered her inner rooster in due time, and was rehomed—we are not zoned for the crowing half of the species. To protect the birds from freezing during our winter travels, and to let them out at the sunrise, they have been housed in the electric henhouse. At dawn and dusk the hens are released or secured by a linear actuator, locking in heat, wind and potential predators locked out.
Betty watching the installation of the electric henhouse.
The heart of the electric henhouse is a bare-chip variant of the Arduino. It connects to a realtime clock with battery backup to get the time. The time, in turn, is used with calculated sunrise and sunset so the door opens at sunrise and closes shortly after sunset when the birds have settled down for the night. The ATMega runs at 5 volts, and so a dual H-bridge is used to provide the linear actuator with the power it needs.
The overall code architecture is straightforward, every second the processor checks the time. If the time is between the sunrise and sunset, tell the motor to open, otherwise close. The motor module maintains a state so that it won’t try to open an open door. The linear actuator is cleverly designed, it won’t strain to open when it is always open and it won’t close when all the way closed.
The only code module with much complexity is the sunrise and sunset calculation, which is an approximation based on a US Naval Observatory code, with only minor modifications. I tested it by running the calculation over a series of days throughout the year and comparing with published almanac.
I purchased two separate FTDI USB-to-serial chips to program the bare ATMega chip, and was unable to get either of them working. I followed programming instructions similar to those here, and those worked every time.
The linear actuator is visible at the top. It slides the door (currently open).
You can get the code on GitHub.