Asked — Edited
Resolved Resolved by Dunning-Kruger!

Interfacing A Pir Onto The Ezb

I have tried every which a way and I cannot find a way to hook the PIR to the EZB. I have tried Analog,Digital, etc. I bought a dozen of these units - the ones with the TWO Potentiometers on the PC. You help would be appreciated.



Upgrade to ARC Pro

Join the ARC Pro community and gain access to a wealth of resources and support, ensuring your robot's success.


PIR can use digital (my old ones worked via analog)... Are you using a 5v voltage regulator?... I just tried and they work from the digital port... Sorry, I thought they were analog...

Note The ones I use are from Parallax... The cheap Chinese ones from eBay don't seem to work with the ezb


Yes, I just tried Digital and they work Great. Thanks for your help.


@MovieMaker, I've been wanting to set up a PIR on my project so it will "wake up" when it detects motion. Do you mind sharing how you have your's configured? and possibly some script to get me going? Thanks


@bhouston Probably the easiest sensor to use... You just plug it in to any of the ezb's digital ports. It is a basic 3 pin sensor (grn,signal,+5v)... When motion is detected the pin goes high... In a script all you have to do is monitor the digital port...

Of course you would do this in a loop or you can use Wait for change option. There are a few ways to do this...

set(D0,OFF) #You might need this line as well, not sure

IF($motion=1) #pin went high
#motion detected so do something



@Richard R, thanks, I'll try that.


Cool, I'd just like to mention that the Wait for Change command uses a lot less resources then a loop that's monitoring a port. This is very important if your monitoring an ADC port. I never monitored a Digital port so I cant comment on the resource draw there.


I was just testing it out. I haven't installed it yet. sorry,

United Kingdom

Dave beat me to it. WaitForChange() would work nicer.

# Do whatever


Wow, that was easy. I hooked up the PIR and ran the Loop code from Rich (thanks for your code as well Richard R) and my script ran when the PIR was triggered.

I put the script in "Script Manager" but with it there I can only run one script at a time.

My question now is - Where can I put the PIR script so that it is always running in the background so that when the PIR is triggered a script will run?



My code and @Rich's code should run continuous unless the code you added causes the script to exit... You can run as many scripts at a time as you want...

United Kingdom

You can run as many scripts in script manager at once as you like. My Ping Roam uses a lot of scripts and they run at the same time.

What I usually do with my projects is add a Script Manager control (sometimes more than one if I want an easy way to organise different script types but let's not over complicate it), add all scripts to that.

Assuming the PIR detection script is named "PIR Detect" and in Script Manager you just need to set it running on connection which is very simple...

Add a control, choose Scripting and choose EZ-Script (not script manager) Name the script "init" Add the following line

ControlCommand("Script Manager", ScriptStart, "PIR Detect")

Add in anything else you want to do on connection, i.e.

SayEZB("Connection has been established")

or nothing if you prefer. Save it Next click on the cog/gear icon on the Connect control (top left) You should see 5 boxes for "Connection Established Cmd". Assuming your EZ-B is EZ-B 0 (the top one) click the pencil icon to the right of the top box Add the following code to the script

ControlCommand("init", ScriptStart)

Click Save Click Save on the connection dialogue

Now whenever your EZ-B is connected it will run the init script. The init script will start the PIR detection script.

You could cut out some of the above however if you do it the way I describe it gives more scope for other init actions.


Man, you guys are great! I will try what you suggested Rich. I did make voice commands to start and stop the PIR sensing and that works good too.

Thanks again


So taking to PIR sensor a few steps further, I would like to do the following but really don't know where to start, so I'll put my Idea out there;

I would like my robot to power down after a specified time of inactivity, then when the PIR senses movement the robot will power up and run a script.

I current have the "Auto Release" in use as well as the PIR, which reacts to movement.

Any help would be appreciated, Thanks


When you mean power down do you mean the ezb too? Because the ezb will have to remain active in order to monitor the PIR... Other peripherals can be powered down by using relays to save power (e.g. like lights, motor controllers etc)


I know that the EZB has to remain powered up. Just have all of the servos power down


Well I think you answered you own question... Use Release all to save power on the servos...:)


But this is what I'm trying to do;

I would like my robot to power down (servos) after a specified time of inactivity, then when the PIR senses movement the robot will power up and run a script.


I am not sure what you're asking... Use the waitforchange (or my code) command in an active script... When motion is detected then do exactly what you said... Use ControlCommand("PowerUp", ScriptStart) in you motion detected script to start your script called PowerUp ....

You will of course need to create a script called PowerUp and put in it what you want the robot to do when it wakes up from motion detected....

United Kingdom

What will the robot be doing while it's counting down to shut down servos?

This topic may be of some assistance to you. It's not exactly what you are asking for but should put you on the right track in the right direction at least.


Here's what I got so far. Not exactly what I want but I'm starting to understand it more. This just repeats over and over;

repeatUntil(1=2) set(D11,OFF) #You might need this line as well, not sure sleep(20) $motion=getDigital(D11)

IF($motion=1) #pin went high ControlCommand("Auto Position", AutoPositionFrameJump, "Wakeup") Sleep(1000) sayezb("i am awake now") sleep(2000) ControlCommand("Auto Position", AutoPositionFrameJump, "Rest")


sleep(10000) endRepeatUntil

Now I need to add a "timer" so that If the robot does nothing for X amount of time it will release all servos but continue to poll the PIR. Then when it senses motion it will power up do the above ONCE and then go back to "Timing" for the next event.

Thanks Rich I will start reading

United Kingdom

For a timer you can use something as crude and simple as a counter script like so...

$x = 0

RepeatUntil($x = 60)

Obviously it needs more to it as it doesn't actually do much other than count down but the idea is there. There are other methods too, the above may not be the best method (I didn't really think about it much) but it's a method that you can build on.

Basically it will count down for 1 minute with 1 second intervals. Throw the controlcommand, if, etc. either before or after the sleep (it doesn't really matter which side you put it).


Thanks I'll keep working on it


Further to @Rich's timer solution (which is really pretty good)... You could remove $x=0 from the timer script and run just the timer script continually... Since all variables are global you can have $x reset to 0 in all your other active scripts (except for the PIR monitoring script of course)... That way while you bot is awake and doing stuff it keeps the timer constantly set to 0. That is until activity stops and then within 60 seconds (or whatever length of time you choose) the bot will go into sleep mode...

Just an idea...

United Kingdom

$x = 0 is there because if it is run before anything else it will fail as $x wouldn't exist. Unless $x is in the init script.

Also, it isn't a forever looping script so once $x did hit 60 (for any reason) the repeat loop would end and the script would stop. Hence why it needs to be part of a bigger script.


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.

#timer to power down
$x = 0
RepeatUntil($x = 30)


#what to do when timer gets to 30

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


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

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

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

#stay powered up -  need something here - what?

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

If($x = 30)


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