If you had any doubts that SiliconFarmer has an actual farm, this project should dispel them. We got six chickens last year. I built them a nice coop. It sits about 100 feet from the house, and has wheels so we can occasionally move it.
Chickens like to be in the coop at night. They are protected from predators, and they can stay warm if there are no drafts. They like to be outside during the day to forage for food.
This means someone has to go out early in the morning to open the coop, or they get noisy and start pecking each other. And after it gets dark, someone has to go out to close the door so they are protected, regardless of the weather. Did I mention it is after dark?
Anyway, this gets old after a while. So I built an automated system to open the door at dawn, and close it at dusk.
The first problem was deciding what sort of motor and mechanism to use. Brent from Autosport Labs suggested using a window wiper motor, as they are 12V, high torque, geared about the right speed, and can be found cheap at a junk yard.
He also suggested using an arm and pulley mechanism so the motor could be run in just one direction to both open and close the door.
These motors have an integrated switch, which allows my controller to determine when the motor is positioned with the door completely closed.
The completely open position isn’t as critical. No one cares if the door is an inch down from the absolute top. So I can use a simple timing loop for opening the door.
First thing I did was figure out which leads ran the motor, and which was the feedback switch. Ohm meter, 12V battery, and an oscilloscope made quick work of that.
One lead is common, two leads are power for slow and fast speeds. I used the slowest speed – fast was too fast! The forth lead comes from a switch connected to common that is only closed at one position.
The motor is rated at 10 amps, and I had a 10A 12V relay in my parts drawer, so I chose to use a relay instead of a transistor to control the motor.
It still took a small NPN transistor and flyback diode to control the relay. I checked out all the circuits, one by one, on a breadboard before I created my schematic and had the boards built by @laen’s PCB prototype service.
I decided to use an Arduino with a custom shield design for this project. As I tried out circuits, I wrote quick little bits of Arduino code to test them. To create the final software code, I had working snippets of code from my testing to use for each function.
My Chick Door Shield has the following features:
- SPST 10A 12V relay to drive the motor.
- NPN transistor and flyback diode to drive the relay.
- An opto-isolated input to sense the motor’s switch.
- 12V battery input. This goes through a polarity protection diode to the Arduino’s VIN. the Arduino’s regulator generates 5V. The Arduino uses an inefficient regulator, so in hind sight, I wish I’d put a 5V regulator with lower quiescent current on the shield.
- Voltage divider input on the 12V battery to check battery charge level. 3:1 ratio so the input is good to 15V.
- Voltage divider input on the solar panel. Again, 3:1 ratio input. This might be too low, as some unloaded solar panels can hit 18 volts.
- A PFET to connect the solar panel to the battery. This is to avoid over-charging the battery. Also, solar panels can drain a battery when there isn’t sufficient sun. Even a solar panel with a protection diode will have a leakage current. With a PFET oriented the correct way, there is no leakage at all.
- An input from a button, so the door can be manually operated.
- I threw on a temperature sensor and a spare connector and power to an IO pin. I plan to eventually add a radio so I can monitor the door position, and check it with a limit switch or optical sensor. I could also monitor the coop temperature.
I built the board, mounted the motor to a bit of metal and attached the arm. Then I tested it on my workbench. Everything worked! I also debugged my software on the workbench. One thing I found out was that the motor really does have a lot of torque. You don’t want it to hit anything!
- The motor switch input pin fires an interrupt, which immediately shuts off the motor. This gives me the best accuracy on repeatedly positioning the arm in the same spot when closing the door.
- The closing the door function uses a delay(500*3) followed by another motor shut off, just in case something happens to the wire from the switch. I don’t want to run the motor until the battery dies!
- The current surge from starting the motor can cause noise spikes from the motor power leads coupling to the switch wire. This could inadvertently stop the motor too soon. So the close door function also delays arming the motor switch interrupt for 10mS after starting on the motor.
- The open direction is controlled by a simple delay(500). This opens the door a bit past fully open. I figure if the door sticks a little, it won’t open quite as far as expected, which should still be OK.
- The light level (reading from the solar panel) is set to 50 for sensing night. That’s under a 1V output from the 12V solar panel. The chickens don’t go into the coop until after sundown, so I figured that on a cloudy day, I need to wait until as late as possible to close the door.
- The open light level is set to 100, plus a 5 second debounce period. This is to add some hysteresis so the door doesn’t go up and down repeatedly, and to avoid lightning flashes from opening the door. It probably wouldn’t hurt to raise it to 200.
- The FET is off when I check the battery and solar panel voltages. It is on only when the solar panel voltage is higher than the battery voltage, and the battery isn’t over 14.6 volts.
- All interesting values are checked for changes, and output on Serial.Print every control loop (10ms). All I have to do is hook up to the USB port to see what is going on. Eventually, I can connect a radio to the Arduino UART pins and get status messages from the chicken coop.
The control electronics are in a case, right next to the battery, in a storage area under the chicken roost. It is dirty down there.
The solar panel on the roof is a spare 10W panel. If there is any sun at all, the battery gets charged.
The manual push button is mounted right by the door. You can see the plastic sleeve going through the wall of the coop so the paracord doesn’t get frayed, and the pulley that pulls the door up and down.
Here is the pulley on the inside, with the paracord heading out through the plastic sleeve. As the arm swings around in its arc, this pulley makes sure the cord is going straight out through the hole in the wall
Here is the motor, mounted to the ceiling, in the open position. When closed, the arm is pointing at the camera position, toward the inside pulley.
An overall picture of the arrangement of the motor and indoor pulley. You can see the cable going to the motor run along the rafter. Don’t put cable (or anything else) where a chicken can peck at it. Eventually, they will damage it if they can get to it.
I have some video of the automatic chicken door in action, but I need to edit it down and upload it to Youtube, then I will update this page.