PIR Sensor for People Counting: Techniques and Algorithms

Introduction

Counting people entering and exiting a space is valuable for retail analytics, building occupancy management, and security. While cameras are common, PIR sensors offer a privacy-preserving alternative.

Challenges of People Counting with PIR

  • Single sensor cannot determine direction (entry vs. exit).
  • Multiple people walking together appear as one event.
  • Sensor has gaps in coverage.
  • Signal varies with walking speed and direction.

Method 1: Dual-Sensor Direction Detection

Two PIR sensors placed side by side with overlapping fields. The order of triggering indicates direction:

  • Sensor A then Sensor B: moving in one direction (e.g., entry).
  • Sensor B then Sensor A: opposite direction (exit).

This is the most common and reliable method for counting at doorways.

Implementation

if (sensorA.triggered() && !sensorB.triggered()) {
    lastTrigger = A;
    triggerTimeA = millis();
}
if (sensorB.triggered() && !sensorA.triggered()) {
    if (lastTrigger == A && (millis() - triggerTimeA) < maxDelay) {
        if (directionFlag) count++; else count--;
    }
    lastTrigger = B;
}

Method 2: Single Sensor with Special Lens

A single sensor with a specialized lens that creates two separate detection zones can sometimes indicate direction based on signal pattern. This is less reliable.

Method 3: Sensor Array (2×2)

Four sensors arranged in a square can track movement across quadrants, enabling more sophisticated counting and even tracking.

Method 4: Machine Learning on Analog Signal

With a single analog sensor, researchers have used neural networks to classify patterns and estimate the number of people. This requires extensive training data.

Signal Features for ML

  • Peak amplitude.
  • Pulse width.
  • Time between pulses.
  • Zero-crossing rate.
  • Energy in frequency bands.

Commercial People Counters Using PIR

  • SensMax People Counter: Uses dual PIR sensors.
  • Echoflex Occupancy Sensor: PIR array.
  • Irisys: Uses thermal array (not PIR).

Accuracy Expectations

With dual sensors in a controlled doorway, accuracy can exceed 95%. In open spaces with multiple people, accuracy drops significantly.

Calibration

Counting systems need calibration for the specific installation:

  1. Measure sensor placement and field overlap.
  2. Set time windows for direction determination.
  3. Test with known counts and adjust thresholds.

Conclusion

People counting with PIR is feasible and privacy-friendly. Dual-sensor direction detection is the most practical approach for most applications.

Leave a Reply

Your email address will not be published. Required fields are marked *