memons
Posts: 12
Joined: Mon Mar 04, 2013 10:39 pm

PIR Sensor

Mon Mar 04, 2013 10:54 pm

my.png
my.png (2.55 KiB) Viewed 3592 times
Hi,
newbie here.. can some one help me please.
I have a cheap PIR sensor, which I bought from ebay. It has three pins. It connects with 9v battery.
i am able to detect motion with it, as i am able to light up a LED on output line or can check output with ameter.
When I connect out line with my PI it never detect the output for reason.
I connected the out wire from sensor into pin 17 and ran the following program:

Code: Select all

from time import sleep
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN)

while True:
    if ( GPIO.input(17) == True ):
        print "Warning - MOTION has been detected!"
    else:
        print "All is QUIET in RPiLand..."
    sleep(1);
but it is always quite in RPILand.
Can some one help me please.
thanks
Please see the diagram
Last edited by memons on Tue Mar 05, 2013 11:38 am, edited 3 times in total.

User avatar
MattHawkinsUK
Posts: 538
Joined: Tue Jan 10, 2012 8:48 pm
Location: UK
Contact: Website

Re: PIR Sensor

Mon Mar 04, 2013 11:13 pm

Did you mean "Pin 17"? Pin 17 on the GPIO Header is actually 3.3V.

Your code is expecting GPIO17 which is on Pin 11.
My Raspberry Pi blog and home of the BerryClip Add-on board : http://www.raspberrypi-spy.co.uk/
Follow me on Google+, Facebook, Pinterest and Twitter (@RPiSpy)

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: PIR Sensor

Mon Mar 04, 2013 11:21 pm

Make sure you've got resistors in the circuit - you don't want 9V going anywhere near your RPi!

The ones I've got from ebay work at 5V - I used a resistor ladder (2k2 and 3k3 to divide 5V voltage down to 3V to feed into my RPi.

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

texy
Forum Moderator
Forum Moderator
Posts: 5161
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: PIR Sensor

Tue Mar 05, 2013 12:24 pm

memons, please reply to the thread, do not 'report this thread' because that just goes to the moderators, not to the people in the thread.

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

memons
Posts: 12
Joined: Mon Mar 04, 2013 10:39 pm

Re: PIR Sensor

Tue Mar 05, 2013 2:58 pm

Do i still needs resistor, if the out is just 3.3 volt going in PI?
simplesi wrote:Make sure you've got resistors in the circuit - you don't want 9V going anywhere near your RPi!

The ones I've got from ebay work at 5V - I used a resistor ladder (2k2 and 3k3 to divide 5V voltage down to 3V to feed into my RPi.

Simon

memons
Posts: 12
Joined: Mon Mar 04, 2013 10:39 pm

Re: PIR Sensor

Tue Mar 05, 2013 2:59 pm

Exactly, see the diagarm - is there some thing wrong with diagram. do i need to include some thing else here?
MattHawkinsUK wrote:Did you mean "Pin 17"? Pin 17 on the GPIO Header is actually 3.3V.

Your code is expecting GPIO17 which is on Pin 11.

User avatar
joan
Posts: 14887
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: PIR Sensor

Tue Mar 05, 2013 4:00 pm

If you are putting 9V across V+ and GND you'll be getting 9V on the OUT pin (according to the preliminary specs). If you've fed that into a Pi gpio without a resistor you will have fried the gpio. Even with a resistor you may have fried a gpio. You should be using a voltage divider resistor pair.

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: PIR Sensor

Tue Mar 05, 2013 5:30 pm

Nobody pick up on the fact there isn't a ground connected ? The voltage will need doctoring to suit the Pi, but unless the Pi shares a ground there is no circuit.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

User avatar
joan
Posts: 14887
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: PIR Sensor

Tue Mar 05, 2013 5:41 pm

pluggy wrote:Nobody pick up on the fact there isn't a ground connected ? The voltage will need doctoring to suit the Pi, but unless the Pi shares a ground there is no circuit.
I didn't. The OP is lucky if that is the case.

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: PIR Sensor

Tue Mar 05, 2013 6:39 pm

Nobody pick up on the fact there isn't a ground connected ?
:lol :lol: :lol:

I didn't even look at the diagram ! :(

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

memons
Posts: 12
Joined: Mon Mar 04, 2013 10:39 pm

Re: PIR Sensor

Tue Mar 05, 2013 10:26 pm

joan wrote:If you are putting 9V across V+ and GND you'll be getting 9V on the OUT pin (according to the preliminary specs). If you've fed that into a Pi gpio without a resistor you will have fried the gpio. Even with a resistor you may have fried a gpio. You should be using a voltage divider resistor pair.
@joan
i have made sure that Pir sensor only return 3.3v before connecting it and yes PI is not fried yet it is working properly

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: PIR Sensor

Tue Mar 05, 2013 10:31 pm

memons wrote:
joan wrote:If you are putting 9V across V+ and GND you'll be getting 9V on the OUT pin (according to the preliminary specs). If you've fed that into a Pi gpio without a resistor you will have fried the gpio. Even with a resistor you may have fried a gpio. You should be using a voltage divider resistor pair.
@joan
i have made sure that Pir sensor only return 3.3v before connecting it and yes PI is not fried yet it is working properly
How di you measure it ?

Between which two points did you put the meter/scope to measure the pulse and idle condition levels?
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

memons
Posts: 12
Joined: Mon Mar 04, 2013 10:39 pm

Re: PIR Sensor

Wed Mar 06, 2013 8:27 am

techpaul wrote:
memons wrote:
joan wrote:If you are putting 9V across V+ and GND you'll be getting 9V on the OUT pin (according to the preliminary specs). If you've fed that into a Pi gpio without a resistor you will have fried the gpio. Even with a resistor you may have fried a gpio. You should be using a voltage divider resistor pair.
@joan
i have made sure that Pir sensor only return 3.3v before connecting it and yes PI is not fried yet it is working properly
How di you measure it ?

Between which two points did you put the meter/scope to measure the pulse and idle condition levels?
@techpaul:
I measured it with VOUT of sensor and ground of sensor. Is it wrong assumption?

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: PIR Sensor

Wed Mar 06, 2013 8:35 am

@memons

You need to measure it without it being connected to the RPi

If its 3.3V or less under those circumstances then you are (luckily!) OK.

If its not, then you are just lucky (So far! :) )

A lot of people "get away" with electrical errors (I do) - but we don't want them thinking that its right and that it'll work next week still :)

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

memons
Posts: 12
Joined: Mon Mar 04, 2013 10:39 pm

Re: PIR Sensor

Wed Mar 06, 2013 9:43 am

simplesi wrote:@memons

You need to measure it without it being connected to the RPi

If its 3.3V or less under those circumstances then you are (luckily!) OK.

If its not, then you are just lucky (So far! :) )

A lot of people "get away" with electrical errors (I do) - but we don't want them thinking that its right and that it'll work next week still :)

Simon
@simplesi:
Yes I have measured it without being connected with RPi. And output of the sensor is 3 volts.
Should I use ground of RPi and Vout of sesnor? as RPi is not reading sensor signal.

memons
Posts: 12
Joined: Mon Mar 04, 2013 10:39 pm

Re: PIR Sensor

Wed Mar 06, 2013 9:47 am

pluggy wrote:Nobody pick up on the fact there isn't a ground connected ? The voltage will need doctoring to suit the Pi, but unless the Pi shares a ground there is no circuit.
@pluggy:
Sorry very novice here! can you please explain "Pi shares a ground there is no circuit"?
Thanks

User avatar
joan
Posts: 14887
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: PIR Sensor

Wed Mar 06, 2013 9:54 am

memons wrote:
pluggy wrote:Nobody pick up on the fact there isn't a ground connected ? The voltage will need doctoring to suit the Pi, but unless the Pi shares a ground there is no circuit.
@pluggy:
Sorry very novice here! can you please explain "Pi shares a ground there is no circuit"?
Thanks
If the only connection between the Pi and your circuit is the gpio then no current will flow. That would explain why you haven't damaged the Pi. For current to flow there needs to be a ground connection between the Pi and your circuit (i.e. the Pi's ground needs to be connected to the PIR ground pin). If you don't have a ground connection I wouldn't add one until you have fixed the voltage problems.

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: PIR Sensor

Wed Mar 06, 2013 10:53 am

Ok then, if output is TRULY 3V, then just connect Pin6 from your RPi to the negative end of your battery

If no magic smoke appears from your RPi then it should detect the sensors output.
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: PIR Sensor

Wed Mar 06, 2013 11:07 am

Your basic problem is not reading the datasheet http://www.infratec-infrared.com/Data/L ... asheet.pdf

The output is a CURRENT output not a voltage output, so the output does not generate a voltage sufficient to drive any GPIO This is common for PIR sensors as current output drive means when not triggered the output stage is drawing NO current which makes it good for low power situations.

Also it can be supplied by 9V but I would personally use the recommended supply voltage of 5V. Better still use the 3V3 from the Pi then output can NEVER go above 3V3.

The main addition you need is a resistor from output pin to ground, disconnected at first from Pi then measure voltage acrioss the resistor and if necessary adjust resistor or resistor divider to give you about 3V to Pi.

Personally I would power the PIR by 3V3 (from the PI) and put a 10k resistor from PIR output to GND.

Once you have that setup THEN connect to Pi with GND as well.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: PIR Sensor

Wed Mar 06, 2013 11:11 am

Becaiuse it is a current output that is why you could light a LED (not best way to drive the LED from these dvices) and measure the current with an ammeter.

Driving the LED might have overdriven the output stage of the PIR.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

memons
Posts: 12
Joined: Mon Mar 04, 2013 10:39 pm

Re: PIR Sensor

Wed Mar 06, 2013 5:40 pm

techpaul wrote:Your basic problem is not reading the datasheet http://www.infratec-infrared.com/Data/L ... asheet.pdf

The output is a CURRENT output not a voltage output, so the output does not generate a voltage sufficient to drive any GPIO This is common for PIR sensors as current output drive means when not triggered the output stage is drawing NO current which makes it good for low power situations.

Also it can be supplied by 9V but I would personally use the recommended supply voltage of 5V. Better still use the 3V3 from the Pi then output can NEVER go above 3V3.

The main addition you need is a resistor from output pin to ground, disconnected at first from Pi then measure voltage acrioss the resistor and if necessary adjust resistor or resistor divider to give you about 3V to Pi.

Personally I would power the PIR by 3V3 (from the PI) and put a 10k resistor from PIR output to GND.

Once you have that setup THEN connect to Pi with GND as well.
@techPaul:
Thank you so much for comprehensive answer. But I am not able to comprehend it. I guess I need to first read basic electronics.
Can you please explain The main addition you need is a resistor from output pin to ground, disconnected at first from Pi then measure voltage acrioss the resistor and if necessary adjust resistor or resistor divider to give you about 3V to Pi.

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: PIR Sensor

Wed Mar 06, 2013 6:37 pm

memons wrote:@techPaul:
Thank you so much for comprehensive answer. But I am not able to comprehend it. I guess I need to first read basic electronics.
Can you please explain The main addition you need is a resistor from output pin to ground, disconnected at first from Pi then measure voltage acrioss the resistor and if necessary adjust resistor or resistor divider to give you about 3V to Pi.
First test your PIR by connecting a 10k resistor between the PIR output pin and its ground
Power the PIR from your 9V battery.

At this stage do NOT connect anything to the PI

Measure with a Voltmeter (or multimeter on voltage setting), between PIR gnd and PIR output when idle (no motion) and when active (motion detected).

You will probably find that idle is 0V and active is nearly 9V

Now disconnect the battery supply
Then connect the PIR power to Pi 3V3 and PIR GND to Pi GND
Repeat voltage measurements and you should find that idle is 0V and active is nearly 3V3

At this point now connect PIR output (with resistor still also connected to GND) to Pi GPIO and try your software again.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: PIR Sensor

Wed Mar 06, 2013 6:45 pm

Actually for the resistor it could be anything between 10k and 100k that you have to hand.

10k is the minimum value
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

memons
Posts: 12
Joined: Mon Mar 04, 2013 10:39 pm

Re: PIR Sensor

Thu Mar 07, 2013 9:44 am

techpaul wrote:
memons wrote:@techPaul:
Thank you so much for comprehensive answer. But I am not able to comprehend it. I guess I need to first read basic electronics.
Can you please explain The main addition you need is a resistor from output pin to ground, disconnected at first from Pi then measure voltage acrioss the resistor and if necessary adjust resistor or resistor divider to give you about 3V to Pi.
First test your PIR by connecting a 10k resistor between the PIR output pin and its ground
Power the PIR from your 9V battery.

At this stage do NOT connect anything to the PI

Measure with a Voltmeter (or multimeter on voltage setting), between PIR gnd and PIR output when idle (no motion) and when active (motion detected).

You will probably find that idle is 0V and active is nearly 9V

Now disconnect the battery supply
Then connect the PIR power to Pi 3V3 and PIR GND to Pi GND
Repeat voltage measurements and you should find that idle is 0V and active is nearly 3V3

At this point now connect PIR output (with resistor still also connected to GND) to Pi GPIO and try your software again.
@techpaul:
Thank you very much.
I am able to get Pi triggered when I connect PIR sensor directly with RPi. Thanks for the info.
But if i want to connect PIR using external battery. How can make it to trigger RPi. Should I connect PIR's ground with pi's ground and Power line with battery? I dont want to fry my Pi.
And yes I have made sure that PIR's output is 3.3 volts.
Thanks

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: PIR Sensor

Thu Mar 07, 2013 10:09 am

memons wrote:@techpaul:
Thank you very much.
I am able to get Pi triggered when I connect PIR sensor directly with RPi. Thanks for the info.
But if i want to connect PIR using external battery. How can make it to trigger RPi. Should I connect PIR's ground with pi's ground and Power line with battery? I dont want to fry my Pi.
And yes I have made sure that PIR's output is 3.3 volts.
Thanks
If using a 9V battery to power the PIR, then the output from the PIR can go to any voltage up to 9V.

When you did the voltage test with the PIR not connected to the PI,what did you meausre across the resistor?

I suspect it was about 9V. So you would need to put a resistor divider on the PIR output to reduce the voltage output so the PIR output pin was at its nearly 9V connected to the top of the divider and the middle of the resistor divider is taken to the Pi with around 3V level and the bottom end of the
resistor divider taken to gnd (of battery and PI).

As batteries drain down over timethe output level will drop and the divided output wil drop in the same ratio. So choosing the two resistor values will take some calclulations. Based on max battery level of new battery and minimum battery level you want to go down to. Then you have to find the right ratio to keep the divided voltage within the range acceptable for the Pi to recognoise the voltage within its limits.

As the device can work down to 2.7V it can work on a very dead battery, well below the normal dead battery voltage that most devices can work with. To work anything out you need to measure and define
1/ What battery voltage level range to use (bearing in mind a 9V battery new can be 10V)
2/ What voltages do you get out of the PIR with 9V battery currently not connected to Pi
3/ Length of cable between PIR and Pi
4/ What resistor values and types you have access to
5/ could you use a very low current 3V3 regulator from your battery to power the PIR

Personally for this type of application I would resitor divide the PIR output by 3 or 4, then feed it into an op-amp in voltage comparator mode to provide around 3V output all the time, so it can work on almost any battery level range. Also I would do something similar to monitor battery level so when a resistor divided voltage from the 9V battery went well below a threshold level the Pi on another GPIO could detect a battery low condition.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

Return to “General discussion”