Skip to content
mikepaxton edited this page Mar 31, 2020 · 2 revisions

Automated Chicken Coop Door Controller

The coopdoor.py script uses Astral and Scheduler to automate the opening and closing of the chicken coop door.

The following python modules will need to be installed on the Raspberry Pi:

  • gpiozero
  • schedule
  • astral

A Raspberry Pi is being used to control an L289 H-Bridge motor controller which in turn is controlling a 16” linear actuator.

The script can be modified to work at any location world wide by changing the location which in the following code. The last portion of the location, elevation can be omitted but provides an even more accurate calculation of sunrise and dusk.

# astral.Location format is: City, Country, Long, Lat, Time Zone, elevation
loc = astral.Location(('lincoln city', 'USA', 45.0216, -123.9399, 'US/Pacific', 390))

In addition to automatically open and closing the door, GPIO push buttons have been added so that you can manually open and close it when needed.

The H-Bridge is controlled using GPIO pins 14 (open) and 15 (close). The push buttons use pins 18 (open) and 23 (close). Note, the open and close buttons are pulled High by default and therefore you need to attach the other end of the buttons to ground.

Refer to the H-Bridge picture below and connect the following GPIO pins to the corresponding H-Bridge Pins:

  • GPIO 14 - IN1
  • GPIO 15 - IN2

This allows you to control MotorA which in my case is a 16” Linear Actuator. Note, on my H-Bridge the ENA pin has a jumper on it which activates MotorA. If the jumper is not used you will need to connect up another GPIO pin from the Raspberry Pi to ENA and change the code in coopdoor.py to turn the ENA pin on before activating either IN1 or IN2. For this reason it’s much simpler to put a jumper on the ENA pin.

Additionally, you will need to wire up MotorA the same way I did so that the polarity is correct and hence the door opens and closes correctly. To do this put the positive (usually red) wire in the upper most terminal of MotorA and the negative (black) in the lower terminal of MotorA.

Clone this wiki locally