Kiss Chicken Coop Door
(Keep it simple stupid)
I have seen a lot of automatic chicken coop doors on the net, most take a lot of knowledge to make happen. I have tried a few different ones most are great, but just not simple. You need an engineer degree or a programing degree to make it happen. That why I decided to keep it simple, my door is very simple and you can design into it what every you want as time goes, but in the mean time you have a working door. So on with the door.
What we will need.
- 2 x 4 x 8
- 12 volt motor ( I used a window motor form a car door slow speed lots of torque and have of a pulley more on that later)
- Piece of thin aluminum size of door I used an aluminum commercial baking sheet
- Some fishing line I used Spider wire
- Pi3 (and the norms keyboard, mouse, monitor)
- Motor Controller L298N
- Some braided wire and some male to male and female to female jumpers
- Power supply for Pi3 and a 12 DC power supply for door motor
- Pi3 (is what I have) and a micro SD card ( I used a 32GB card)
Step 1
Okay to start we need to make the door I bought this used commercial baking sheet from a scrap metal supplier for a buck used what every you can find my door is a little taller I have some turkeys in my run also. I just sawed the edges off to make a flat light weight door. Then I drilled a hole in the top center about a ½ inch down to tie my fishing line into to lift door. Picture 1
Step 2
Next we need a set of tracks for the door to run. I ran my 2 x 4 x 8 thru a table saw, you can use a skill saw, router whatever you have just be careful and know what you are doing or get someone to do it for you. I started the slot about ½ in from the edge ran it the length of 2 x 4 then cut the 2 x 4 in half. This will give you a track for both sides of the door. Make the slot a little wider than the thickness of your door so it will slide easily and not bind. Now install your tracks inside your coop. Slide your door inside them and screw them to the wall of your coop keeping the slot side towards the wall. Also keep your screws back from the edges on the slot side so that you don’t stick a screw thru the slot. Space your 2 x 4 with slots about ¼ inch wider than your door to allow a little space to keep door from binding when going up and down. Picture 2
Step 3
Now install your motor so that the center of your pulley is center of the door. Keeping it high enough for your door to open all the way and some extra space for your string. (Mine is about 20 inches higher than my opened door) I used a car window motor it has a small gear boxed attached so it runs very slow up and down.
Step 4
Setting up the Pi. There are tons of info on the net on getting the Pi up and running. This is the official site if you click on link then read thru the info this should get you going goes in steps you can click on from the left side of the page.
https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up
I have a Pi3 like I said in the beginning I not much on programming, learning as I go that’s why I love the Pi. So for all the experts out there I’m sure I have a lot of coding mistakes and may be an easier way of doing this, but everything I looked at and tried had pages of code. So that’s why I came up with this, basically you have a python script that tells door to open and another one to tell it to close. Then I use a crontab to tell which script when to run. Pretty simple. You will need your Pi, your L298N motor controller and I used
1 yellow female to female
1 blue female to female
1 orange female to female
1 black female to male
1 red female to male jumper wire like you use with Pi and breadboards (you can use any color you like)
A couple of lengths of wire pairs one to go from 12 VDC power supply to the motor controller and then one to go from controller to DC motor.
On the L298N for this we are going to pull all the jumpers off the board.
Out1 and out2 goes to the DC motor
Plus 12VDC goes to the positive side of your 12 VDC power supply
GND goes to the ground side of your power supply and to Pin 39 of the Pi
ENA goes to Pi pin 22
In 1 goes to Pi pin 16
In2 goes to Pi pin 18
Now, I did add some code that will text me when the door opens and again when it shuts. For this you would have to set up a Twilio account and have internet Wi-Fi available. I did not include the texting part of the code, this is basic and simple. If you look down thru the code you will see the sleep 1.5 this will set the amount of time your motor will run. You will need to have door open, run the closed code manually and figure out how much longer you need to run it to close all the way. For example to get your door to close if you have to run the close 4 times to shut door than you would take 4 x 1.5 equals 6 that would be what you change the sleep time on open and close from 1.5 to 6 then run open if it does not open all the way then adjust accordingly both open and close should be set the same. On my setup my sleep is set at 7.5, depending on your motor speed and height of door and height it needs to raise door yours will vary. When you are working on this be prepared to unplug one of the wire if you need to stop motor till code times out (I have alligator clips so I can disconnect in a hurry if something goes wrong making adjustments) Here are the open and close scripts, if you are using a windows computer you can download Kate a text editor open up a new window copy and paste the Open code in it and save it as Open.py and same for close. Then transfer it to the desktop of the Pi.
Code:
# This is the Door Open Code
import RPi.GPIO as GPIO
from time import sleep
import time
from datetime import datetime
from twilio.rest import Client
GPIO.setmode(GPIO.BOARD)
Motor1A = 16
Motor1B = 18
Motor1E = 22
GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)
print ("Turning motor on")
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
GPIO.output(Motor1E,GPIO.HIGH)
# Edit sleep(1.5) controls the length of time motor runs
#.5 is short 1.5 runs longer
sleep(1.5)
print ("Stopping motor")
GPIO.output(Motor1E,GPIO.LOW)
GPIO.cleanup()
Code:
# This is the Door Close Code
import RPi.GPIO as GPIO
from time import sleep
import time
from datetime import datetime
from twilio.rest import Client
GPIO.setmode(GPIO.BOARD)
Motor1A = 16
Motor1B = 18
Motor1E = 22
GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)
print ("Turning motor on")
GPIO.output(Motor1A,GPIO.LOW)
GPIO.output(Motor1B,GPIO.HIGH)
GPIO.output(Motor1E,GPIO.HIGH)
# Edit sleep(1.5) controls the length of time motor runs
#.5 is short 1.5 runs longer
sleep(1.5)
print ("Stopping motor")
GPIO.output(Motor1E,GPIO.LOW)
GPIO.cleanup()
This is the crontab
To edit the crontab bring up terminal and type in
crontab –e
should bring up something like this
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
Use the arrow keys and scroll down below this and start typing in your job you need and when you want it done. Anytime you have the # sign in front of a line of code it will be ignored it is just used to write in notes so you can remember what’s going on. I saved my Open.py and my Close.py to my desktop so it would be easy to access in the future if I need to run it manually. This will run the Open.py at 5:30 am every morning of everyday and the Close.py at 9:00 pm every evening of every day. This time will need to be adjusted for you and from time to time depending on day light dark and when you want it to open and close. Not a big deal open terminal type in crontab –e scroll down using arrow keys on keyboard then over to the number you are changing with arrow key.
# Open The Door At Certain Time
30 05 * * * python3 /home/pi/Desktop/Open.py
# Close The Door At Certain Time
00 21 * * * python3 /home/pi/Desktop/Close.py