Sunday, October 11, 2020

How an outdoor motion PIR sensor switch works with schematic

In this article I will be explaining how a pyroelectric (PIR) sensor works and show the reverse engineered schematic simulated in LTspice. The schematic is for NV-1111.35 outdoor PIR sensor used to switch a mains light and has 3 potentiometers for setting SENSITIVITY, LUX and TIMEOUT.

This sensor is based on a popular three stage op-amp topology. Understanding this can help you understand other pyroelectric sensors as well and also something about active filters using LM324 and removing and setting a DC voltage bias.

Outdoor PIR sensor board repair

Outdoor PIR sensor board repair

 

How a PIR sensor work

This particular sensor board is using the D203S PIR sensor. Pyroelectric passive infrared (PIR) sensors detect infrared (IR) radiation. A warm object emits infrared energy that is not visible with a human eye. Since the purpose of the sensor is to detect motion not only heat, there are two parts sensitive to IR that look like two little windows or slots. 

D203S PIR sensor
The sensor window is actually split into two parts

This two elements are used in series with opposite polarity so the average radiation is cancelled out. When the sensor is idle both slots detect the same amount of IR so the ambient temperature won't trigger the sensor. If a warm body like a human or animal passes by the infrared energy it is first detected by an element then by the second one and so generating an AC signal. A mosfet is also included to buffer the weak signal produced by the PIR sensor.

PIR sensor elements polarity diagram
PIR sensor diagram

 
Principle of the PIR sensor movement detection
Image from AN4368 - Signal conditioning for pyroelectric passive infrared (PIR) sensors

The signal produced by the PIR sensor is around 1mVpp and it has a DC offset voltage that can vary from 0.3V to 1.2V. 

Fresnel lenses

In order for the sensor to cover a wide angle, Fresnel lenses are mounted in front of it. They are cleverly designed with many areas of Fresnel lenses arranged in a way so they can split the detection area into multiple sections. This for the sensor looks like it has not only two detection elements but many pairs of them. So even a small movement can trigger both elements.

PIR Fresnel lens diagram
Image from D203S datasheet

PIR sensor circuit explanation and schematic using the LM324N op-amp

Outdoor PIR sensor board repair

The board can be powered from 5V to 12V however the value of the components are designed for 8V to 12V. It can work on 5V but the voltage division created by R17 and R18 must be changed.

Power consumption is very low: 1.5-2mA.

Outdoor PIR sensor board repair
Parts of solder mask were burned due to the power board short-circuit but only the op-amp was damaged on the main board

Outdoor PIR sensor board schematic
Outdoor PIR sensor board schematic (click to enlarge)

This op-amp architecture consists of three stages.

Stage 1

The first architectural stage amplifies the signal. It cancels the DC part of the signal and filters the high frequency noise that could lead to false detections.

PIR sensor schematic - stage 1
 
The high frequencies are filtered by C4 and R4 and the cut-off frequency is 2.2 Hz (fhigh1 = 1 / (2 x pi x R4 x C4)).
The second filter is used to reject the DC part of the signal. C1 and R3 perform a high pass filter that has a cut-off frequency of 0.34 Hz (flow1 = 1 / (2 x pi x R3 x C1)).
The stage gain is 221 (Gain = 1 + (R4 / R3)). The gain must be high enough to amplify the sensor signal above the noise level but not too high to drive the op-amp into saturation. The amplification is made around a common mode voltage set by the sensor and is not VCC / 2. 
 

Stage 2 - Setting PIR sensor sensitivity

 
Stage 2 is very similar to stage 1. It is used to filter and amplify the AC signal except that this time the signal is inverted.
PIR sensor schematic - stage 2

The signal Vout1 from stage 1 enters stage 2 through a 10k potentiometer that is used to set the sensitivity of the PIR sensor so it does not trigger every time a dog passes by.
Regarding the filtering function, the low and high cut-off frequencies respectively are 0.72 Hz (flow2 = 1 / (2 x π x R6 x C5)) and 4.8 Hz (fhigh2 = 1 / (2 x π x R10 x C6)). The flow2 also depends on the potentiometer position.
The gain of this stage is -100 (minus represents the inverted signal) (Gain2 = -R10/R6). This gain means that after stage 2 the signal between 0.7 Hz and 4.8 Hz will have been amplified 22100 times (87 dB).
In this stage the op-amp common mode voltage is set by the resistors R12, R9 and R8 to 37% of the power supply (Ratio = R8 / (R12 + R9 + R8)). The gain is intentionally set high so the signal is clipping looking more like a square wave now.

Stage 3 - Setting PIR sensor timeout and light threshold


PIR sensor schematic - stage 3

In this last stage 3 the signal from stage 2 is again inverted and filtered by the R11 and C7 with a 3.38 Hz cut-off frequency but this time the last two op-amp are used mostly as comparators. The non-inverting input is set by R12, R9 and R8 at 44% of VCC, one diode voltage drop above the ratio in stage 2.
The R16 potentiometer together with the LDR controls at what light intensity the sensor will trigger. The more light the lower the resistance of the LDR will be and if the pot is lower the base of Q1 will be pulled low turning off the transistor and R13 will let the diode D1 conducting the sensor signal to ground. If the potentiometer is on the other side even if the LDR would have 0 resistance the 150k of the pot would make the Q1 turn on then R13 will develop a voltage drop of VCC / 2 which is higher than the output voltage from stage 2 and the sensor will trigger. 
 
The last op-amp has the non-inverting input set at 83% of VCC. When no movement is detected Vout3 is always high and so the inverting pin of U1.4 is higher than (+) pin making the output to relay low. When Vout3 is low the negative plate of C8 is pulled to ground and so (-) pin is lower than (+) pin making the output high turning on the transistor that controls the power relay. Now even if Vout3 will be a very short pulse or the sensor will detect movement multiple times, the output will still remain high. If Vout 3 will keep going low to to motion detection the timeout will be reset but the relay will remain on. So when Vout3 remains high the capacitor C8 will be charged through R20 and the pot R19 that sets the timeout.
This method of using a capacitor was new to me and it took me a while to understand it. after the C8 charges to almost VCC the (-) pin will be higher than (+) and the output will go low turning off the relay. 
 
PIR sensor signal conditioning
PIR sensor signal conditioning ploted in LTspice

The schematic was simulated in LTspice. In the first plot there is Vpir that represents the 1mV signal from the sensor around 500mV offset voltage.
In the second plot Vout1 is the amplified signal after stage 1.
Vout2 is the output from stage 2. Here the signal is inverted, amplified to the maximum op-amp output and the offset voltage is set to 2.96 V at 8V power supply.
Vout3 is the output from stage 3 and is normally high. When motion is detected and signal Vout2 is higher than 3.55V then Vout3 will go low. Notice that it only uses the second half of the PIR signal pulse.
Finally Vrelay goes high when Vout3 is low. It will remain high even if Vout3 will change states again. If Vout3 remains stable at a high level then Vrelay will remain high depending on the RC constant set by C8, R20 and potentiometer R19. 
 
PIR sensor LTspice simulation
PIR sensor simulated in LTspice

In the next tutorial I will be presenting the capacitive power supply.

Download


16 comments:

  1. Süper bir calişma ..sürekli yazinizi okuyorum. ve bu devreyi yapmak.

    ReplyDelete
  2. Sevgili arkadaşim.
    5v veya 12v için R17 ve R18 nasil ayarlanir. Ögrenmek istiyorum. Formul nedir.
    nasil deneme yapilir.

    ReplyDelete
    Replies
    1. Try and swap the values. Make R18 100k and R17 20k. At lower voltages the non-inverting pin of the op-amp will always be higher than the inverting pin, making the signal to the relay always high. Hope it helps.

      Delete
    2. I have linked at the end of the page the LTSpice simulation and the PCB in DipTrace if you need them.

      Delete
  3. Teşekkür ederim.ilginiz için

    ReplyDelete
  4. Hi, thanks for your content.
    I will to remove sensitivity pot for my schematic.
    what is the equivalent circuit?

    ReplyDelete
    Replies
    1. The pot can be replaced by a fixed resistor. You can find the redraw schematic at this link https://drive.google.com/file/d/1yL3QXjgciPmGxRemkGyJxisyB-IQ2p_x/view?usp=sharing

      The resistor can be any value between 0 and 10k. I would try a 2.2k or 4.7k. The higher the value the lower the sensitivity if I remember correctly.

      Delete
  5. I tried to get result but faild.
    it blinks.
    2 sec off and about 3 sec on.

    ReplyDelete
    Replies
    1. Try with a 10k resistor maybe it's too sensitive and also check the connections. Connect the node where the pot wiper was to the junction between the new resistor and the pulldown resistor. I did fix one like that that had a broken pot and it works very well.

      Delete
    2. Also check the timeout pot if the timeout is not too short

      Delete
  6. Hi. Thanks for an excellent article. I have one of these pir circuits which is misbehaving. As soon as the last stage times out, the relay goes off for almost a second and then goes on. You can hear the relay ticking for a second. In effect, the relay almost always remains on. Appreciate your reply.

    ReplyDelete
    Replies
    1. Hi. Hope I can help but the potential problems could be many. My first step in troubleshooting a circuit is to first examine with a magnifying glass if for shorts, smoke or bad solder joints. If I remember correctly that was also my issue. The voltage on the (-) pin of the last op-amp #4 would not go higher than the voltage of the (+) pin so the output of the op-amp would be always high. I remember that I had to change the op-amp but I think because of other issues, then I lowered the value of resistor R17 in the voltage divider to get a lower voltage on the (+) pin so the (-) pin can go higher. I would also check the timing capacitor and potentiometer off circuit. Good luck.

      Delete
  7. Yes. By removing the LDR the sensor should work at night and during the day as well.

    ReplyDelete
  8. Hi, Thank you for an interesting functional explanation. I have a need to extend he timeout and keep the power relay on for a longer time. Could you please explain the easiest way to increase the timeout time to about the double from the present value.

    ReplyDelete
    Replies
    1. It's easy. Replace the timing potentiometer (R19 in stage 3) with a fixed resistor with a larger value. If the potentiometer is 2M use a 4M resistor or multiple is series if you don't have one that large.

      Delete