A PIR is what we normally call a movement detection sensor. You can find it in all kinds of security devices but also in the lamp that switches automatically on when you approach it. The official name is Passive Infra-Red sensor.
I ordered some PIR's from a chinese supplier just for testing purposes and maybe some fun projects. And I have this vague idea to incorporate it in my domotics system.
So before I start serious work with it I needed to test it to see how a PIR functions.
The above picture shows you first the actual sensor. But this is not how we see it. The sensor is incapsulated in a plastic lens. A so called fresnel lens. This is the familiar white bulb you can see in the first picture in this story. This plastic white bulb has, as you can see, several sections. These are designed in such a way that the sensor will get information from a very wide angle and range.
In reality there are 2 infra-red detectors (within the same sensor) placed next to each other. Placed in front of it is the lens. The two infra red sensors get the same information but when something in a room moves one sensor gets different information than the other one and that triggers the PIR.
The PIR has 3 connections Ground, VCC and Signal. It is recommended that tthe power supply does not exceed 6 volts. Your specifications might vary however. If there is no information available I suggest to hold on to this golden rule.
The PIR operates at 5 Volts. This is fine for Arduino projects but makes it a bit more difficult in ESP8266 projects. Naturally I tried to operate the PIR at 3 volts and you can really forget it. It just will not work.
First lets look on how the PIR will be connected.
Well actually there are a few models PIR out in the wild and it seems that they have different connections.
If you look at the image above you can see that in my particular case the VCC is on the left connection, the SIGNAL in the middle (I isolated it with some tape) and the GND on the right connection. But please examine your PIR closely to see if your connections are likewise.
I have seen designs on which VCC and GND were exchanged and I even have seen a version on which the SIGNAL lead was on the left connection (seems to be the Parallax brand version). So please check your PIR closely.
Fortunately the PIR has a safety diode which prevents harmfull connections. Off course: CHECK yours might be different.
And there is an extra option for the really adventurous amongst us.
So any of you feeling lucky you may surpass that controller and feed it with 3 Volts. This will make experimenting with an ESP8266 easier, however I am not advocating this and will not go into details about this. Do this on your own risk.
Take it slowly.
My first impression was that the PIR was not working. I could not get a meaningfull read-out.
What I did was to attach te PIR to a battery setup and used my Multimeter to read the signal. And all I got was gibberish.
Well in the end it occurred to me that the PIR has to settle first before you will get meaningfull results. And that settling takes with my version about a minute.
So when you Power up your PIR you'll have to wait a minute before you will get meaningfull results.
Next step is to set the sensitivity.
The PIR has 2 potentiometers which you need to tweak for finding your optimum settings.
Looking at the top side of the PIR the right potmeter adjusts sensitivity, and the left potmeter duration. Again: this might be different with your version so test it.
Look at my settings. The right potmeter is turned to it atmost left position. This gives the highest sensitivity. This means that the PIR will detect movenment from a few centimeters away to a few meters.
You will have to determine that exact maximum distance in you particular case as it may vary. The specs I have found on the internet stated that the maximum distance can be as much as 6 meter. However do not take my word for it and experiment.
The left potmeter determines how long the SIGNAL line will be in the HIGH state when movement has been detected and how long it will be off.
As you can see I have turned it to the atmost right position.
When movement is detected the Signal will go HIGH for about 6 seconds, and then it will turn off again for about 6 seconds and then looks for movement again.
If the person in the room keeps moving the SIGNAL will remain HIGH and only gets LOW when no movement is detected again.
In it's most simple form a setup for testing can be as the next breadboard setup and schematics show you.
Unfortunately I have not found a Fritzing part for just 3xAA batteries so I had to use the 4xAA version. But as you can see from my setup I just used 3AA batteries which supply about 4.5 Volts which is enough for the PIR to work.
As you can see I printed my own battery case. The connectors were made from paperclips just as described in this story (click here).
Those that want to print their own battery case can find the STL files in my Github repositry by clicking here.
So what happens is as follows.
As soon as the PIR notice some movement the led lights up ans stays on for about 6 seconds. After that, if no mevement is detected, the led goes out and satys out for another 6 seconds after which it will look for movement again.
If movement is detected and the person keeps moving the led stays on.
What can we do with it.
The easiest step is to attach a relay to the PIR and connect a lamp. This way the lamp will go on as soon as movement is detected. A very easy setup that can be bought in many DIY stores as a burglar alarm or just a device to make it easy to find your keyhole in the dark.
Another example is attaching the PIR to a photocam. Place the setup at a bird (fill in: deer, wild boar etc) feeding place to make pictures at the right moment.
Attach a PIR with a relay to your garden sprinkler installation to scare the shit out off cats/kids/mailmen trespassing your garden.
And by attaching the PIR to an ESP82566 a whole lot of projects come to mind. For example a burglar alarm which sends notice to your phone, or a mailbox alarm which notifies you if you got mail. And off course the obvious domotics application that turns on the lights in a room but only when it is dark AND a peron is in the room.
Just use your imagination.
In a follow up story I will be discussing the attachment of a PIR to an ESP8266.
Till then: Have fun