ESP32 LD2450 Human Presence Sensor
Overview
The LD2450 is a 24GHz mmWave radar sensor designed for precise human presence detection and tracking. It supports both UART and BLE communication, making it suitable for advanced automation applications.
About LD2450 Human Presence Sensor
The LD2450 is a 24GHz mmWave radar sensor capable of tracking up to three human targets simultaneously, providing real-time data on position, speed, and movement. It utilizes FMCW technology and supports both UART and Bluetooth Low Energy (BLE) communication. The sensor is ideal for applications requiring precise motion tracking, such as smart lighting, occupancy detection, and automation systems. For more information on the LD2450 series, see LD2450.
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 LD2450 is a multi-target 24GHz mmWave radar sensor that outputs real-time position and motion data for up to three individuals. It communicates over UART and also supports BLE for wireless configuration. The module features the following pins:
5V
– Power supply input. Connect to a regulated 5V DC source. Required for full operation of both radar and onboard BLE hardware.GND
– Ground reference pin. Must be connected to the ground of the ESP32 or host microcontroller to ensure reliable UART communication and power distribution.TX
– UART transmit pin. Sends radar data such as X, Y coordinates and speed of tracked targets. Connect this to the ESP32’s RX pin (e.g., GPIO16).RX
– UART receive pin. Used to receive commands or configuration data. Connect this to the ESP32’s TX pin (e.g., GPIO17).
Note: BLE functionality is built into the sensor and requires no additional pins. It can be used for configuration or passive monitoring using compatible Bluetooth devices.
Wiring with ESP32
To connect the LD2450 radar module to an ESP32 using UART, use the following wiring plan. This setup allows for real-time multi-target tracking through a high-speed serial link. BLE configuration can be optionally used for parameter setup or debugging:
5V
(red wire) → 5V pin on ESP32. Supplies main power to the radar module. Ensure a clean, regulated 5V supply.GND
(black wire) → GND pin on ESP32. Establishes common electrical ground to stabilize signal levels.TX
(green wire) → GPIO16 (RX on ESP32). Receives serial radar data from the sensor to the ESP32.RX
(blue wire) → GPIO17 (TX on ESP32). Allows the ESP32 to send configuration commands back to the LD2450.
Important Configuration: Set the UART to use a baud rate of 256000
, with no parity and 1 stop bit. If using BLE for configuration or testing, ensure the ESP32’s Bluetooth interface is initialized and does not conflict with the UART interface in your firmware.
Troubleshooting Guide
Common Issues
🚫 No Data Received
Issue: The ESP32 receives no data from the sensor.
Ensure correct wiring: verify that TX and RX are properly connected. Confirm that the UART is configured with the correct baud rate (256000), no parity, and 1 stop bit. Also, ensure that the sensor is powered with 5V DC.
❌ Presence Not Detected
Issue: The sensor does not detect presence even when someone is in range.
Check the sensor's field of view and ensure there are no obstructions. Verify that the sensor's firmware is up to date and that the configuration settings are appropriate for the detection range and sensitivity required.
⚠️ Intermittent Detection
Issue: Sensor intermittently detects presence or fails to maintain detection.
Ensure stable power supply and UART communication. Check for environmental factors that may cause interference, such as reflective surfaces or moving objects outside the intended detection area.
🔌 BLE Connection Issues
Issue: Unable to connect to the sensor via BLE.
Ensure that the ESP32's Bluetooth is enabled and that the sensor is in range. Verify that the correct BLE address is being used and that there are no other devices interfering with the connection.
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 <HLK_LD2450.h>
HLK_LD2450 radar;
void setup() {
Serial.begin(115200);
Serial2.begin(256000, SERIAL_8N1, 16, 17);
radar.begin(Serial2);
}
void loop() {
radar.read();
for (int i = 0; i < radar.getTargetCount(); i++) {
Serial.print("Target ");
Serial.print(i);
Serial.print(": X=");
Serial.print(radar.getTargetX(i));
Serial.print(" Y=");
Serial.print(radar.getTargetY(i));
Serial.print(" Speed=");
Serial.println(radar.getTargetSpeed(i));
}
delay(500);
}
This Arduino example utilizes the HLK_LD2450
library to interface with the LD2450 sensor over UART. It initializes communication on Serial2
with a baud rate of 256000 and reads data for up to three targets, printing their X and Y coordinates and speed to the serial monitor. Ensure that the sensor is connected to GPIO16 (RX) and GPIO17 (TX) on the ESP32. The library can be found at RBEGamer/HLK-LD2450.
ESPHome Example
uart:
id: uart_bus
tx_pin: GPIO17
rx_pin: GPIO16
baud_rate: 256000
ld2450:
uart_id: uart_bus
sensor:
- platform: ld2450
target:
id: target1
name: "Target 1"
target:
id: target2
name: "Target 2"
target:
id: target3
name: "Target 3"
This ESPHome configuration sets up the LD2450 sensor over UART, using GPIO17 for TX and GPIO16 for RX at a baud rate of 256000. The ld2450
component is initialized with the UART bus, and three targets are defined to track up to three individuals simultaneously. Each target's data, including position and speed, can be accessed in Home Assistant for automation purposes. For more details, refer to the ESPHome documentation: ESPHome LD2450 Sensor Component.
PlatformIO Example
platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
rbegamer/HLK-LD2450
monitor_speed = 115200
PlatformIO Example Code
#include <HLK_LD2450.h>
HLK_LD2450 radar;
void setup() {
Serial.begin(115200);
Serial2.begin(256000, SERIAL_8N1, 16, 17);
radar.begin(Serial2);
}
void loop() {
radar.read();
for (int i = 0; i < radar.getTargetCount(); i++) {
Serial.print("Target ");
Serial.print(i);
Serial.print(": X=");
Serial.print(radar.getTargetX(i));
Serial.print(" Y=");
Serial.print(radar.getTargetY(i));
Serial.print(" Speed=");
Serial.println(radar.getTargetSpeed(i));
}
delay(500);
}
This PlatformIO example uses the HLK_LD2450
library to communicate with the LD2450 sensor over UART. It initializes Serial2
with a baud rate of 256000 and reads data for up to three targets, printing their positions and speeds to the serial monitor. Ensure that the sensor is connected to GPIO16 (RX) and GPIO17 (TX) on the ESP32. The library is available on the PlatformIO Registry: HLK-LD2450 PlatformIO Library.
MicroPython Example
from machine import UART
import time
uart = UART(2, baudrate=256000, tx=17, rx=16)
while True:
if uart.any():
data = uart.read()
if data:
print(data)
time.sleep(0.5)
This MicroPython code initializes UART2 on an ESP32 using GPIO17 for TX and GPIO16 for RX, configured at a baud rate of 256000. It reads raw byte data from the LD2450 sensor and prints it to the console. This can be used for debugging or as a base for parsing structured radar output. For a more complete implementation, refer to the MicroPython driver available at csRon/HLK-LD2450.
Conclusion
The ESP32 LD2450 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.