In one of my current projects, I’d like to use a few motion or proximity sensors, also known as PIR sensors.
PIR sensors, or Passive Infra Red sensors, can be great for Arduino and Raspberry Pi projects, and can be bought really cheap – I only paid about a dollar per sensors in bundle of 10 PIR sensors from eBay, but you can get them really cheap at places like Amazon or AliExpress as well.
In this short article we will see how we these sensors work, how the can be used, how we can test them, and possible fine tine them a little bit.
No Arduino, Raspberry Pi or anything like that is needed. Just a PIR, a LED, a battery and a resistor.
What is a PIR sensor?
A PIR sensor is an electronic sensor that measures infrared light radiating from objects in its field of view. Normally this type of sensor would be used as a motion or proximity sensor.
Quite often they are referred to as:
- PIR Sensor
- Motion Sensor
- Proximity Sensor
- Infrared (motion) Sensor
- Pyroelectric sensor
Cheap PIR – Top view
Cheap PIR – Sensor Exposed
Cheap PIR – Bottom view
The short and simple explanation on how these sensors work
The sensor in the PIR detects or “reads” infrared radiation “emitted” from objects all around us.
Each object with a temperature above absolute zero ( -273.15° Celsius, -459.67° Fahrenheit, or 0 Kelvin) will radiate infrared, even us humans, and even though we mere humans cannot see this.
With special Thermal Infrared Camera’s however, this can be made visible to the human eye.
Note that the PIR just uses a relatively simple sensor – it is most definitely not a camera!
Example of InfraRed radiation
PIRs are called “passive” since they are not assisted by any “helpers” that for example would send some form or shape of “radiation” or “light” to help detect. It’s purely based on what the sensor can pick up out of the environment, what’s being emitted by objects.
PIR’s actually only look at the “difference” between two sensor “halves”. If the difference is too high then it will trigger – it detects “motion”. This is done in a smart way, to avoid false positives caused for example by a brief flash or an increase in room temperature.
A chip and some discrete electronics handles all this for you.
PIR Lens “Dome”
As you can see in the pictures above, the PIR has some funny dome-like bubble, which is a collection of lenses covering the sensor.
If you look closer, you’ll see that the “dome” is build out of little segments – each being a small plastic Fresnel Lens. These tiny lenses help the sensor to look “around” in one swoop, which would have been impossible with just the flat sensor (see figure 2).
A few points on the PCB of the PIR are of importance to us:
The most important pins are of course Power supply (Vcc 3 to 5 Volts – it is said that this can even be up to 12V) and GND (Ground).
The OUTPUT pin is the switching pin.
The two potentiometers (orange) allow you to tune Delay time (Tx) and Sensitivity (Sx).
Testing your PIR
If you’d like to experiment a little with your PIR, or test how well it works, then you actually do not even need an Arduino or Raspberry Pi.
All you need is either a power source, a resistor and a LED.
The power can be drawn from either batteries or a power supply – 3 to 9 Volts will work – I used a 5V USB charger.
For the LED, we need to pay attention, since it’s important that we connect the pins right. The longest pin of the LED (Anode, or “plus”) should be connected to the resistor, see the LED drawing below.
The resistor should be 470 Ohms, the colors are Yellow, Violet, and Brown (see also the Tweaking4All resistor calculator).
Connect the PIR Vcc pin to the + of your power source.
Connect the PIR Output pin to one end of the resistor.
Connect the other end of the resistor to the long leg (Anode) of the LED.
Connect the short leg of the LED (Cathode) to the − of your power source.
Connect the PIR GND to the − of your power source.
And that’s all … you should have something like this now:
Testing your PIR with a Battery, LED and a Resistor
p.s. I made this drawing with Fritzing, a great tool to make electronic design!
Playing with the “settings”
Now that we have a test setup, time to do some playing.
When the LED goes on, motion is detected.
In the beginning you might notice some seemingly erratic behavior – this is perfectly normal. We need to understand a few things before we can tweak the settings.
When connecting the battery, the sensor will take up to 30 to 60 seconds to stabilize (warm up).
Place your setup in such a way that there will be no motion and wait until the LED remains OFF.
Once the LED remains OFF, you can move your hand or anything for that matter, in front of the little dome, and see the LED go ON and OFF.
Depending on what is moving around, the detectable range should be up to 20 feet or about 6 meters.
Also keep in mind that the sensor will remain “ON” for a little bit after it detects motion. At a later time you can tune the timing with the “Delay Time” potentiometer.
The “Delay Time”, determines how long the PIR will keep the Output “High” (ON) after detecting motion.
For example, when motion has been detected, you could set this somewhere between a few seconds (mine has an approximately minimum delay time of 2 seconds) up to a few minutes (specifications of mine claim about 200 seconds).
When assembling the basic test setup (above) and the LED seems to stay on forever, turn this dial down – the delay might be too long. The lowest setting, when facing the philips screw of the potentiometer, is all the way to left.
When doing your first tests, turn it as low as possible … until you notice there is a need for a time delay.
With this potentiometer you can determine set the “range” you have in mind.
I have the impression that it regulates how much motion it takes to be “seen”, or maybe more technical terms: how much difference between the two “halves” of the sensor need to see before it’s considered motion.
You’ll have to play a little with this to see what is the appropriate setting for your purposes.
An increased sensitivity can be beneficial for when using a PIR for long range, say up to 20 feet (6 meters) or more. This can however also cause false positives in smaller spaces – i.e. the PIR might trigger when it should not.
A decreased sensitivity is good for a short range, say half of the maximum range or up to 10 feet (3 meters). Which in turn could miss movement at a longer range. Objects further away may need more motion to be detected.
To illustrate this, a little test …
First I did set the sensitivity to it’s lowest and walked 14 feet (app. 4 meters) away from the sensor. I had to wave both arms to get detection.
After that I did set sensitivity to it’s maximum setting and walked again 14 feet away from the sensor. No I pretty much only needed to move a finger to be detected.
Up to you to find what works best for your application of the PIR – with the test setup it’s easy to play and tune.
The Retrigger Jumper
On some PIR’s, they conveniently did not install the jumper (like in the ones I have) – this does not mean that they do not work. Just setting them is a little bit more cumbersome.
If your PIR does not have jumpers for this, and just soldering pads, then look closely and you might see that it’s default set to “H”. It took me a while to even see that mine was shorted to “H”.
The “L” setting seems to behave a little erratic – when you move in front of the PIR, you will see that it occasionally switches the LED ON and then OFF again. This is called “non-retriggering” – this setting does not or just barely retrigger.
When using the “H” (default) setting, you will see that the LED remains ON when moving in front of the PIR. This is what is called “retriggering” and it seems that this would be the most used setting as this seems to behave the nicest.
Additional Information Sources