pi and passive infrared sensor
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

pi and passive infrared sensor

by bill2009 on Mon Oct 21, 2013 2:13 pm

I have a parallax PIR sensor wired to my pi via the pi cobbler. + on the PIR is connected to 5V0 on the cobbler, - to pin labelled GND, OUT to pin labelled #25.(picture attached)

If I just power the pi, the reading on out is what I expect - 0v unless I put a hand in range then it goes to 3.2V for a few seconds. If I run the code though, it immediately goes to 3.2V and stays there (with occasional brief dips to 0v).

Clearly the code isn't right but I don't know why. I have tried a 10K resistor from OUT to ground and playing with the pullup/down specifications in the setup call but it didn't seem to change anything. The same thing happens with pin #24.

I'm using a raspbian image i downloaded with noobs a few days ago. The pi is a model B version 2.

Image

Image
bill2009
 
Posts: 6
Joined: Mon Oct 21, 2013 1:22 pm

Re: pi and passive infrared sensor

by bill2009 on Mon Oct 21, 2013 3:39 pm

hah! I did all the sudo apt-get stuff and it suddenly started working right.

I THEN REBOOTED AND IT's RIGHT BACK WHERE IT WAS!
bill2009
 
Posts: 6
Joined: Mon Oct 21, 2013 1:22 pm

Re: pi and passive infrared sensor

by adafruit_support_mike on Mon Oct 21, 2013 5:08 pm

Glad to hear you have it working. Happy hacking!
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10127
Joined: Thu Feb 11, 2010 2:51 pm

Re: pi and passive infrared sensor

by bill2009 on Mon Oct 21, 2013 6:49 pm

adafruit_support_mike wrote:Glad to hear you have it working. Happy hacking!


nope, after a reboot it is doing the same thing - stuck at 3.2V

I don't know if the problem is the cobbler or my unfamiliarity with linux but it's pretty frustrating. This is the most basic thing anybody would want to do with the pi/cobbler and it just doesn't work.
bill2009
 
Posts: 6
Joined: Mon Oct 21, 2013 1:22 pm

Re: pi and passive infrared sensor

by adafruit_support_mike on Tue Oct 22, 2013 12:59 am

Hmm.. let's test a couple of things:

Connect the sensor's VCC and GND pins to the RasPi, but disconnect the jumper between the sensor's OUT pin and the RasPi. Repeat the same sequence you've already done, testing it without the code running, then running the code.

With no connection to the RasPi, you'd think the sensor will continue to behave normally, but let's verify that.

At the same time, let's see what that GPIO pin is doing. Make a voltage divider between the RasPi's 3.3v pin and GND with a couple of 10k resistors, then connect the GPIO pin to the center of that divider. Without the GPIO pin connected, the voltage at the center of the divider should be 1.65v. Check that during the part of your test before you run the code, then check again after you start running the code. If there's an internal pull-up or pull-down resistor connected, you should see some change in the voltage at the center of the divider. If you have 100k resistors, those will make the change even more visible.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10127
Joined: Thu Feb 11, 2010 2:51 pm

Re: pi and passive infrared sensor

by bill2009 on Tue Oct 22, 2013 7:55 am

adafruit_support_mike wrote:Hmm.. let's test a couple of things:

Connect the sensor's VCC and GND pins to the RasPi, but disconnect the jumper between the sensor's OUT pin and the RasPi. Repeat the same sequence you've already done, testing it without the code running, then running the code.

With no connection to the RasPi, you'd think the sensor will continue to behave normally, but let's verify that.

At the same time, let's see what that GPIO pin is doing. Make a voltage divider between the RasPi's 3.3v pin and GND with a couple of 10k resistors, then connect the GPIO pin to the center of that divider. Without the GPIO pin connected, the voltage at the center of the divider should be 1.65v. Check that during the part of your test before you run the code, then check again after you start running the code. If there's an internal pull-up or pull-down resistor connected, you should see some change in the voltage at the center of the divider. If you have 100k resistors, those will make the change even more visible.

ok. thx - good suggestions. i won't be able to get at it til tonight but i appreciate your time.
bill2009
 
Posts: 6
Joined: Mon Oct 21, 2013 1:22 pm

Re: pi and passive infrared sensor

by bill2009 on Wed Oct 23, 2013 2:06 pm

Ok, I'm pretty sure the problem is with the PI's 5V supply. I tried the sensor from my arduino and it was fine so I connected the PIR power to the arduino's rail which shows 5.1V it behaves normally. If I power it from the PI's GPIO 5V which shows just under 4.9V it it goes to the failure mode - generally always high but occasional drops to 0v.

The sensor data sheet says it's good from 3.5 to 5v but i guess not!

I guess I'll let the arduino run the halloween automation. I'll see if i can get the pi to do sound effects and camera duty. If I come across another PIR sensor sometime i'll try it and I'll look for a beefier power supply cable - the wall wart already says it does 5.2V and trying other usb supplies generally gets lower 5v readings at the pi's GPIO.

Thanks for your help.
bill2009
 
Posts: 6
Joined: Mon Oct 21, 2013 1:22 pm

Re: pi and passive infrared sensor

by adafruit_support_mike on Wed Oct 23, 2013 9:24 pm

How much current does the PIR use?

The RasPi is known to have fairly tight power limits. It's a side effect of the tradeoffs necessary to hit the size/price/performance targets of the original design. If the PIR wants a lot of current, the RasPi might not be able to deliver enough.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10127
Joined: Thu Feb 11, 2010 2:51 pm

Re: pi and passive infrared sensor

by bill2009 on Thu Oct 24, 2013 7:33 am

the data sheet says 3ma. I assume that the problem is not the pi but the sensor. if the sensor is powered from the pi's 4.8v the it gives bad readings.
bill2009
 
Posts: 6
Joined: Mon Oct 21, 2013 1:22 pm

Re: pi and passive infrared sensor

by adafruit_support_bill on Thu Oct 24, 2013 7:56 am

it it goes to the failure mode - generally always high but occasional drops to 0v.

This is typical for these sensors. It happens when powered by Arduinos too - or even powered direct from a 5v supply. If you search the forums you will find several threads on the subject.

The re-triggering circuit occasionally drops the output to zero. This is not dificult to filter in code. It's pretty much the same logic as switch debouncing, but with a longer time constant.
User avatar
adafruit_support_bill
 
Posts: 30887
Joined: Sat Feb 07, 2009 10:11 am