For a start, I suggest you make a small digression on the theory. What is a pic? It stands for “Passive Infrared Detector”. He is a motion sensor. Perhaps the very first question will be: “why passive?”. This term has no relation to laziness or sexual orientation. “Passive” are sensors that emit nothing, that is, they work exclusively with their environment. By the way, the concept of "sensor" in the case of the whole instrument is not true. The device is called the detector, and the sensor is one of its components, the sensitive element. The core of the sensing element is pyroelectric. This crystalline substance has a remarkable property - as the temperature rises, it becomes polarized and an electric field appears. The signal is monotonically dependent on the amount of IR radiation. So, I think for now let's finish with the theory. It's time to get down to business.
We collect the detector
For work we need any debug board with a microcontroller. Specifically, I used Arduino. Now, it remains only to get the sensor itself. In my hands I got this: ')
They cost about 2-3 dollars. The photo immediately catches the eye optical system (white cap). On its surface there are lenses focusing radiation from various points of space on the sensitive element. And, it turns out that when the intruder moves past the detector, the radiation from it will hit different segments of the cap and will be focused several times on the pyroelectric. This scheme is used to reduce the number of false positives. In addition to the optical system, there is an output pulse shaper on the board, as well as a potentiometer with which its duration is regulated.
Specifically, my device has the following characteristics: Viewing angle: 100 degrees Range: 7 meters Power supply: 4.5 - 20V
On the board there is a three-pin connector (PLS plug): "+" - food. In our case, 5V from the Arduino board “OUT” is the output signal (3V - Alarm, 0 - Everything is calm). We connect to the connector A0 "-" - common wire (GND)
To test the sensor, I came up with a simple algorithm. As soon as it “works”, the LED will light up, and an alarm will sound from the speaker. Then I completely forgot to mention that you will need some kind of speaker, preferably a high impedance one, since a large current cannot be obtained from the microcontroller. Specifically, I used the speaker from the old Soviet phone. However, you can do with one LED. In this case, it will only affect the entertainment.
Programming
It is time to write a simple sketch:
#define PIR 14 #define LED 13 #define PING 2 #define GND 3
void ping(unsigned int freq) { long t = 500000/freq; digitalWrite(PING,HIGH); delayMicroseconds(t); digitalWrite(PING,LOW); delayMicroseconds(t); }
Let's go over the code a bit to understand the essence of what is happening: PIR - here we connect the contact “OUT” of the sensor LED - LED on the Arduino board. We will include it during the alarm PING - port for the speaker. GND is the second speaker wire. One could just “plant” on the ground. I did it purely for reasons of convenience, so that both wires were nearby.
Further, as you probably already understood, the output signal from the sensor goes to the analog port of the Arduino. There it is digitized and if the signal exceeds the value of 500 (~ 2.5V), it signals the alarm. In fact, you can connect the sensor to any digital port and wait for a logical unit. This step was taken to increase reliability (if the signal level from the sensor is less than 3 volts, unstable, or something else). 3 volts is close enough to the border between zero and a TTL unit of logic, that's why it was reinsured. So, if the sensor reports an alarm, then turn on the LED and signal the speaker. The ping () function generates rectangular oscillations on the dynamics. The frequency is chosen to taste.
And now the video with the result:
Low price and simplicity make PIR sensors quite attractive. The first thing that comes to mind is to install home-made announcers around the apartment that will communicate their status to a certain central unit via radio. In general, it all depends on your imagination. Well, I'll finish my review on this. I hope it turned out interesting and useful. I will be glad to your comments and comments.