Designing an ultra low power PIR sensor

Prithvi Raj Narendra
Appiko
Published in
9 min readApr 20, 2020

Processor wakes up only on motion detection

SensePi motion sensor

A Passive Infrared (PIR) sensor detects movement of heat. They are typically used to detect movement of humans and other warm blooded animals. This article at Adafruit explain quite well how PIR sensors work. For this article we need to know that the PIR sensor provides an analog output AC signal of about 1mV peak to peak over a constant offset voltage in the range of 0.6 to 1V. This minute analog signal needs to be processed and digitized for a usual widget to perform appropriate action.

PIR sensor operation (source: Adafruit- how PIRs work)

Need for PIR sensor

Low cost & Low current draw

The primary advantages of a PIR sensor are their low cost and low current consumption. This way they are a common sensor used for non-critical detection of human presence, especially in areas where there is sporadic movement such as corridors and toilets. Also PIR sensors are the most common means of detecting animals in camera traps to automatically capture images and videos of them in the wilderness. We developed SensePi — a motion sensor for a DSLR camera trap using a PIR sensor. Cost, reliability and power consumption were key considerations when building this part of the system.

Basic architecture

For a PIR sensing system can be divided into three generic parts

PIR sensor →Signal processing →Digitization of the signal

The PIR sensor circuitry is quite simple and is specified in most of the datasheet of available sensors. It consists of a resistor between the OUT and GND pin to form a source follower voltage buffer circuity with the JFET in the PIR sensor. A resistor of about 50k is recommended, though a higher value will provide lower power consumption at the expense of lower sensitivity and higher noise. Some of the common PIR sensors are LHI968, D204B and KP506B. The performance of these were quite similar.

The objective of the signal processing circuitry is to

  1. Amplify the signal from ~1 mV to 100s of mV. This is so that the processed signal covers a significant range of the Analog to Digital Conversion (ADC) done after processing.
  2. Bandpass the signal to only allow the desired frequency of signal to the ADC. In case of detecting walking humans and animals, the signal from the PIR depends on the lens used, walking speed and distance from the sensor. In most cases it won’t exceed 10 Hz, so we can use a low pass filter with this cut off.
  3. Move the offset voltage of the PIR signal. As mentioned earlier, the PIR output is a tiny signal on top of a constant offset. This constant offset is not consistent across different PIR sensors, even across individual units. So what we would like is to extract amplify and bandpass is changing signal and offset it with a constant voltage. This we have chosen as half of the supply voltage so that the signal has maximum room before it hits the rails of the supply voltage or ground.

The last part of the PIR sensing circuitry is the digitization of the processed analog signal. We need to make sure that we capture the AC part of the signal over the offset voltage that we added in the processing section. This will provide a sense of the amplitude of the signal from the PIR sensor and will help in making a decision to take appropriate action for the microcontroller.

Hardware

In this section we describe the circuitry of the SensePi’s PIR motion sensing section . You can find the entire schematic here. The design was done with KiCad, a cross-platform and open source electronics design automation suite. At the core of the circuit is a nRF52810, a ARM cortex M4 based System on Chip (SoC) that contains a 2.4 GHz radio peripheral capable of Bluetooth Low Energy (BLE).

Power supply with reverse voltage protection

The power supply is two AA batteries. This provides a clean and stable supply for the noise sensitive design.

PIR sensor circuitry

Starting off with the PIR IC itself, its circuitry is quite simple. There’s a 47k resistor for biasing the PIR sensor and a buffering 100 nF cap. The connector is to inject a known test signal before soldering the PIR sensor during board level testing, which we have described here.

The output of the PIR sensor is passed to a two stage band pass amplifier. This architecture as well as working of PIR sensors is described in this application note by ST Microelectronics. The setting of the band pass cut off voltages as well as the working of the circuirty is explained in this app note. TLV8802 used in this design or TLV522 for even cheaper OpAmps are great choices for this design due to their appropriate specs, current consumption in nA and cost cost.

First stage — vanilla band pass filter

The first stage of the band pass amplifier is as per the application note by ST, it takes in the PIR sensor output, amplifies and band pass filters it. The gain of this stage is (1+1500k/33k), which is 46.45.

The second stage is more modified from the application note. First, a digitally controlled resistor (programmable rheostat) is added in series between the two stages. This is added primarily to enable the change of the gain of the second stage by software. A side effect is the high pass filter section of the band pass filter has a variable cut-off frequency, though it won’t matter for this design the exact value. The resistor can be set in software from a min value of about 100s of Ohm to 50k, changing the gain from about 90 to 23 respectively. Also to reuse the 33k resistor, two of them were used in parallel to get an appropriate value to be in series with the rheostat.

Second stage of the signal processing chain with programmable gain

The second stage also changes the offset voltage of the signal to half of supply voltage. This is done by providing this reference voltage to the +ve terminal of the OPAMP from a voltage divider. Since the input impedance of an OPAMP is in the order of 10s of Mega Ohms, a high value like 1.5M can be used for a voltage divider to generate this reference voltage and thus reduce the power consumption.

The graph below shows the output of the first and second stages. The first stage has small amplification of the AC signal of the PIR sensor and is around the same offset voltage as the PIR sensor, which is around 1V in this graph. In the output of the second stage one can clearly see the peaking of the signal when there is movement as indicated in the graph. Also the DC offset of the second stage is mid supply voltage, which as you can see in the graph can provide enough room to hit either the supply voltage or ground during motion detection.

Graph of the output of the first and second stage from ST’s application note ‘Signal conditioning for PIR sensor

The next section of the signal processing circuitry is inspired from an application note by TI. As you can see the PIR interface to the differential ADC in a MSP430 microcontroller is through two RC low pass filters without any additional amplifying active blocks. This usage of the differential ADC provides signed output at the ADC depending on whether the signal is above or below the offset voltage and removes the need to think of the offset voltage when writing code. Our testing didn’t provide reliable results without the amplifying the PIR signal and using only the 4 gain in the differential ADC of nRF52810. So we added the two stage amplification with the programmable gain with the two RC low pass filters at the end to provide the signals to the two inputs of a differential ADC of nRF52810. Make sure that the microcontroller chosen has a differential ADC before moving this design to a different platform.

Software

In the TI application note, the MSP430 wakes up two times from sleep for every ADC sample — one for starting the ADC conversion and one for checking the sampled ADC value.

Peripherals wake the processor only on detecting motion

For minimal power consumption from the processor part of the circuitry our intention was to make sure that there is minimal processor activity for sensing motion from PIR signal. As mentioned earlier, the nRF52 based SoC is the platform for SensePi. We used a feature called Programmable Peripheral Interconnect (PPI) to achieve this goal reducing the involvement of processor for capturing the ADC value and comparing it against threshold. PPI can start a task on a peripheral based on an event generated from any peripheral in the SoC without the involvement of the processor. Also another feature that came handy was the limit monitoring in the ADC, where a high and low limit can be specified and if a sampled value crosses this threshold, only then an interrupt is generated to wake the processor. Using these two features with a low power 32.768 kHz timer (RTC), the sampling of the processed PIR signal was completely processor independent until it crossed the specified threshold.

Software flow for processor independent ADC sampling for PIR sensing

The timer period set is for 40 ms to do an ADC sampling. When this count is reached by the timer, a compare event is generated. Using PPI, on this event we clear the timer to start the count again and enable the ADC. When the ADC is powered on, again using PPI we start an analog to digital conversion. On finishing ADC sampling the PPI is again used to disable the ADC. The processor is woken up by an interrupt only when a sampled value crosses the set limit on ADC. Since it is a differential sample, the value can be positive or negative, so the limit too is a positive and a negative one. The code for this implementation can be found here in our nRF52 codebase repository.

Results

The entire circuitry was powered with a supply of 2.6V from two AA rechargable NiMH batteries. The current consumption of the entire circuitry was about 18 uA when there is no motion to trigger ADC interrupt. When there was motion and the processor was woken up once a second the current consumption rose to about 21 uA. This enables multi year battery life from the PIR motion sensor when always sensing.

This architecture provides two means of configuring the sensitivity of the motion sensor, namely the programmable gain of the second stage of the band pass amplifier and the threshold limit set in the ADC.

The power supply rejection of this circuitry is quite bad, so one needs to be aware of this with this design. We could see this play out when we blinked simple red LED from a GPIO of the SoC, the output of the second stage amplifier had large pulses at its output when the LED turned on and off due to the few mA current draw of the LED.

Possible improvements

Keep a low threshold and high gain so that the processor wakes up early in the movement, so start capturing the processed signal. This will cause a lot more waking up of the processor but with appropriate algorithms to process the captured signal, the false positives, especially due to sunlight hitting the lens of the PIR sensor can be reduced or removed.

The algorithm to be used is to be figured out. A possible way is to keep logging the output of the PIR sensor along with a video recording of what it is seeing. This way it is straight forward to visualize the kind of signals produced for different situations i.e. various environments, various movements of humans and animals.

The labeled data produced from the above exercise would be interesting to be used with Machine Learning, especially with TinyML to see how effective it is in various parameters such as latency, power consumption and reliability.

--

--