Maybe you are under the impression that only roosters, not hens, can make a lot of noise. You would be mistaken. Although roosters crow more loudly than hens cackle, the cackling of hens can sure wake you up, or your neighbors for that matter. This is a lesson we learned after we bought 6 Wyandotte chicks, a pretty and rather large breed of chickens. From the internet we learned that roosters will start crowing at 6 months of age. Ours started at 4 months. After a visit from one of our neighbors, I started contemplating making an automated door in our chicken coop. But the need for such a device went away when our two roosters ended up in our frying pan. After that, we had no noise problems with our four hens, until they started laying eggs. Again, one of our neighbors, another one this time, came to our door with noise complaints. The hens would get out of their coop at 5:15 am and start cackling loudly. As we sleep on the other side of the house, we weren't aware of this. I promised the neighbor I would keep them inside until at least 7:00 a.m. and he was happy with that. But now I had to make some haste with getting the automated door, since I don't want to go outside at 7:00 every day. On this web page you can read all about how I created the hard- and software for a motorized chicken coop door. Perhaps you have a similar reason as I had for needing an automated door. Or, you may want to prevent foxes or ferrets getting in the coop at night. Or you may want to protect your chickens from the cold. Regardless, the software is easy to adapt to handle a number of use cases. The hardware is cheap and, as it turned out, pretty reliable (in a trial of one).

The software

I started out with putting my requirements on paper. In a nutshell:
* I want to keep the door open as long as possible for fresh air, but close it before the chickens want to go outside. In practice this means that the door has to go down some time before sunrise. (But not in winter, when they go outside before sunrise, we found out.)
* The door has to be controlled by moving up and down a fixed period.
* For improving reliability, the software must be able to handle sensors that detect the up and down position of the door.

Before I started writing code, I made a state machine diagram that captures the behavior of the software. The image below shows this diagram. A state machine diagram shows the various states the system can be in and the conditions that trigger a transition from one state to another. Having this diagram made it a lot easier for me to write the core functionality of the software. 


The test hardware

For my first experiments, I used a DC motor I took from an old printer and a small motor driver. I stuck all the parts I thought I would need on a breadboard and started making the software. Here a photo of this experimental setup:

This worked very well for creating and testing the software. Another important element is the microcontroller that is used to control the system. I selected an ESP8285 for this task and it works very well. It is also extremely cheap, just a few euros on the well known Chinese websites. I used the Arduino development environment to write the software. It's not the best IDE, but it's free and does the job.

After I created an initial version of the software, I started testing it on the test setup shown above. This way I learned how the system behaved and where I could improve it. In this period I made a lot of changes to the software and it got better and better. For instance, I decided to remove the retry mechanism as shown in the state machine diagram, as it turned out to be difficult to predict if it would do good or harm when something goes wrong. I also started to add more features into the software, such as:

What I also included in the software was:
* A Wi-Fi client that connects the system to the internet.
* A web server serving up a page that allows me to move the door up and down.
* An NTP client that reads the...

Read more »