I'm having difficulty getting my Parallax PIR to work properly in my program. I've used the simple test code below and everything works fine. The PIR waits for motion to trigger, it lights the LED on b.1, resets to 0 and waits for motion to retrigger. I've used this code successfully in several controllers I've built with the 08 Picaxe and with the exception of some false triggers outside during the day, it's worked fine.
The problem comes into play when I add the PIR code in with the rest of the program. The PIR will trigger without any motion and will not reset to 0 causing the program to immediately restart when it loops back. I've added an LED into the PIR wire and it stays lit most of the time but does have periods where it will go out. Here's the code for the complete program which is controlling one of the scenes in my Halloween display. Any help would be appreciated.
Code:
#Picaxe 18M2
Testit:
readadc b.7,b0
debug b0
pause 5 'Brief pause on the checking loop
b0 = b0 + 5 * b.7
if b0 < 100 then Testit
goto Routine
Routine:
high b.1
pause 3000
low b.1
pause 5000
goto Testit
Code:
'Picaxe 18M2 Seance Room Controller
'B.0 is Bookshelf motor and light
'B.1 is Light for Rocking chair
'B.2 Audio in for jaw servo
'B.3 Starts audio
'B.4 is Wiper Motor for rocking chair
'B.6 is Skeleton jaw servo
'B.5 is DVD servo
'B.7 is PIR
#Picaxe 18M2
Init: 'Just a starting point label
debug
Pause 6000'0 'Wait 60 secs for PIR to 'settle down
Symbol btime = b4
Symbol delay = 5000 'Sets variable delay for making the whole thing wait for a while after pressing the button
Servo b.5,75
Testit:
readadc b.7,b0
debug b0
pause 5 'Brief pause on the checking loop
b0 = b0 + 5 * b.7
if b0 < 100 then Testit
goto Routine
Routine:
high b.1 'Light comes on Rocking Chair
high b.4 'Skeleton starts rocking
high b.0 'Bookshelf starts moving and its light comes on
high b.3 'Serial output pin idle-high
wait 2 'Allow module to fire up
serout b.3,T4800,($EF) 'STOP module
wait 2
serout b.3,T4800,($01) 'PLAY song 001.mp3
w3=5000 'Counter for number of loops needed, every 1000 = about 15 seconds +/-
b2=8 'Set pause delay
b3=180 'Set Servo Min position and also offset - mouth open
b4=214 'Set Servo Max position - mouth closed
Servo b.6,b3 'Initialises b.6 as a servo output and sets servo to the start position
OP:
ADCA: 'Reads input voltage in 256 steps Pin 1 (leg 6)
Readadc b.2,b5 'Read input voltage into b0
b1=225-b5+b3 'Add offset for servo's CCW output
If b1<b3 then gosub servomax 'Test for less than servo min position and if less, set at servo min
If b1>b4 then gosub servomin 'Test for more than servo min position and if more, set at servo max
MoveA: 'Move servoA
servopos b.6, b1 'Pulse pin 4 (leg 3) width=b1 - Using servopos can help prevent jitter
pause b2 'Wait Delay b2
w3=w3-1 'Decrement the counter
if w3>0 then goto OP 'Test for counter being larger than 0 if yes, go round the loop again
goto Projection
goto OP
servomin:
b1=b3
return
servomax:
b1=b4
return
Projection:
low b.1 'Light goes off on Rocking Chair
low b.4 'Skeleton stops rocking
goto Pressdown
pressdown:
servopos b.5,160 'Move servo to other end to press button and start Madame Leota
pause 500 'Hold the button down for a half a second
servopos b.5,75 'Move the servo back to the other position
w3=5000
Madame:
w3=w3-1 'Decrement the counter
if w3>0 then goto Madame 'Test for counter being larger than 0 if yes, go round the loop again
goto Hold
Hold:
low b.0 'Bookshelf stops and its light goes out
for btime = 1 to 30 '30 is the number of seconds of retriggger delay
pause 1000 'Pause for 1 sec
next btime
goto Testit 'Go back and wait for the PIR again