USA
Asked — Edited
Resolved Resolved by JustinRatliff!

Pir Script

I'm trying to read the status of a PIR detector using:

getDigital(D0)

but it is always showing the the port is high, whether something is in front of it or not. Do I first have to designate that the port is in input port, and if so, how do I do this? If that is not the issue, any suggestions?

Thanks for anyone willing to assist.

R1D1


ARC Pro

Upgrade to ARC Pro

Get access to the latest features and updates before they're released. You'll have everything that's needed to unleash your robot's potential!

United Kingdom
#1  

Here's a simple example to test your PIR sensor...

If (GetDigital(D0) = 1)
  Print(detected)
EndIf

And here's a quick example I used to test my PIR sensor a while ago...

If(getDigital(D0)=1)
Print ("On")
Elseif(getDigital(D0)=0)
Print("Off")
Sleep (2000)
Goto(start)
Endif

Hope that helps.

#2  

If your port is always high then either your PIR is not working, wired incorrectly or won't work off of 3.3V .... The ezb is not an Arduino so you don't need to designate the port as an input or output....

United Kingdom
#3  

One other thing to add, does your PIR have a potentiometer on the back? If so, that might need adjusting. The one I use has two, one for adjusting distance, and one for light sensitivity which had to be adjusted.

#4  

The PIR unit's I own require 5 volts. If you can send us a link to the PIR unit you are using we can check the specs.

United Kingdom
#5  

As Justin stated, some PIR sensors require 5v like the one I use as well, so it may need a regulator depending on you EZ-B power set up if you don't use one already, v4 ground and Vcc pins via regulator, and signal to digital out on PIR. I wanted to add one thing further, some PIR's have DO (digital out) and AO (analog out) pins, so of yours has these pins, make sure your using DO on a digital port.

#6  

I have Parallax PIRs and they work fine off of 3.3v.... I have one in my inMoov as we speak... not all PIRs need 5v...

#7  

I bought the unit from TotalRobots about 5 years ago, but never used it, so while it is not new, it hasn't been used before. TotalRobots advertises it simply as "Passive Infrared Motion Sensor". The document I got with it says it should be powered from 5 volts.

My EZB runs off a 6 volt nimh, and I have an inline 5 volt voltage regulator between the sensor and the EZB.

I used code just like the first example above, except my output was for speech, instead of print, sleep 10 seconds and check the status of the pin again, but I can point it at the wall and it just keeps indicating the pin is high every time.

#8  

I should add that the documentation says when it does not detect anything it puts out < 0.8VDC. If it does detect something it puts out >2.5VDC.

United Kingdom
#9  

Have you tried adjusting any settings on the PIR itself? Most (not all) sensors have some kind of adjustment that can be done by turning a knob or using a screwdriver (potentiometer).

User-inserted image

#10  

Do you have a link for "TotalRobots", I could not find them from a google search.

Not all PIR have the adjustment potentiometers like SteveG pictured. The kind he pictured is probably the standard type now, but there are older ones still being sold that don't have the pots and in documentation suggest having a pull up or pull down resister. I'd really like to see the exact PIR you purchased @R1D1. If you can't find a site link to the product can you post a pic of your PIR if SteveG's advice does not work?

@RichardR, I'm surprised the Parallax PIR's run on 3.3 volts. That's handy to know! :)

#11  

@R1D1 Try it on an analog port (since it is an old PIR version).... see if the voltage changes with motion.... Also I was referring to the ezb's signal pin being only 3.3v... that may have something to do with why it won't work ....

@JustinRatliff User-inserted image

#12  

@RichardR, that makes sense, you have the revB that works in the lower voltage range.

#13  

Here is a picture of the sensor. There is no place to make any adjustments. I was however able to dig up some old notes that came with it saying that if it always indicates that the sensor is activated, then to connect a 10k resistor between the signal wire and ground. So now I've got to see if I've got one laying around, as Radio Shack is no longer!

User-inserted image

#15  

Unfortunately, too much secular work right now. I will try to wire up the resistor this weekend and post as to whether or not this was successful.

Thanks for all of the input so far.

#16  

@R1D1, if you can't find a 10K resister let me know and I'll mail you a few for free. My email address is in my profile.

#17  

I appreciate the offer for the resistor Justin. I found two 5.6K 's. So I could put them in series and be pretty close. Think there is any harm in being 1.2K off?

#18  

I don't think there will be any harm to try it. My guess is it will work, but it is possible it could be too much resistance to allow the sensor to trip or it might not be optimal, but certainly no harm.

#19  

Well, finally got some time to play with this again. I grounded the signal wire with two 5.6k resistors in a series and that did the trick! Finally, seeing a spark of life in my project. Thanks so much for your input. All of you were helpful. Hopefully I'll be able to add to the discussion in time.