ESP32 LD2420 Human Presence Sensor
Overview
The LD2420 is a mmWave radar sensor for motion, micro-motion, and presence detection. It supports UART communication and GPIO output, and integrates easily with ESPHome and Arduino platforms.
About LD2420 Human Presence Sensor
The LD2420 is a high-performance 24GHz mmWave radar sensor designed for human presence detection, capable of sensing motion, micro-motion, and stationary targets within a range of up to 8 meters. It features UART and GPIO outputs, operates at 3.3V, and is suitable for a wide range of smart home and automation applications. The sensor supports flexible configuration options via UART and is compatible with ESPHome and Arduino environments. For firmware versions below 1.5.3, the baud rate is 256000; for newer firmware, it's 115200. No MicroPython or ESP-IDF libraries are available yet.
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 LD2420 is a versatile 24GHz mmWave radar sensor capable of detecting motion, micro-motion, and presence across configurable gate zones. Its pin layout is designed for straightforward UART communication with microcontrollers like the ESP32. The module includes the following pins:
VCC
– Power input pin. Requires a regulated 3.3V DC source. Supplying a higher voltage may damage the sensor permanently.GND
– Ground reference. This pin must be connected to the ESP32 or host microcontroller's GND pin to ensure stable logic levels and power.TX
– UART transmit pin. Used to send radar data to the microcontroller. Connect this to the ESP32’s RX pin (e.g., GPIO16).RX
– UART receive pin. Used to receive configuration commands from the microcontroller. Connect this to the ESP32’s TX pin (e.g., GPIO17).OUT
– Optional digital output pin that goes HIGH (3.3V) when presence is detected. This pin can be used to trigger logic-level events or interrupts.
Note: The OUT signal operates at 3.3V logic, compatible with ESP32 I/O without the need for level shifting.
Wiring with ESP32
To connect the LD2420 sensor to an ESP32 using UART for real-time presence detection, wire the pins as follows. This configuration assumes use of UART2 on the ESP32:
VCC
(red wire) → 3.3V on ESP32. Power input for the LD2420. Use a stable LDO or onboard 3.3V regulator output.GND
(black wire) → GND on ESP32. This is the ground connection shared with the ESP32 for consistent signal referencing.TX
(green wire) → GPIO16 (RX on ESP32). Allows the ESP32 to receive data packets such as distance, presence, and signal strength.RX
(blue wire) → GPIO17 (TX on ESP32). Allows the ESP32 to send configuration or command messages to the LD2420.OUT
(yellow wire, optional) → GPIO18 on ESP32. Use this if you want to act on a simple HIGH signal indicating presence, without parsing UART data.
Important: The correct baud rate must be chosen based on the sensor’s firmware version: 256000
for firmware <1.5.3, or 115200
for firmware ≥1.5.3. Be sure to match this in both hardware and ESPHome/Arduino configuration.
Troubleshooting Guide
Common Issues
📶 Baud Rate Mismatch
Issue: Sensor does not respond over UART.
Check firmware version: use 256000 baud for firmware < v1.5.3 and 115200 baud for ≥ v1.5.3. Ensure both TX and RX lines are properly connected.
❌ No Presence Detection
Issue: The sensor does not detect movement.
Verify power is 3.3V. Confirm detection zones and sensitivity settings via UART or ESPHome configuration.
⚠️ Intermittent Readings
Issue: Sensor data updates inconsistently.
Ensure stable UART connection. Check signal quality and reduce environmental interference or obstacles.
🔌 ESPHome Entity Unavailable
Issue: Home Assistant shows unknown or unavailable sensor states.
Ensure sensor firmware matches baud rate in configuration. Also confirm ESPHome version supports LD2420.
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
#if defined(ESP32)
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#define MONITOR_SERIAL Serial
#define RADAR_SERIAL Serial1
#define RADAR_RX_PIN 32
#define RADAR_TX_PIN 33
#elif CONFIG_IDF_TARGET_ESP32S2
#define MONITOR_SERIAL Serial
#define RADAR_SERIAL Serial1
#define RADAR_RX_PIN 9
#define RADAR_TX_PIN 8
#elif CONFIG_IDF_TARGET_ESP32C3
#define MONITOR_SERIAL Serial
#define RADAR_SERIAL Serial1
#define RADAR_RX_PIN 4
#define RADAR_TX_PIN 5
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
#else // ESP32 Before IDF 4.0
#define MONITOR_SERIAL Serial
#define RADAR_SERIAL Serial1
#define RADAR_RX_PIN 32
#define RADAR_TX_PIN 33
#endif
#elif defined(AVR_ATmega32U4)
#define MONITOR_SERIAL Serial
#define RADAR_SERIAL Serial1
#define RADAR_RX_PIN 0
#define RADAR_TX_PIN 1
#endif
#include <ld2410.h>
ld2410 radar;
uint32_t lastReading = 0;
bool radarConnected = false;
void setup(void)
{
MONITOR_SERIAL.begin(115200); //Feedback over Serial Monitor
//radar.debug(MONITOR_SERIAL); //Uncomment to show debug information from the library on the Serial Monitor. By default this does not show sensor reads as they are very frequent.
#if defined(ESP32)
RADAR_SERIAL.begin(256000, SERIAL_8N1, RADAR_RX_PIN, RADAR_TX_PIN); //UART for monitoring the radar
#elif defined(AVR_ATmega32U4)
RADAR_SERIAL.begin(256000); //UART for monitoring the radar
#endif
delay(500);
MONITOR_SERIAL.print(F("
Connect LD2410 radar TX to GPIO:"));
MONITOR_SERIAL.println(RADAR_RX_PIN);
MONITOR_SERIAL.print(F("Connect LD2410 radar RX to GPIO:"));
MONITOR_SERIAL.println(RADAR_TX_PIN);
MONITOR_SERIAL.print(F("LD2410 radar sensor initialising: "));
if(radar.begin(RADAR_SERIAL))
{
MONITOR_SERIAL.println(F("OK"));
MONITOR_SERIAL.print(F("LD2410 firmware version: "));
MONITOR_SERIAL.print(radar.firmware_major_version);
MONITOR_SERIAL.print('.');
MONITOR_SERIAL.print(radar.firmware_minor_version);
MONITOR_SERIAL.print('.');
MONITOR_SERIAL.println(radar.firmware_bugfix_version, HEX);
}
else
{
MONITOR_SERIAL.println(F("not connected"));
}
}
void loop()
{
radar.read();
if(radar.isConnected() && millis() - lastReading > 1000) //Report every 1000ms
{
lastReading = millis();
if(radar.presenceDetected())
{
if(radar.stationaryTargetDetected())
{
Serial.print(F("Stationary target: "));
Serial.print(radar.stationaryTargetDistance());
Serial.print(F("cm energy:"));
Serial.print(radar.stationaryTargetEnergy());
Serial.print(' ');
}
if(radar.movingTargetDetected())
{
Serial.print(F("Moving target: "));
Serial.print(radar.movingTargetDistance());
Serial.print(F("cm energy:"));
Serial.print(radar.movingTargetEnergy());
}
Serial.println();
}
else
{
Serial.println(F("No target"));
}
}
}
The LD2420 is supported by the Bolukan/ld2420 Arduino library. This library provides initialization, data reading, and configuration functions for working with the LD2420 via UART. Developers should match the correct baud rate according to the sensor's firmware version (115200 or 256000).
ESPHome Example
# Example configuration entry
ld2420:
text_sensor:
- platform: ld2420
fw_version:
name: LD2420 Firmware
sensor:
- platform: ld2420
moving_distance:
name : Moving Distance
binary_sensor:
- platform: ld2420
has_target:
name: Presence
select:
- platform: ld2420
operating_mode:
name: Operating Mode
number:
- platform: ld2420
presence_timeout:
name: Detection Presence Timeout
min_gate_distance:
name: Detection Gate Minimum
max_gate_distance:
name: Detection Gate Maximum
# See "Number" section below for detail
gate_select:
name: Select Gate to Set
still_threshold:
name: Set Still Threshold Value
move_threshold:
name: Set Move Threshold Value
button:
- platform: ld2420
apply_config:
name: Apply Config
factory_reset:
name: Factory Reset
restart_module:
name: Restart Module
revert_config:
name: Undo Edits
The LD2420 is natively supported by ESPHome. The official component allows full UART communication and exposes multiple binary and numeric sensors such as presence state, motion energy, and distance. Refer to the documentation at esphome.io for configuration examples. Ensure baud rate and firmware compatibility (256000 for firmware <1.5.3, 115200 for ≥1.5.3).
PlatformIO Example
No official PlatformIO support exists for the LD2420 sensor at this time. Developers can use the Arduino library manually within a PlatformIO project if needed.
MicroPython Example
There is currently no MicroPython driver for the LD2420. Developers may implement their own UART-based parser based on the official datasheet protocol.
Conclusion
The ESP32 LD2420 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.