PIR on RPi

How do I detect motion using a PIR on a RPi using FreeBSD?

Which wires do I connect to where and can I get any sample code from anywhere? I only want to switch on a LED if motion is detected. Would I need a breadboard to make this work?
 
Would I need a breadboard to make this work?
No they make all kinds of little expermenter boards with PIR sensor. Just two wires. One to a ground and one to a GPIO pin.
You must set the GPIO pin for the correct mode (input).
To switch on a LED when PIR is triggered might take a small script. You need to poll the PIR as it is nothing more than a on/off switch.
 
I just had a look at ebay and I see that PIR sensors use 3 wires.
Power(VCC), Ground, Signal.
All you need is a board like this and some Pi jumper wires (female to female).
I have found these to be most useful even on motherboards.
I had a 1U case I was re-purposing and the power switch leads were too short.
Pi Male to Female jumper wires were the perfect extension cord!
 
It sounds like you have not yet used a switch with GPIO.
I suggest you start there. First bring up an LED with the jumper wires. Then try a conventional toggle switch.
You will find that a switch alone is really touchy. If you flip the switch back and forth quickly FreeBSD GPIO will lose some switch cycles.
This phenomenon is called debounce. When you flip a switch it drives a GPIO pin low or high. Since the switch is dumb there is no feedback as to the actual position of the switch. So commonly to hold a switch at a state a resistor is used to drive a pin state. Beaglebone has some resistors built in. Pi does not.
Using the PIR ciruit board you may notice some circuitry. This is time delay and sensativity.
The time delay should help you with GPIO pin driving. On PIR triggering the sensor would send hundreds of on-off cycles. So the circuity helps smooth out the switch signal. Remember PIR is a switch too.
 
Not entirely sure what you mean by 'conventional toggle switch'....

As for PIR, I see it has three pins, gnd, output and Vcc. I have the RPI2-B so assume gnd can use any of the pins 6,9,14,20,25,30,34,39.... Also assume Vcc should connect to either 2 or 4. Not sure if the PIR uses 3.3v or 5v...
No idea where the output pin should be connected...
 
What you could do is study the default pin states. gpioctl -lv
Some RPi pins are inputs and some are outputs.
Start with your LED Pin and find an OUT pin to use with it and the same with PIR. Look for a IN pin.
That way on startup it is already the right direction. Otherwise you must define pins (IN/OUT) with a script or the dtb.
 
Back
Top