If you are building a motion sensor circuit for an ESP32 or Arduino, the default choice for reliable indoor presence detection is the HLK-LD2410 mmWave radar module. While legacy PIR (Passive Infrared) sensors like the HC-SR501 are cheaper and adequate for basic hallway lighting, they fail completely at detecting static human presence (like someone reading on a couch). This guide breaks down the exact wiring, output signal math, and interference mitigation for both technologies so you can wire the right sensor for your application without a second trip to the parts bin.

The Physics: PIR vs. Microwave Sensing Principles

Passive Infrared (PIR) sensors detect motion by measuring changes in infrared radiation (specifically in the 8-14 μm wavelength band) emitted by warm bodies. The core component is a pyroelectric crystal (usually an RE200B) paired with a Fresnel lens that chops the field of view into discrete zones. When a heat source crosses from one zone to another, the crystal generates a microvolt-level AC charge. PIR strictly requires lateral movement across these zones; if a person sits perfectly still, the thermal gradient stabilizes, and the sensor registers the room as empty.

Microwave and mmWave radar sensors, like the 24GHz HLK-LD2410, operate on Frequency-Modulated Continuous Wave (FMCW) and Doppler principles. The module transmits a continuous radio wave and measures the phase shift and frequency change of the reflected signal. Because 24GHz waves can detect micro-movements down to fractions of a millimeter, these sensors easily detect the mechanical expansion of a human chest cavity during breathing. This allows mmWave circuits to report static presence, exact distance, and even target velocity, entirely independent of ambient temperature or lateral movement.

Wiring and Pinout: Supply Ranges and Logic Levels

A common mistake in motion sensor circuit design is mismatching the logic level to the microcontroller. The ESP32 is strictly 3.3V tolerant on its GPIO pins, while many legacy PIR modules output 5V. Below is the spec-sheet-table for the most common hobbyist modules.

Module Core IC / Tech Supply (VCC) Logic Output Interface
HC-SR501 BISS0001 (PIR) 4.5V - 20V ~3.3V or 5V (depends on VCC) Digital GPIO
AM312 Integrated PIR 2.7V - 12V 3.3V (Native) Digital GPIO
RCWL-0516 Microwave Doppler 4.0V - 28V 3.3V / 5V Digital GPIO
HLK-LD2410 24GHz mmWave Radar 5.0V (via Type-C or pins) 3.3V UART UART (TX/RX)
Bench Tip: If you must use an HC-SR501 with an ESP32, do not power the PIR module with 3.3V; it will brownout and trigger false positives. Power it with 5V, but place a bidirectional logic level converter (like a BSS138 MOSFET board) or a simple 1kΩ/2kΩ voltage divider on the OUT pin before it hits your ESP32 GPIO.

Output Signal Math: From Raw Data to Physical Units

It is critical not to conflate analog and digital outputs. Standard hobby PIR modules output a digital push-pull signal (HIGH/LOW), while mmWave modules output serial UART data frames containing parsed physical units.

PIR Internal Comparator Math (HC-SR501)

The raw output of the pyroelectric sensor is an analog AC signal in the range of 10-50 μV. The BISS0001 IC amplifies this and feeds it into an internal comparator. The reference voltage ($V_{ref}$) is hardcoded internally to $V_{DD} / 2$. The sensor triggers a digital HIGH only when the amplified signal peak exceeds this threshold. The duration of the digital HIGH pulse ($T_{delay}$) is governed by the RC network on pins 11 and 12 of the BISS0001:

T_delay ≈ 2.2 × R_pot × C_10

With the onboard ceramic capacitor $C_{10}$ typically at 104 (100nF) and the delay potentiometer maxing out at ~1MΩ, the output pulse width scales from roughly 0.3 seconds to 22 seconds. There is no 'distance' or 'velocity' unit here; the physical unit is strictly binary time-duration.

mmWave UART Parsing Math (HLK-LD2410)

The LD2410 outputs a 256kbps UART stream. To extract the physical distance in centimeters, you must parse the engineering-mode reporting frame. The target distance is stored in little-endian format across two specific bytes in the payload.

Distance_cm = (Frame_Byte[6] << 8) | Frame_Byte[5]

Furthermore, the sensor divides its detection field into 8 'gates' (each 0.75 meters wide). The raw gate energy (a value from 0-100) represents the reflection amplitude. If Gate 2 (1.5m - 2.25m) shows an energy spike of 85, you have a high-confidence physical mass at roughly 1.8 meters. For exact implementation, refer to the ESP-IDF UART documentation for configuring the hardware serial ring buffer to catch these 44-byte frames without dropping packets.

Interference, Calibration, and Failure Modes

Every sensor technology has specific environmental blind spots. Understanding these prevents the most common 'ghost trigger' support tickets in DIY smart home builds.

PIR Interference & Calibration

  • Thermal Masking: PIR sensors detect the delta between background and target. If your room ambient temperature rises to ~35°C (95°F), the delta between the room and a 37°C human body drops below the sensor's noise floor. The circuit will fail to trigger.
  • Optical Noise: Direct sunlight hitting the Fresnel lens, or HVAC vents blowing hot air across the sensor's field of view, will cause continuous false HIGH states.
  • Calibration: Requires physical adjustment of the two blue potentiometers (sensitivity and time delay). The 'settling time' (the lockout period after a trigger) is fixed at ~2.5 seconds on the BISS0001 and cannot be reprogrammed via software.

mmWave Interference & Calibration

  • Wall Penetration: 24GHz radar easily penetrates standard drywall and thin wood. If mounted on a shared apartment wall, it will detect your neighbor walking in the next room. Fix: Reduce the maximum detection gate distance via UART config commands to limit the field to your room's dimensions.
  • Micro-Doppler Noise: Oscillating fans, spinning ceiling fan blades, and even heavy curtains moving in a draft will register as 'motion'. Fix: Use the LD2410's 'static target' vs 'moving target' thresholds. Raise the static gate energy threshold so only high-mass reflections (like a human torso) trigger the presence flag.
  • Calibration: Done entirely in software via the manufacturer's Bluetooth app or custom UART config commands. No physical pots to adjust.

For a deeper dive into how FMCW radar handles these environmental reflections, All About Circuits provides an excellent technical breakdown of mmWave presence detection.

Decision Tree: Which Motion Sensor Circuit to Build

Use this decision path to select the exact module for your PCB or breadboard layout.

Application Constraint Required Capability Module Pick
Budget is under $2; battery-powered (deep sleep) node Ultra-low quiescent current (<10 μA) AM312 (PIR)
Outdoor security light; needs to see through plastic enclosures Wide area, ignores temperature changes RCWL-0516 (Microwave)
Simple hallway auto-lighting; user walks through the zone Lateral motion detection, basic timing HC-SR501 (PIR)
Bathroom vanity light; user sits still on toilet or in tub Static presence, micro-movement detection HLK-LD2410 (mmWave)
Smart desk lamp; turns off when you leave, stays on while reading Distance gating, static presence, no false triggers from pets HLK-LD2410 (mmWave)
The Default Recommendation: Unless you are strictly constrained by a sub-$2 BOM cost or require a coin-cell battery life exceeding 12 months, build your motion sensor circuit around the HLK-LD2410. The ~$4 module cost is offset by the elimination of false-negative 'lights turning off while I am reading' complaints. Wire its TX/RX to your ESP32's UART2 pins (GPIO 16/17), power it via the 5V rail, and use the UART engineering frames to map your room's exact physical dimensions in software.