First off, great forum. Been cruising through for a few days now, looking at all the horribly complex projects all you boffins are completing, and thought I’d chip in with what I’m currently doing/planning to do. The aim is to explain my project and attract as many comments and as much criticism as possible so the project can be improved!
So, as the title suggests, I’m making an automatic chicken coop door opener. Chickens tend to rise and go to bed with the sun (i.e. dawn and dusk). During the summer months they wake VERY early, and if the door isn’t opened for them the chickens get particularly cross. They make this anger audible. The reason for closing the door in the first place is that our area is crawling with foxes and cats who would, given half the chance, quickly run off with one of the ladies during the night.
I actually made an automatic door 5 years back with two mechanical timers and 5 relays, but it was horribly unreliable. Having discovered the PICAXE last week, I’ve been messing around and I think this is the answer. Coupled with a sturdy and reliable guillotine-type door we can hopefully say bye-bye to early mornings!
So here’s the plan: 08M chip. LDR senses daylight. At dawn (I’ll have to fiddle the ADC value) the chip arms a relay, which will drive the 12V motor and pull up the door. Once the door is opened a switch will close, providing an input into the chip and stopping the motor. The switch will also turn on an orange LED. At dusk, the chip arms another relay which will drive the motor in the opposite direction (closing). Again, another switch will input into the chip once the door is closed, stopping the motor and switching on a red LED. That’s pretty much it.
Now some points:
So, some questions:
Looking forward to your thoughts!
Tim
CODE:
So, as the title suggests, I’m making an automatic chicken coop door opener. Chickens tend to rise and go to bed with the sun (i.e. dawn and dusk). During the summer months they wake VERY early, and if the door isn’t opened for them the chickens get particularly cross. They make this anger audible. The reason for closing the door in the first place is that our area is crawling with foxes and cats who would, given half the chance, quickly run off with one of the ladies during the night.
I actually made an automatic door 5 years back with two mechanical timers and 5 relays, but it was horribly unreliable. Having discovered the PICAXE last week, I’ve been messing around and I think this is the answer. Coupled with a sturdy and reliable guillotine-type door we can hopefully say bye-bye to early mornings!
So here’s the plan: 08M chip. LDR senses daylight. At dawn (I’ll have to fiddle the ADC value) the chip arms a relay, which will drive the 12V motor and pull up the door. Once the door is opened a switch will close, providing an input into the chip and stopping the motor. The switch will also turn on an orange LED. At dusk, the chip arms another relay which will drive the motor in the opposite direction (closing). Again, another switch will input into the chip once the door is closed, stopping the motor and switching on a red LED. That’s pretty much it.
Now some points:
- I know there is a driver array available to drive the motors, instead of using two relays. However, as I already have the relays, and NPN transistors, and as the driver array still requires two outputs, I’d rather not spend the money.
- I’m not sure which type of switches to use for the open/closed sensing. The 5 year old door uses magnetic reed switches, but I found that the chickens would sometimes knock the door which caused the magnet to move out of range of the reed switch. As a result, I’m thinking of just using push-to-make switches at the top and bottom of the door frame, and as the door is pushed onto the switch (or falls onto the switch when closing), this will provide an input into the chip.
- Alternatively, I could just run the motor for a pre-determined length of time to open and close the door – this way I’d have two free input/output pins which I could do other funky stuff with. The state of the door would be stored in the EEPROM as a simple 0/1 (true/false) variable, which will be checked when the relay is about to be activated. But then I’d never know if the door was actually open/closed (snapped/tangled/mangled wire etc).
- I was actually thinking of having a combination of switch and timer: if the switch is not activated after a pre-set amount of time (a bit longer than the door would take to open/close), then stop the motor anyway and provide some sort of error signal (perhaps flash both red/green LEDs?).
So, some questions:
- What do you reckon to the circuit diagram (attached – apologies for the quality: first time EAGLE user) and code? I know the code could be condensed by combining the CLOSE and checkClosed functions (labels), but it seems a bit easier to read for me at the moment!
- If I wanted to leave the serial jack out of the board (i.e. program the PICAXE on another board), what do I do with leg 2 (SERIN) – can I just tie it to ground with a 32k (10k+22k) resistor (as in second schematic)?
- Is it possible to do what I want using less pins than I’ve already allocated?
- Has anyone else done something similar? If so, how did you determine the state of the door (open/closed)? Switches – if so, which?
- This is going to be on all day, every day. Should I foresee any problems with running this device 24/7?
Looking forward to your thoughts!
Tim
CODE:
Code:
' Automatic Chicken Door Opener
'
' Dawn: will open the chicken door
' Dusk: will close the chicken door
'
' Dawn/dusk detected by a LDR
' Motor driven in opposite directions using two relays
'
' When door closed, red LED lit
' When door open, green LED lit
' When door moving, orange/amber LED lit
let dirs = %000011010
symbol openSwitch = pin2 'INPUT pin for door-open-detect switch
symbol closeSwitch = pin3 'INPUT pin for door-closed-detect switch
symbol doorOpen = 1 'OUPUT pin for door open relay
symbol doorClose = 0 'OUPUT pin for door close relay
symbol door_is_open = b0 'Boolean variable to store whether the door is open or close
symbol light_input = b1 'Int variable to store the amount of 'sunlight'
'FUNCTION: main body
main:
'read 0,door_is_open 'EEPROM CODE: Read eeprom value
readadc 4,light_input
if light_input<50 then 'Dusk is detected
if openSwitch = 1 and closeSwitch = 0 then CLOSE 'Door is open, so close it
'if door_is_open = 1 then CLOSE 'EEPROM CODE: Door is open, so close it
elseif light_input>=200 then 'Dawn is detected
if openSwitch = 0 and closeSwitch = 1 then OPEN 'Door is closed, so open it
'if door_is_open = 0 then OPEN 'EEPROM CODE: Door is closed, so open it
endif
pause 60000 'Take a (long) breather. Turn down for simulation testing!
goto main 'And round we go again
'FUNCTION: Activate when you want door to close
CLOSE:
high doorClose 'Activate the CLOSE relay (R_CLOSE on the schematic)
goto checkClosed
'FUNCTION: Activate when you want door to open
OPEN:
high doorOpen 'Activate the OPEN relay (R_OPEN on the schematic)
goto checkOpen
'FUNCTION: Checks for input during the door closing
checkClosed:
if openSwitch = 0 and closeSwitch = 1 then 'Constantly check to see if the door has hit the closed switch
'TIMER could go in here instead of IF statement
'door_is_open = 0 'EEPROM CODE: write 'false' to door_is_open (door is closed)
goto finish 'Once the closed switch has been hit, finish off.
endif
goto checkClosed
'FUNCTION: Checks for input during the door opening
checkOpen:
if openSwitch = 1 and closeSwitch = 0 then 'Constantly check to see if the door has hit the opened switch
'TIMER could go in here instead of IF statement
'door_is_open = 1 'EEPROM CODE: write 'true' to door_is_open (door is open)
goto finish 'Once the opened switch has been hit, finish off.
endif
goto checkOpen
'FUNCTION: Final tidying up after movement, then back to main body
finish:
let pins = %00000000 'Turn off all relays
'write 0,door_is_open 'EEPROM CODE: write door_is_open boolean to position 0
goto main
Attachments
-
262.7 KB Views: 169
-
244.5 KB Views: 120