ESP32 LD2412 Human Presence Sensor
Overview
The LD2412 is a wide-angle 24GHz mmWave radar sensor that detects human presence via FMCW. It supports both UART and digital output and is ideal for real-time occupancy monitoring in smart environments.
About LD2412 Human Presence Sensor
The HLK-LD2412 is a 24GHz FMCW radar sensor designed for human presence detection with a wide sensing angle of ±75° and a range up to 9 meters. It offers both UART communication and a digital output signal, and supports flexible power supply options (3.3V or 5V). This makes it highly adaptable for smart home, automation, and occupancy detection use cases.
Where to Buy
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
Technical Specifications
Pinout Configuration
The VCC
pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND
pin is the ground connection and must be connected to the ground of your ESP32.
The LD2412 module features the following pins:
OUT
– Digital presence detection output. Goes HIGH when presence is detected.TX
– UART transmit pin (connect to RX on ESP32).RX
– UART receive pin (connect to TX on ESP32).5V
– Power input (use either 5V or 3V3).3V3
– Power input for 3.3V systems (do not power both 5V and 3V3 at the same time).GND
– Ground pin, connect to ESP32 GND.
Logic levels are 3.3V. Digital OUT is also 3.3V compatible with ESP32.
Troubleshooting Guide
Common Issues
🛑 No UART Response
Issue: The ESP32 receives no data from the LD2412 sensor.
Ensure TX/RX lines are correctly wired. Check that only one power source (either 5V or 3V3) is connected. Confirm UART baud is 115200 and no conflicting components use the same UART.
⚠️ Digital OUT Stuck LOW
Issue: The OUT pin never changes even when motion is detected.
Check power supply voltage. Try reinitializing the sensor with a UART command. Ensure OUT is not floating and that detection parameters are configured properly via UART.
Debugging Tips
🔍 Serial Monitor
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
⚡ Voltage Checks
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
Code Examples
Arduino Example
#include <HardwareSerial.h>
#include "LD2412.h"
LD2412 radar;
void setup() {
Serial.begin(115200);
Serial2.begin(115200, SERIAL_8N1, 16, 17);
radar.begin(Serial2);
}
void loop() {
radar.read();
if (radar.presenceDetected()) {
Serial.println("Presence detected");
} else {
Serial.println("No presence");
}
delay(1000);
}
This Arduino code uses the LD2412
library to communicate with the sensor over UART2 (GPIO16/17). It continuously polls for presence and prints the result to the Serial Monitor. The LD2412 library handles packet parsing and state tracking. See ginkel/LD2412 for library details.
ESPHome Example
external_components:
- source: "github://Rihan9/LD2412"
refresh: 0s
uart:
id: uart_bus
tx_pin: GPIO17
rx_pin: GPIO16
baud_rate: 115200
ld2412:
uart_id: uart_bus
binary_sensor:
- platform: ld2412
presence:
name: "LD2412 Presence"
sensor:
- platform: ld2412
distance:
name: "LD2412 Distance"
This ESPHome configuration connects the LD2412 sensor using an external component from GitHub. UART2 is used at 115200 baud with GPIO16/17. It exposes presence detection as a binary sensor and measured distance as a sensor entity. Full documentation available at Rihan9/LD2412.
PlatformIO Example
platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
ginkel/LD2412
monitor_speed = 115200
PlatformIO Example Code
#include <LD2412.h>
LD2412 radar;
void setup() {
Serial.begin(115200);
Serial2.begin(115200, SERIAL_8N1, 16, 17);
radar.begin(Serial2);
}
void loop() {
radar.read();
if (radar.presenceDetected()) {
Serial.println("Presence detected");
} else {
Serial.println("No presence");
}
delay(1000);
}
This PlatformIO example communicates with the LD2412 radar using the LD2412
library. It initializes UART2, polls the sensor for presence detection, and logs results via Serial. Use GPIO16/17 for UART2, and install the library via PlatformIO Registry at ginkel/LD2412.
MicroPython Example
There is currently no official MicroPython driver for the LD2412. Developers may implement a custom UART parser based on the protocol in the datasheet.
Conclusion
The ESP32 LD2412 Human Presence Sensor is a powerful Human Presence sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.