Hi all very new to picaxe and there is probably a better way to do this, but did not find a lot of code for pir's out there in googles, so any suggestions are great, this is part of a chicken protection system, I live in a rural Maine US town Porter if you care to know, that has lots of critters that like to eat chickens everything from weasels to bears. I keep a few, 8 or so Rhode Island Reds for fresh eggs, and wish to keep them safe. The idea is some pir sensors, an ldr sensor, an alarm siren, and bright lights which I want to turn on only after dark. The following code has been bread boarded and works as intended on an 08m2. This is my only my second bit of working project code, I am 52 yo newbie to this stuff so any ideas, pointers, or primers gratefully accepted.
and so since I am going to need more than 1 pir sensor to cover coop and run area, this is the code scaled up for 6 pirs and one ldr, on a 14m2, and I'll bet there is a way better way to do this, but it seems to work. I wondered about putting all pir sensors to one pin but feared it would over load it. Would like to get it all on the little 08m2 board but as a newbie felt this was safer and easier to trouble shoot should a pir fail.
Thanks for looking ossipee [river I live on banks of]
Code:
main:
readadc 1,b1 'pir sensor
readadc 4,b4 'ldr sensor
if b1> 0 and b4> 100 then sethigh 'turn on siren alarm
if b1> 0 and b4< 100 then sethigh2 'turn on flood lights and siren alarm
if b1= 0 then setlow 'nothing is around all quiet
goto main
sethigh: 'siren only
high 0
goto main
sethigh2: 'siren and lights
high 0
high 2
goto main
setlow: 'no critters siren lights off
low 0
low 2
goto main
Code:
main:
readadc 1,b1 'ldr sensor
readadc 2,b2 'pir sensor 1
readadc 3,b3 'pir sensor 2
readadc 4,b4 'pir sensor 3
readadc 5,b5 'pir sensor 4
readadc c.0,b6 'pir sensor 5
readadc c.4,b7 'pir sensor 6
if b7>0 or b2>0 or b3>0 or b4>0 or b5>0 or b6> 0 and b1> 100 then sethigh 'its light out audible alarm only
if b7>0 or b2>0 or b3>0 or b4>0 or b5>0 or b6> 0 and b1< 100 then sethigh2'its dark out lights on audible on
if b7=0 and b2=0 and b3=0 and b4=0 and b5=0 and b6=0 then setlow'no critters about all quiet on chicken front
goto main
sethigh:
high c.2 'siren alarm'
goto main
sethigh2:
high c.1 'flood lights and alarm siren
high c.2
goto main
setlow:
low c.1 'all quiet
low c.2
goto main