Home-made PIR (PIC) detector from Arduino

    Bit of theory


    To begin with, I suggest you take a short tour of 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 themselves do not emit anything, that is, they work exclusively with their environment. By the way, the concept of "sensor" in the case of the entire device is not true. The device is called a detector, and the sensor is one of its components, a sensitive element.
    The core of the sensing element is a pyroelectric. This crystalline substance has a remarkable property - with increasing temperature, it polarizes and an electric field appears. The signal monotonically depends on the magnitude of the infrared radiation. So, I think for now, let's finish the theory. It's time to get down to business.

    Assembling the detector

    For work, we need any debug board with a microcontroller. Specifically, I used Arduino. Now, it remains only to get the sensitive element itself. I fell into my hands like this:

    image

    They cost about 2-3 dollars. The optical system (white cap) is immediately evident in the photo. On its surface are lenses focusing radiation from various points in space on a sensitive element. And, it turns out that when the intruder moves past the detector, the radiation from it will fall on various segments of the cap and will be focused several times on pyroelectric. Such a scheme is used to reduce the number of false positives.
    In addition to the optical system, there is an output pulse former 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
    Supply voltage: 4.5 - 20V

    On the board there is a three-pin connector (PLS plug):
    "+" - power. In our case, 5V from the Arduino
    “OUT” board is the output signal (3V - Alarm, 0 - Everything is calm). Connect to connector A0
    "-" - common wire (GND)

    To check 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, since you can’t get a lot of current from the microcontroller. Specifically, I used the speaker from an old Soviet phone. However, you can do with one LED. In this case, it will only affect the entertainment.

    Programming


    It’s time to write a simple sketch: Let's go over the code a bit to understand the essence of what is happening: PIR - here we connect the “OUT” contact of the LED sensor - an LED on the Arduino board. We will turn it on during the alarm PING - port for the speaker. GND is the second speaker wire. One could just "plant" on the ground. I did so purely for reasons of convenience, so that both wires were close by.

    #define PIR 14
    #define LED 13
    #define PING 2
    #define GND 3

    void setup()
    {
    Serial.begin(9600);
    pinMode(PIR,INPUT);
    pinMode(LED,OUTPUT);
    pinMode(PING,OUTPUT);
    pinMode(GND,OUTPUT);
    digitalWrite(GND,LOW);
    }

    void loop()
    {
    if(analogRead(PIR)>=500)
    {
    digitalWrite(LED,HIGH);
    ping(500);
    }
    else
    digitalWrite(LED,LOW);
    }

    void ping(unsigned int freq)
    {
    long t = 500000/freq;
    digitalWrite(PING,HIGH);
    delayMicroseconds(t);
    digitalWrite(PING,LOW);
    delayMicroseconds(t);
    }









    Further, as you probably already understood, the output signal from the sensor is sent to the Arduino analog port. There it is digitized and if the signal exceeds the value of 500 (~ 2.5V), this signals an 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 - close enough to the border between zero and a unit of TTL - logic, and therefore reinsured.
    So, if the sensor reports an alarm, then turn on the LED and signal the speaker. The ping () function generates a square wave on the speaker. 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 detectors in the apartment that will communicate their status via radio channel to a certain central unit. In general, it all depends on your imagination.
    Well, I will end with my review. I hope it turned out to be interesting and useful. I will be glad for your comments and remarks.

    Also popular now: