Canada
Asked — Edited
Resolved Resolved by Rich!

Trying To Get A Pir Working

I feel like a blind man wandering around in the bush at night hoping to find my way home!

So here's where I'm at with this project, I've put some comments in so you can see what I'm trying to accomplish. Any and all help will be appreciated.



:loop
#timer to power down
$x = 0
RepeatUntil($x = 30)
$x++
Sleep(1000)

EndRepeatUntil
repeatUntil(1=2)

#what to do when timer gets to 30

set(D2,OFF)
#$x = GetDigital(D2)
ControlCommand("Script Manager", ScriptStart, "power down")#do this once

sleep(5000) 
WaitForChange(GetDigital(D2))
sleep(5000)

#do this when the PIR is triggered after "power down"

$motion=getDigital(D2)
IF($motion=1) #pin went high
ControlCommand("Script Manager", ScriptStart, "Power up")#do this once
endif

#do this if PIR is triggered anytime after it has powered up

$motion=getdigital(D2)
if($motion=1)
#stay powered up - need something here - what?
sleep(10000)
EndIf

# if Pir is not triggered in 30 sec start the timer again

If($x = 30)
GoTo(loop)
endif
EndRepeatUntil


Thanks

PS. I would pay money to go to a course somewhere to learn EZ-Robot scripting!


ARC Pro

Upgrade to ARC Pro

ARC Pro is more than a tool; it's a creative playground for robot enthusiasts, where you can turn your wildest ideas into reality.

#9  

@bhouston... Digital will return a value of 1 or 0 (true or false)... whereas 8 bit analog will be something like 0 - 255... So when reading analog you should assume the PIR has been activated if the adc7 value is greater than say something like 100... The number may vary so you will need to test this...

#10  

@Richard R, I have tried several different settings - none make a difference. Any other thoughts?

#11  

Can you try changing part of your code your code to this?


# Check the status of the analog port
$PIR = GetADC(ADC7)
# Check if it is high or low and take action
IF($PIR >100)
 # Motion detected, return to start
 Goto(start)
EndIf

#12  

@Richard R, Tried that at different values - no change

United Kingdom
#13  

Can the PIR work on the analogue ports? Check it's datasheet (post it's datasheet if unsure). Bearing in mind that the Analogue ports are 3.3v regulated which may not be enough voltage to power the PIR or may cause problems if there isn't enough current available.

If not, you may need to build a small circuit to make it work for ADC.

#14  

Try this in a separate script and see what values $pir are giving you... wave your hand in front of the pir detector and see what happens to the value of $PIR


repeatuntil(1=2)
$PIR = GetADC(ADC7)
print($PIR)
sleep(3000) #give time for the PIR to rearm
endrepeatuntil

United Kingdom
#15  

Or add the ADC graph, value or meter control;)

#16  

@Rich... bite me LOL.... Forgot about the analog value control. That's much easier... I have some PIRs from Parallax Inc and I have them working on both analog and digital ports... Saying that however, @bhouston does not have the same PIRs so you may be right, the ones he has may not work via analog...