Updated - Chicken house lights Mk II
Hi all,
A word of encouragement for anyone working themselves up to starting their first project. I found the whole PICAXE thing really easy. Hopefully you will too.
I do have the advantage of being a programmer for part of my career, but haven't done any electronics since Uni, many many years ago.
The first project I set myself was to build a circuit to automatically control lights in a Chicken house. I'm hoping the same design will work just as well for watering the greenhouse.
The lights will come on at dusk and stay on for a couple of hours. What constitutes "dusk" and "a couple of hours" can be set by the user - the circuit has a "learn" mode for this. For greenhouse watering, it will only be a couple of minutes rather than hours, with the lights replaced by a cheap boat bilge pump submerged in a water butt.
A PICAXE 08M2 is used, and LDR senses the light level and a logic-level FET controls the lights. The whole thing runs on a 12V battery, kept topped up by a solar cell.
The lights can be switched on or off at any time be pressing an illuminated button. Pressing the button for 5 seconds puts the circuit in "learn" mode where it records the light level at that point and times how long the user leaves the light on. It then repeats this daily.
Hi all,
A word of encouragement for anyone working themselves up to starting their first project. I found the whole PICAXE thing really easy. Hopefully you will too.
I do have the advantage of being a programmer for part of my career, but haven't done any electronics since Uni, many many years ago.
The first project I set myself was to build a circuit to automatically control lights in a Chicken house. I'm hoping the same design will work just as well for watering the greenhouse.
The lights will come on at dusk and stay on for a couple of hours. What constitutes "dusk" and "a couple of hours" can be set by the user - the circuit has a "learn" mode for this. For greenhouse watering, it will only be a couple of minutes rather than hours, with the lights replaced by a cheap boat bilge pump submerged in a water butt.
A PICAXE 08M2 is used, and LDR senses the light level and a logic-level FET controls the lights. The whole thing runs on a 12V battery, kept topped up by a solar cell.
The lights can be switched on or off at any time be pressing an illuminated button. Pressing the button for 5 seconds puts the circuit in "learn" mode where it records the light level at that point and times how long the user leaves the light on. It then repeats this daily.
Code:
; Dusk activated light/pump timer
; P.Beard 14/8/2011
#picaxe 08m2
symbol timerload = 1 ; lights/pump etc output pin
symbol lightlevel = 2 ; light level analog input pin
symbol pushbutton = pin3 ; Pushbutton input pin
symbol pushbuttonLED = 4 ; LED (inside pushbutton) output pin
symbol interruptmask = %00001000 ; interrupt on Pin3 (pushbutton)
symbol interruptvalue = %00001000 ; when Pin 3 high
symbol daymode = 0
symbol duskmode = 1
symbol nightmode = 2
symbol learnmode = 4
symbol shortbuttonclick = 1
symbol longbuttonpress = 20
symbol currentmode = b0 ; learn/run mode
symbol dusk = b2 ; light level at dusk
symbol day = b3 ; min light level during day
symbol ontime = w3 ; time load has been on so far
symbol onlength = w4 ; required load on-time
symbol dusksaved = 0 ; addresses in non-volatile memory
symbol onlengthsaved = 1
data dusksaved, (64)
data onlengthsaved, (20, 0) ; approx a minute
main:
setfreq k31 ; clock setting for lowest power consumption
currentmode = daymode
low timerload
low pushbuttonLED
read dusksaved, dusk ; read saved dusk level from non-volatile memory
day = dusk + 50 ; prevent a small change in light level causing switch to day mode
read onlengthsaved, word onlength ; read on length from non-volatile memory
do
select currentmode
case daymode
readadc lightlevel, b1
if b1 <= dusk then
currentmode = duskmode
high timerload
ontime = 0
end if
case duskmode
inc ontime
if ontime > onlength then
currentmode = nightmode
low timerload
end if
case nightmode
readadc lightlevel, b1
if b1 >= day then
currentmode = daymode
end if
case learnmode
inc ontime
end select
toggle pushbuttonLED ; flash the led to show timer working
toggle pushbuttonLED
setint interruptmask, interruptvalue
pause 20 ; approx 3 seconds at 31KHz clock
setint off
loop
interrupt:
b1 = 1
do while pushbutton = 1 ; time how long pushbutton pressed
inc b1
loop
if b1 >= longbuttonpress then
currentmode = learnmode
high pushbuttonLED ; show user we are in learn mode
readadc lightlevel, dusk ; capture the dusk light level
write dusksaved, dusk ; save dusk level to non-volatile memory
day = dusk + 50
high timerload
ontime = 0
elseif b1 >= shortbuttonclick then
select currentmode
case daymode, nightmode
currentmode = duskmode
high timerload
ontime = 0
case duskmode
currentmode = nightmode
low timerload
case learnmode
currentmode = nightmode
onlength = ontime
write onlengthsaved, word onlength ; save onlength to non-volatile memory
low pushbuttonLED
low timerload
end select
endif
setint interruptmask, interruptvalue
return
end
Last edited: