PDA

View Full Version : Light Activated Chicken Coop Door



Scampy
- 21st January 2014, 23:44
This project was a request from my wife who has recently had a coop delivered and now keeps three chickens (producing an egg each every day - yum !). To ensure the chickens are let out when the sun comes up, and to stop my wife complaining as she realised she would be getting up at 5am in the summer she asked if I could come up with something to automatically open the coop door and let the chickens out in the morning.

Commercial door openers that tend to use a clock and require programming cost in excess of £120 by the time you've purchased a modified door to go with them. They also rely on gravity to close them as the motor simply winds up a cord on a pulley to open it and unwinds it to close it. The door on our coop slides horizontally !

After a few days trawling the net to get inspiration, I found it on a DIY CNC machine where motors were used to turn threaded bar, thus moving the rail attached to it. I did some rough calculation and worked out that a 6:1 geared motor would give enough speed to open the door fairly quickly, so ordered one of the MFA motors from Maplin. Whilst proving the project on the development board I was going to use normal transistors for the H-Bridge to control the test motor, but ordered a L298 board of E-bay for a fiver to control the MFA motor.

With help from the guys here (my PBP programming skills are a tad rusty as I don't code that often) I have the code proven and it works fine on the desk. My next step is to place the PIC and a few resistors etc on a bit of strip board, place it all in a box and then fix it and the motor to the coop. Anyway, in a bid to return the help Henrik, Al, Robert and a few others gave me here is my code and a schematic. Note that the diodes etc for the motor is all contained on the H-Bridge board.



'************************************************* ***************
'* Name : Light Activated Door Control *
'* Author : Malcolm Crabbe *
'* Date : 21st January 2014 *
'* Version : 1.0 *
'* Notes : Uses PBP 2.60c *
'* : 12F683, int osc *
'* : Program uses a light dependent resistor to turn *
'* : on an electric motor and open a sliding door. *
'* : Door travel controlled by limit switches *
'************************************************* ***************


ASM
__CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF
endasm

DEFINE ADC_BITS 10 ' ADC resolution
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
number VAR word ' Variable to store ADC result
day var byte ' Variable to indicate day or night

CMCON0=7
CCP1CON=0
ANSEL = %00000001 ' GPIO.0 A/D in, rest digital
ADCON0.7 = 1 ' Right justify for 10-bit
GPIO = %00000000 ' Initialize outputs
TRISIO = %101011 ' GPIO 0,1,3,5 = input, 2 & 4 outputs


Motor1 var gpio.2 ' H-Bridge pin 1
Motor2 var gpio.4 ' H-Bridge pin 2
SW1 VAR gpio.5 ' Door open limit switch
SW2 VAR gpio.1 ' Door open limit switch

low Motor1 ' Turn off H-Bridge pin 1
low Motor2 ' Turn off H-Bridge pin 2
day=0 ' Initialise unit to check if day time

main:

if sw1=0 then day = 0 ' If limit switch is open, and mode is night then
adcin 0,number ' Read AN0
if day=0 then ' Day 0 = night, Day 1 = Day
If number >400 then ' If ACD result is above a threshold
high Motor1 ' Turn on H-Bridge pin 1
Low Motor2 ' Turn off H-Bridge pin 2
endif
endif

if SW1 = 1 then ' Door closes limit switch and applies 5v to GPIO.5
low Motor1 ' Turn off H-Bridge pin 1 } Stop motor
low Motor2 ' Turn off H-Bridge pin 2 }
day = 1 ' Set variable to day to indicate the door is open
endif

if sw2=0 then ' Door closes limit switch and applies 5v to GPIO.1
low Motor1 ' Turn off H-Bridge pin 1 } Stop motor
low Motor2 ' Turn off H-Bridge pin 2 }
endif

goto main


OK there may well be smarter, tighter way of coding, but this works and seems logical to my way of thinking !!

Regards

Malcolm

Dam, juts noticed I made an error in the schematic - The LEDs should be after the switches not between them and the supply... its been a long day and its late !! - I'll correct it and upload a new version later

Demon
- 22nd January 2014, 00:56
SW2 VAR gpio.1 ' Door open limit switch
You mean closed?

SW3 is a manual override in case of predators?


there may well be smarter, tighter way of coding, but this works and seems logical to my way of thinking !!
It doesn't matter if there's a more efficient way. The important thing is that this works for you, and understand what's going on.

Darrel, Henrik and a few others can make circles around me in code (actually it's a lot more than a few). But using their code isn't much use to me if I can't make changes for my application.

So, when are you putting bands on your chicken to make sure they all came in?

Robert
:)

richard
- 22nd January 2014, 10:47
if sw3 is pressed at the wrong time or the motor stalls before the limit switches operate (ie door shuts on a chook , fox , next door neighbours kid )you will let the smoke out of your l298 .
those cheap satellite positioners make really good easy to use linear actuators ,somewhat weather proof too.
also you could use gp3 as an input to check that the motor is not stalled (reed sw and a magnet that rotates with the motor)