Using PIR Sensors for Motion Detection

Motion detection is used in a variety of applications and (lucky for us!) is relatively easy to implement in your next project using PIR motion sensors. Whether you are building on an Arduino board or you are designing your own PCB, PIR sensors are easy to incorporate. Some applications include power switches for electromechanical systems (think automatic sliding doors) or proximity sensors for alarm and lighting systems.

How Does a PIR Sensor Work?

shutterstock_1476976379

When a warm body moves in front of a PIR sensor, the sensor generates a differential voltage. Each PIR sensor unit consists of two individual infrared-sensitive halves. As the radiating body (a person in our case) moves in front of the sensor, one sensor will be crossed before the other. For this short duration, the first sensor will capture a larger amount of radiation than its counterpart, creating a positive differential voltage. Similarly, while leaving a PIR motion sensor’s field of view, one sensor will continue to receive more radiation, resulting in a negative differential voltage.

Difference in motion detection for single and dual modes of the PIR sensor
Principle behind the motion detection using PIR sensor. [Source: 
Adafruit]

PIR motion sensors usually come in a three-pin package with VDD, GROUND, and SIGNAL pins. The supply voltage typically ranges from 3 to 5 V, although it can reach as high as 12 V in some sensors. Although the sensor itself is essentially a pair of photodiodes and a transistor, the dome-shaped packaging for an integrated sensor can be rather large. The dome on a PIR sensor acts as a Fresnel or plano-convex lens, which focuses infrared light on a back-to-back photodiode. This photodiode arrangement can then connect to the gate on a transistor, providing a digital output.

The digital output is active high and can drive a load up to 10 mA (always check the datasheet!). In most cases this pin can be connected to a microcontroller input, but you should cross-check your datasheets as this pin may be open-collector, which requires placing a pull-up resistor on this pin. There is a PIR sensor available at SparkFun that has a fourth pin which supplies the analog output from the PIR sensor. This provides additional flexibility for using and analyzing the PIR output.

Difference in motion detection for single and dual modes of the PIR sensor
PIR motion sensor for Arduino projects or similar projects

Designing a Custom PIR Motion Sensor

If you’re a serious electro-optical designer and you’re looking to build a custom PIR motion sensor, you’ll have plenty of fun building your own PCB for a custom PIR sensor. The layout for a PIR motion sensor on a custom board is not difficult as it only requires two detectors, a transistor, and some resistors. The signal conditioning, delay, and sensitivity are controlled with an integrated PIR controller. The real fun is in designing the optics, but you can reuse a dome from a different PIR motion sensor module.

PIR sensor modules usually have two trimming potentiometers on the backside that can be used to customize the behavior of the motion sensor. The sensitivity trimpot can be used to change the detection range of the PIR sensor. The second is an OSC trimpot which controls the length of time the digital output stays high (i.e., the delay time). The pulse width of the output can be anywhere between hundreds of milliseconds to a few seconds.

Using the Digital Output

Most PIR sensors are 3-pin designs that produce a digital output. This sensor produces a pulse when motion is detected, which is then captured with a PIR controller and processed. There are two possible trigger modes for the digital output. The first is single pulse mode detection, where you can detect an object that enters or leaves the PIR’s field of view, and the second is a dual pulse mode detection where you can distinguish objects entering and leaving the field of view. The modes can be easily selected in your PIR motion sensor controller. Figure below shows both the modes of a PIR sensor for the NCS36000DG PIR controller from ON Semiconductor.

Difference in motion detection for single and dual modes with PIR motion sensorsSingle and dual pulse modes for PIR motion sensors. [Source: ON Semiconductor]

Using the Analog Output

The analog output from a PIR can provide a huge amount of information. Theoretically, multiple sensors could be used to determine the dimensions, speed, distance, and direction of the object. The figure shown below is from Arduino serial plotter, where the correlation between the hand motion and the output can be easily seen.

Motion detection using the analog output from PIR motion sensors
Analog output from a PIR motion sensor showing various hand movements. [Source: 
SparkFun]

The downside of using the analog output is the additional signal processing requirements. It is easy to view the signal on a serial plotter and process it in MATLAB or another program, but doing so on hardware adds significant complexity to your project.

Implementing a Prepackaged PIR Motion Sensor Module

One simply method to configure a prepackaged PIR sensor is to connect it to a battery and drive a simple LED with the sensor’s output pin, as shown here. This arrangement works well for testing the delay and sensitivity of your system. However, you normally want to use the digital or analog output to perform another set of tasks. In this case it makes more sense to use a PIR motion sensor with a microcontroller. Arduino or another development board, and some open-source code for your project, provide a good starting point for testing your prototype. It can also be used to drive and store the output signal from the PIR motion sensor.

Simple motion detector using Arduino and PIR sensorSet-up for a simple motion detector using Arduino UNO and a prepackaged PIR motion sensor. [Source]

You can find details of the implementation and the Arduino code here. One important thing to note at this point is that the PIR sensor takes up larger current when detecting the motion. The sensor from SparkFun (here) runs at approximately 3 mA while detecting motion and 80 uA during standby. If you have a more complex system with multiple sensors, this would be the time to start thinking about managing battery life.

A simple trick to reduce the current in a prepackaged PIR module is to remove the LED from the backside. The job of this LED is to simply tell you that sensor is ready, and this LED will blink every time motion is detected. You can pull out the LED once you have thoroughly tested and calibrated your PIR board.

Using Upverter to Design a PIR Motion Detection System

Whether you are designing a custom PIR motion sensor module, or you are purchasing one on the market, you’ll want to make a system that contains all the required sensors, microcontroller, power source, and some output module. The output module will be based on what you wish to do with motion detection. Some common examples can be triggering a relay to run a motor, sending data to the cloud (e.g., when counting the number of people crossing the sensor), or simply switch other devices on and off.

You can sign up for free and get access to the best browser-based PCB editor, schematic editor, and component database. Visit Upverter today to learn more.

IoT Solutions For Monitoring Workplace Safety And Health
UR32