#picaxe 14m2 ;*values to be set
symbol east=w0 ;sensor east
symbol west=w1 ;sensor west
symbol offset=b5 ;adjust this value according to sun intensity at location and sensor mounting
symbol volts=b6 ;12.6v lithium-ion actuator and picaxe battery level
symbol light=b7 ;lightning storm and morning
symbol flash=b9 ;flash LED when battery is under preset
symbol watch=b12 ;false alarm on night_parking
symbol diff=w10 ;difference between east and west on sensors
Low_Battery:
if b13=2 then goto overload
do
readadc c.4,volts
if volts=<143 then low b.4 low c.2 ;battery under 11.1v static or 9.6v loaded, turn off actuator drive, east=b.4, west=c.2
high c.1 inc flash endif ;turn OFF H bridge driver
if flash=>250 then let flash=1 endif ;prevent stack overflow
if flash=>1 and volts<150 then high c.0
pause 200 low c.0 pause 1000 endif ;flash warning LED
loop until volts=>150 let flash=0 b8=0 ;battery over 11.5v, start tracking
Light_level:
for b11=1 to 20
readadc10 b.1,east ;read PhotoTransistor sensor east
readadc10 b.5,west ;read PhotoTransistor sensor west
if east=>1000 or west=>1000 then let b10=1
low c.1 pause 50 goto sun_tracking endif ;minimum light level for tracking reached,turn ON H Bridge driver
if time=>14500 and b10=0 then low c.1 pause 100 high b.4 ;cloudy weather, light below tracking limit
low c.2 pause 40000 low b.4 high c.1 let b10=1 endif ;drive tracker to the horizontal if low light from dawn after 4hrs*
if east=<5 and west=<5 then inc watch endif
if east=<5 and west=<5 and watch=>240 then let watch=0 ;minimum light level, wait 4mins,dusk has arrived*
time=0 low c.1 goto night_parking ;turn ON H bridge driver for home parking
elseif east>5 or west>5 then let watch=0 endif ;dusk level false alarm, reset b12 before 4 mins has past
pause 1000
next b11
goto low_battery ;check battery voltage every 20seconds
Sun_tracking:
do
readadc10 b.1,east ;read PhotoTransistor sensor east
readadc10 b.5,west ;read PhotoTransistor sensor west
if east=<1023 or west=<1023 then let offset=4 ;*differential offset gain level change, according to light intensity
elseif east<1016 or west<1016 then let offset=7 ;*
elseif east<1004 or west<1004 then let offset=10 endif ;*
if east<1000 and west<1000 then low c.2 ;below minimum light level for solar collection,stop tracking**
low b.4 high c.1 goto light_level endif ;turn OFF H bridge driver
if east>west then let diff=east-west
gosub drive_east ;store east/west difference into DIFF when tracking east
elseif west>east then let diff=west-east
gosub drive_west endif ;store west/east difference into DIFF when tracking west
if volts=<125 and b8=0 then let b8=1 endif ;battery drops to 9.6volts under load
if pinc.2=0 and pinb.4=0 and b8=1 then readadc c.4,volts ;when actuator turns OFF, 60secs has passed,readvolts to see if the voltage has recovered
endif
if pinc.2=0 and pinb.4=0 and b8=1 and volts=<140 then ;still <10.8v
inc b13 goto low_battery ;voltage has not recovered suspend operation until battery is charged
elseif pinc.2=0 and pinb.4=0 and b8=1 and volts>140 then ;voltage has recovered >10.8v continue operation
let b8=0 endif
loop
Drive_east:
if diff>offset then high c.2 pause 30 ;brighter in the east,turn ON east,turn OFF west drive
low b.4 readadc c.4,volts ;track east, check voltage under load
elseif diff<offset then low c.2 ;hysterisis value. when east/west sensors gets within a set distance of tracking sun hold position*
low b.4 pause 60000 endif ;hold position for 60sec once locked to sun, prevents false motion(clouds,tree branches)
return
Drive_west:
if diff>offset then high b.4 pause 30 ;brighter to the west,turn ON west,turn OFF east drive
low c.2 readadc c.4,volts ;track west, check voltage under load
elseif diff<offset then low c.2 ;hysterisis value. when east/west sensors gets within a set distance of tracking sun hold position*
low b.4 pause 60000 endif ;hold position for 60sec once locked to sun, prevents false motion(clouds,tree branches)
return
Night_parking:
high c.2 pause 30
low b.4 ;drive actuator back to east home position
do
if pinb.2=1 then exit ;tilt switch stops motion, so actuator is sheltered from frost by the panels
loop until time=>180 ;turn off picaxe output after 3mins
low c.2 high c.1 ;turn OFF H bridge driver and picaxe output to save power over night
do
readadc10 b.1,east
if east=>180 then inc light ;east sensor indicates dawn or lightning storm then inc light variable
elseif east=<80 then light=0 endif ;if light level drops below set, then reset light variable, lighting storm activity
if east>180 and light=>13 then let light=0 ;light level over set point for over 5mins consistantly
time=0 b10=0 b8=0 b13=0 goto light_level endif ;morning has arrived
sleep 10 ;23sec low power state
loop
Overload:
low c.2 low b.4 high c.1 ;turn OFF actuator and H bridge driver in case of overload
do
high c.0 pause 1000 low c.0 pause 200 ;flash LED to warn of NO tracking operation
loop
;Single axis solar tracker with Li-ion 12.6v 700mHr for actuator and control circuit battery
;Uses PhotoTransistors for sensors
;Functions
;1)low voltage, Lo-ion battery monitor (short flash LED)
;2)minimum light level detection and auto light intensity(once OFFSET value is set for sensor angle and location)
;3)return home to east after sun down
;4)overload detection in case of frosted or seized actuator (long flash LED)
;5)false tracking in lightning storms and to save drive battery power at night