mitchnufc
Posts: 16
Joined: Thu Sep 20, 2012 1:12 pm

PRI Sensors

Mon Oct 01, 2012 1:46 pm

Hello,

I need to purchase some cheap and reliable PRI motion sensors for use on a Raspberry PI, I'm not to good with components and wonder if someone would be kind enough to recommend some suitable ones from Farnell and also some simple connectors so I can connect these to the GPIO pins.

Thanks

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

Re: PRI Sensors

Mon Oct 01, 2012 1:55 pm

Can't speak for Farnell but this does what it says on the tin (at least for me).

http://www.ebay.co.uk/itm/Automatical-A ... 0947825391

mitchnufc
Posts: 16
Joined: Thu Sep 20, 2012 1:12 pm

Re: PRI Sensors

Mon Oct 01, 2012 2:32 pm

Yeah needs to be ordered through RS or Farrell as its through University. Thanks though

User avatar
hayesey
Posts: 78
Joined: Mon Nov 28, 2011 12:46 pm
Location: Manchester, England

Re: PRI Sensors

Mon Oct 01, 2012 3:13 pm

They're called PIR sensors, not PRI sensors. Searching on farnell's website for "PIR sensor" brings plenty of results.

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: PRI Sensors

Tue Oct 02, 2012 6:49 am

PIR sensors?

I'm using the ones from Tandy:

http://www.tandyonline.co.uk/pir-motion ... odule.html

They run at 5v, but produce a 3.3v output. I'm using it in the Halloween Pi project. (See this moths MagPi magazine!)

-Gordon
--
Gordons projects: https://projects.drogon.net/

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

Re: PRI Sensors

Tue Oct 02, 2012 9:29 am

Try this and others in the range from Farnell

http://uk.farnell.com/panasonic-ew/amn3 ... tt=1373712

work from 3V to 6V, digital output, lower current than older types, better detection zones, less prone to sun traversal problems. I have found them to operate in no output on at 1/5 current of standard devices people use.

They are only three pins power, gnd and output. in a metal can transistor style base (TO5)

You can use the 3V from Pi to power it direct, I first used them from self contained security cameras that had to run off batteries for 1 year.

You can find plenty of connection schemes for mounting them, I also would say one of my boards (see signature below)
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PRI Sensors

Wed Jan 09, 2013 10:36 am

joan wrote:Can't speak for Farnell but this does what it says on the tin (at least for me).

http://www.ebay.co.uk/itm/Automatical-A ... 0947825391
Can you tell me how you've wired this up? Did you connect it direct to the GPIO?

I've got a very similar looking PIR sensor and wired it up directly.

VCC ---- 5V
GND ---- GND
Out ---- GPIO18

When I enable the GPIO pin, create it as an input and cat the value it is constantly "1". Even without the VCC or GND (so Out + one other) connected it is still "1".

I've tried changing the jumper and tried adjusting the dials but never seem to get it to change to "0".

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: PRI Sensors

Wed Jan 09, 2013 10:55 am

ant_thomas wrote: When I enable the GPIO pin, create it as an input and cat the value it is constantly "1". Even without the VCC or GND (so Out + one other) connected it is still "1".

I've tried changing the jumper and tried adjusting the dials but never seem to get it to change to "0".
If you have wiringPi installed, then test the GPIO as follows:

Remove all hardware from the Pi:
Type:

Code: Select all

gpio mode 1 in
gpio mode 1 high
gpio read 1
gpio mode 1 low
gpio read 1
gpio mode 1 high
gpio read 1
You should get 1, then 0, then 1 from the gpio read commands.

And if that's OK, then start looking at the sensor.

One thing to know - the sensors need 5-10 seconds of no movement to stabilise. Then, when triggered, the'll hold the output for a set time. So you need to be still when you first power it up.

-Gordon
--
Gordons projects: https://projects.drogon.net/

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

Re: PRI Sensors

Wed Jan 09, 2013 11:02 am

I use the modules that Gordon mentioned. I ordered mine on eBay. If you can wait a few weeks you can get them for £2 from China (I've got 2 more on the way!). I've currently got one running 24/7 in my garage. The performance is great for something so small and cheap. If I remember correctly I wired mine up directly.

ant_thomas, are you sure you connected to Pin 12, GPIO18 and not Pin 18, GPIO24?
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)

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PRI Sensors

Wed Jan 09, 2013 11:18 am

Thanks Gordon, I'll give that a go.

Matt: Definitely referencing the correct GPIO pin (12/18). Once I unplug the "out" cable it goes to "0".

I'll give wiringPi a go tonight. Maybe it is constantly detecting movement. I'll stick the sensor in a box or something to avoid light/movement. I got mine off eBay, cost a grand total of £1.38!

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PRI Sensors

Tue Jan 15, 2013 7:36 pm

gordon@drogon.net wrote: If you have wiringPi installed, then test the GPIO as follows:
Only just had chance to give wiringPi a go but it doesn't seem to want to compile using "./build" even as root.

Here's the output

http://pastebin.com/TB9XNWkQ

(probably not the best thread for this!)

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: PRI Sensors

Tue Jan 15, 2013 7:44 pm

ant_thomas wrote:
gordon@drogon.net wrote: If you have wiringPi installed, then test the GPIO as follows:
Only just had chance to give wiringPi a go but it doesn't seem to want to compile using "./build" even as root.

Here's the output

http://pastebin.com/TB9XNWkQ

(probably not the best thread for this!)
Ah. you managed to grab a snapshot of wiringPi when I noticed that issue for myself and fixed it (ish) and pushed another version!

What you need to to is:

sudo apt-get install libi2c-dev

then run the ./build again. (no need to be root as long as sudo works for you)

The latest version (ie. 5 minutes after you pulled that one!) checks for it and advises on what you do.

-Gordon
--
Gordons projects: https://projects.drogon.net/

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PRI Sensors

Tue Jan 15, 2013 7:57 pm

gordon@drogon.net wrote:Ah. you managed to grab a snapshot of wiringPi when I noticed that issue for myself and fixed it (ish) and pushed another version!

What you need to to is:

sudo apt-get install libi2c-dev

then run the ./build again. (no need to be root as long as sudo works for you)

The latest version (ie. 5 minutes after you pulled that one!) checks for it and advises on what you do.

-Gordon
Bingo! Pulled it again and it compiled first time, thanks!

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PRI Sensors

Tue Jan 15, 2013 8:15 pm

gordon@drogon.net wrote:
If you have wiringPi installed, then test the GPIO as follows:

Remove all hardware from the Pi:
Type:

Code: Select all

gpio mode 1 in
gpio mode 1 high
gpio read 1
gpio mode 1 low
gpio read 1
gpio mode 1 high
gpio read 1
You should get 1, then 0, then 1 from the gpio read commands.

And if that's OK, then start looking at the sensor.

One thing to know - the sensors need 5-10 seconds of no movement to stabilise. Then, when triggered, the'll hold the output for a set time. So you need to be still when you first power it up.

-Gordon
Doing - gpio mode 1 high
gives - mode: Invalid mode: high. Should be in/out/pwm/up/down/tri

So no chance to read it as high or low because it won't let me set as high or low.

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: PRI Sensors

Tue Jan 15, 2013 8:46 pm

ant_thomas wrote:
gordon@drogon.net wrote:
If you have wiringPi installed, then test the GPIO as follows:

Remove all hardware from the Pi:
Type:

Code: Select all

gpio mode 1 in
gpio mode 1 high
gpio read 1
gpio mode 1 low
gpio read 1
gpio mode 1 high
gpio read 1
You should get 1, then 0, then 1 from the gpio read commands.

And if that's OK, then start looking at the sensor.

One thing to know - the sensors need 5-10 seconds of no movement to stabilise. Then, when triggered, the'll hold the output for a set time. So you need to be still when you first power it up.

-Gordon
Doing - gpio mode 1 high
gives - mode: Invalid mode: high. Should be in/out/pwm/up/down/tri

So no chance to read it as high or low because it won't let me set as high or low.
Sorry - I confuse myself sometimes.

gpio mode 1 up ; gpio read 1
gpio mode 1 down ; gpio read 1

etc.

I recently added the ability to write a gpio pin using high/low as well as 1/0 ...

-Gordon
--
Gordons projects: https://projects.drogon.net/

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PRI Sensors

Tue Jan 15, 2013 8:53 pm

They both output 0

I can use "gpio write 1 0" and "gpio write 1 1" to write 1 and 0 to the pin but mode 1 up or down doesn't seem to do anything.

Code: Select all

pi@raspberrypi ~ $ gpio mode 1 up
pi@raspberrypi ~ $ gpio read 1
0
pi@raspberrypi ~ $ gpio mode 1 down
pi@raspberrypi ~ $ gpio read 1
0
pi@raspberrypi ~ $ gpio write 1 1
pi@raspberrypi ~ $ gpio read 1
1
pi@raspberrypi ~ $ gpio write 1 0
pi@raspberrypi ~ $ gpio read 1
0
pi@raspberrypi ~ $

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PRI Sensors

Tue Jan 15, 2013 8:59 pm

Whereas pin 3/22 works fine (this is the one I was trying to plug the PIR sensor in to)

Code: Select all

pi@raspberrypi ~ $ gpio mode 3 down
pi@raspberrypi ~ $ gpio read 3
0
pi@raspberrypi ~ $ gpio mode 3 up
pi@raspberrypi ~ $ gpio read 3
1
pi@raspberrypi ~ $ gpio mode 3 down
pi@raspberrypi ~ $ gpio read 3
0

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: PRI Sensors

Tue Jan 15, 2013 8:59 pm

ant_thomas wrote:They both output 0

I can use "gpio write 1 0" and "gpio write 1 1" to write 1 and 0 to the pin but mode 1 up or down doesn't seem to do anything.

Code: Select all

pi@raspberrypi ~ $ gpio mode 1 up
pi@raspberrypi ~ $ gpio read 1
0
pi@raspberrypi ~ $ gpio mode 1 down
pi@raspberrypi ~ $ gpio read 1
0
pi@raspberrypi ~ $ gpio write 1 1
pi@raspberrypi ~ $ gpio read 1
1
pi@raspberrypi ~ $ gpio write 1 0
pi@raspberrypi ~ $ gpio read 1
0
pi@raspberrypi ~ $
I'm not sure what you're doing, or intending to do.

I'm suggesting a way to test the inputs of your GPIO pins, so:

Set them to input mode with nothing connected:

gpio mode 1 in

set the intenal pull-up to high:

gpio mode 1 up

read the pin - and expect 1:

gpio read 1

change the internal pull up to a pull-down and read the pin again:

gpio mode 1 down
gpio read 1

expect 0.

If you set the mode to output, or start writing when it's an input then it's not going to change anything...

-Gordon
--
Gordons projects: https://projects.drogon.net/

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PRI Sensors

Tue Jan 15, 2013 9:16 pm

I think my issue might be power.

The PIR sensor should be getting 5V but I've measured it at only 1.25V. I'll try and figure out that issue first!

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PRI Sensors

Tue Jan 15, 2013 10:29 pm

Power was the issue.

I've now got that sorted and it works great.

Thanks for the help. Even pointing me to wiringPi has made my scripting easier!

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PRI Sensors

Wed Jan 16, 2013 9:09 pm

I made a simple script to detect motion and report it. Nothing fancy.....

Code: Select all

#!/bin/bash
#

gpio mode 3 in

while true
do

if [ `gpio read 3` -eq 1 ];
then

echo 'Motion Detected: '`date +"%Y-%m-%d_%H-%M-%S"` >> /var/log/webcam/motion.log
echo 'Motion Detected'

else

echo 'No Motion'

fi
sleep 1

done
This works great when I run it manually.

I've created an init.d script to start it on boot and be able to stop/start/restart it. The script does start and can been seen as a running process but it doesn't detect any motion. If I manually restart the script motion is able to be detected.

Is there any issues with accessing GPIO pins using wiringPi via init scripts?

I've also tried adding /usr/bin/motion-log to rc.local which has the same result.

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: PRI Sensors

Wed Jan 16, 2013 9:43 pm

ant_thomas wrote:I made a simple script to detect motion and report it. Nothing fancy.....

Code: Select all

#!/bin/bash
#

gpio mode 3 in

while true
do

if [ `gpio read 3` -eq 1 ];
then

echo 'Motion Detected: '`date +"%Y-%m-%d_%H-%M-%S"` >> /var/log/webcam/motion.log
echo 'Motion Detected'

else

echo 'No Motion'

fi
sleep 1

done
This works great when I run it manually.

I've created an init.d script to start it on boot and be able to stop/start/restart it. The script does start and can been seen as a running process but it doesn't detect any motion. If I manually restart the script motion is able to be detected.

Is there any issues with accessing GPIO pins using wiringPi via init scripts?

I've also tried adding /usr/bin/motion-log to rc.local which has the same result.
init scripts are run with no environment - in particular no PATH set.

So at the start of the script do something like:

#!/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

or change gpio into $gpio and gpio=/usr/local/bin/gpio

-Gordon
--
Gordons projects: https://projects.drogon.net/

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PRI Sensors

Wed Jan 16, 2013 9:58 pm

Perfect!

Thanks again for your help.

Return to “General discussion”