'PBASIC program listing for June 2003 "Silicon Chip" PICAXE-08 "Chook Door" article 'Refer magazine for hardware needs and circuit of course. Ver 1.1 9th May 2003 'Code author & circuit designer Simon Goldstone => sgoldstone@optusnet.com.au 'Article writer (as part of series) Stan. SWAN => s.t.swan@massey.ac.nz ' ------------------------------------------------------------------------------------- start: pins = 0 'reset outputs to low readadc 1 ,b0 'read ldr on pin 1 if b0 >= 43 then raise 'this value is to kick start the system after 'initial powerup (ie after battery charging) if b0 < 43 then lower 'as above raise: 'this routine raises the door low 4 'make sure the lowering output pin 4 is kept low high 2 'send up command from pin 2 to latching relay 'via up transistor pause 500 'hold high for .5 seconds low 2 'send pin 2 low. Relay will have latched. goto up 'once door has been commanded to raise move on 'monitoring routine of opened door up: 'monitors open door and waits for pre close command readadc 1 ,b0 if b0 < 64 then lower '64 is the value of the door closing command if b0 <= 107 then pre 'this value is included to give a visual warning 'via the LED on output 0 that door closure is 'approaching. high 0 'this is a monitor function to indicate - 'the system is active pause 500 low 0 wait 30 goto up lower: 'this routine lowers the door low 2 'ensures the raise output is kept low high 4 'send down command from pin 4 pause 500 'hold pin 4 high for .5 seconds low 4 'return pin 4 low. relay will have latched goto down down: 'this routine monitors the door once it is down readadc 1 ,b0 if b0 > 107 then raise 'commands raise routine when enough light available if pin3 = 1 then warn 'pin 3 monitors the down microswitch. A visual 'output on pin 0 alerts that door is not closed 'when dark if pin3 = 0 then rest 'this line added to avoid recurring problems with 'false triggering during darkness goto down warn: 'this routine is the warning output from pin 0 for b1 = 1 to 20 'sets no. of flashes of LED high 0 pause 20 'keep pin 0 high for .02 seconds low 0 pause 500 'keep pin 0 low for .5 seconds next b1 pause 500 'wait .5 seconds goto down pre: 'this routine added to give a visual aid so one 'can see that the system is armed for closing just 'before dark.Very useful high 0 pause 20 'keep pin 0 high for 20 milliseconds low 0 pause 100 'keep pin 0 low for .1 seconds high 0 pause 20 low 0 wait 10 'wait 10 seconds goto up rest: 'the rest sequence to conserve power but mainly to 'stop false triggering during darkness which can 'cause the door to get spurious up commands sleep 300 goto down