If you need to detect human presence—not just transient movement—the default motion sensor schematic for an ESP32 uses the Hi-Link HLK-LD2410 mmWave radar wired via hardware UART, rather than a standard HC-SR501 PIR module. While PIR sensors are cheap and low-power, they are blind to stationary targets. This guide provides the exact schematics, UART parsing math, and hardware decision paths to interface either sensor with a 3.3V microcontroller without frying your logic pins or drowning in false triggers.

The Physics of Motion Detection: PIR vs. mmWave

Passive Infrared (PIR) sensors rely on pyroelectric materials (typically lithium tantalate) that generate a surface charge when exposed to changes in infrared radiation. A segmented Fresnel lens focuses IR from a moving heat source onto a dual-element sensor, creating a differential voltage. An onboard comparator (usually a BISS0001 chip) amplifies this delta and triggers a digital GPIO HIGH. Because it requires a change in thermal signatures across the lens zones, a human sitting perfectly still on a couch becomes invisible to a PIR sensor within seconds.

Millimeter-wave (mmWave) radar uses Frequency Modulated Continuous Wave (FMCW) technology. It transmits a 24 GHz or 60 GHz RF signal and analyzes the reflected wave's phase and frequency shift. According to Analog Devices' FMCW radar primers, this phase coherence allows the sensor to detect micro-Doppler signatures—like the 1 cm chest expansion of a human breathing. The output is not a simple boolean pin, but a continuous digital UART data stream containing precise target distance, energy, and state matrices.

Decision Matrix: Which Sensor Fits Your Build?

Do not default to a PIR sensor just because it has three pins and a potentiometer. Use this decision path to select the correct module for your schematic.

Requirement HC-SR501 (PIR) HLK-LD2410B (mmWave)
Detect stationary presence? No (times out) Yes (breathing detection)
Power Source Battery (CR123A/18650) Mains / USB (5V continuous)
See through plastic enclosure? No (IR blocked) Yes (RF penetrates ABS/PLA)
Typical Cost (2026) ~$1.20 ~$4.50
Output Type Digital GPIO (3.3V HIGH/LOW) Digital UART (256000 baud)
The Concrete Pick: If your project is an ESP32 smart-home presence node powered by USB, buy the HLK-LD2410B. It natively integrates with ESPHome, operates at 5V, and solves the 'sleeping on the couch' false-negative problem. Only choose the HC-SR501 PIR if you are building a battery-powered intruder alarm where micro-amp sleep currents are mandatory.

The mmWave Motion Sensor Schematic and Pinout

The HLK-LD2410B operates strictly at 5V and draws up to 150mA during RF transmission bursts. A common bench mistake is powering it from the ESP32's onboard 3.3V LDO, which will immediately trigger a brownout reset on the microcontroller. You must power the sensor from the 5V VIN rail and use a logic-level shift or rely on the ESP32's 5V-tolerant RX pin configuration.

HLK-LD2410B Pin ESP32 DevKit V1 Pin Notes & Constraints
VCC VIN (5V) Supply range: 4.5V to 6V. Do NOT use 3V3.
GND GND Common ground required for UART reference.
TX GPIO 16 (RX2) ESP32 UART2 RX. 5V tolerant on most DevKits.
RX GPIO 17 (TX2) ESP32 UART2 TX. Outputs 3.3V (sensor accepts >2V as HIGH).
Hardware Mitigation: Solder a 100µF electrolytic capacitor directly across the VCC and GND pins on the LD2410B module. The 24GHz PA (Power Amplifier) draws sharp current spikes; without local bulk capacitance, the voltage rail sags, corrupting the UART frames and causing the ESP32 to drop bytes.

UART Output Math: Converting Raw Hex to Distance

The LD2410B outputs digital UART frames at an unusually high 256,000 baud rate. The Espressif UART API handles this easily, but you must parse the byte stream manually if you aren't using a pre-built library. The sensor outputs a 32-byte reporting frame every 100ms.

The frame structure begins with a header (F4 F3 F2 F1), followed by the data length, and a data head byte (AA). The physical units we care about are buried in the payload:

  • Target State: Byte 0 of payload (0 = empty, 1 = moving, 2 = stationary, 3 = both).
  • Moving Target Distance: Bytes 1-2 of payload (Little-endian 16-bit integer, in centimeters).
  • Moving Target Energy: Byte 3 of payload (0-100 scale).

The Raw-to-Unit Math:
Because the distance is transmitted as a little-endian 16-bit integer, you cannot just read a single byte. You must bitwise-OR the low byte with the high byte shifted left by 8 bits.

// Assuming 'payload' is an array starting immediately after the 0xAA data head byte
uint8_t target_state = payload[0];

// Raw-to-Unit Math for Distance (cm)
uint16_t raw_distance_cm = payload[1] | (payload[2] << 8);

// Raw-to-Unit Math for Energy (0-100%)
uint8_t target_energy = payload[3];

// Convert cm to meters for standard physical unit display
float distance_meters = raw_distance_cm / 100.0;

Calibration and Scaling: The LD2410B does not require software math scaling for distance; the factory calibration is baked into the FMCW timing. However, you must calibrate the Distance Gates. The sensor divides its 6-meter range into eight 0.75m 'gates'. Using the manufacturer's BLE configuration app on your phone, you must set the 'Maximum Detection Gate' to match your room size, otherwise the sensor will report reflections from the hallway outside your room.

Interference Sources and Hardware Mitigation

Both sensor types suffer from environmental interference, but the failure modes are entirely different. Understanding these prevents hours of frustrating debugging.

PIR (HC-SR501) Interference

  • Delta-T Airflow: HVAC vents blowing warm air across cold rooms will trigger the BISS0001 comparator. Fix: Baffle the lens or lower the sensitivity potentiometer.
  • Direct Sunlight: IR radiation from a shifting sunbeam saturates the pyroelectric element, blinding the sensor. Fix: Apply an IR-blocking optical filter (typically included as a white silicone sleeve over the TO-5 can).

mmWave (HLK-LD2410B) Interference

  • Ceiling Fans and Motors: The micro-Doppler effect will interpret spinning fan blades as a massive moving target. Fix: Use the BLE app to lower the 'Moving Sensitivity' in the specific distance gate covering the ceiling, while keeping 'Stationary Sensitivity' high to still detect breathing on the couch below.
  • Thin Drywall and Water Pipes: 24 GHz RF easily penetrates standard 1/2-inch gypsum board. It will detect a person walking in the adjacent room, or even water flowing through copper pipes in the wall. Fix: Mount the sensor inside a grounded metal RF shield (like an Altoids tin with a cutout) to narrow the beam angle, or reduce the maximum distance gate to physically clip the radar horizon at the wall boundary.

By selecting the correct physics for your application, buffering the 5V rail with local capacitance, and properly parsing the little-endian UART frames, your ESP32 motion node will deliver reliable, drift-free presence detection on the bench and in the field.