| Crates.io | ld2410 |
| lib.rs | ld2410 |
| version | 1.0.0 |
| created_at | 2025-12-19 21:37:36.073938+00 |
| updated_at | 2025-12-19 21:37:36.073938+00 |
| description | Rust interface for LD2410 presence detection |
| homepage | |
| repository | https://github.com/lomagno2003/ld2410 |
| max_upload_size | |
| id | 1995595 |
| size | 26,433 |
A no_std compatible Rust driver for the HLK-LD2410 human presence radar sensor. This library provides a robust interface for communicating with the LD2410 over UART using the vendor's binary framed protocol.
The LD2410 communicates via UART at 256000 baud (8N1) using a binary framed protocol:
[Header: F4 F3 F2 F1][Length: u16 LE][Frame Data][Footer: F8 F7 F6 F5]
Frame data contains:
[Header: FD FC FB FA][Length: u16 LE][Command Word: u16 LE][Payload][Footer: 04 03 02 01]
use ld2410::LD2410;
// Create sensor with UART peripheral
let mut sensor = LD2410::new(uart);
// Read presence data continuously
loop {
match sensor.read_presence() {
Ok(data) => {
println!("Presence: {}", data.presence());
println!("Moving: {}cm (energy: {})",
data.moving_distance_cm,
data.moving_energy);
println!("Still: {}cm (energy: {})",
data.still_distance_cm,
data.still_energy);
}
Err(e) => println!("Error: {:?}", e),
}
}
// Enter configuration mode
sensor.enter_config_mode()?;
// Read firmware version
let fw = sensor.read_firmware_raw()?;
// Exit configuration mode
sensor.exit_config_mode()?;
// Enable engineering mode for detailed diagnostics
sensor.enable_engineering_mode()?;
// Read engineering reports (type 0x01)
// ... handle engineering data ...
// Return to normal mode
sensor.disable_engineering_mode()?;
Contains the parsed presence detection report:
target_state – NoTarget, Moving, Stationary, or Bothmoving_distance_cm – distance to moving targetmoving_energy – energy level of moving target (0-255)still_distance_cm – distance to stationary targetstill_energy – energy level of stationary target (0-255)detection_distance_cm – overall detection distanceRead(E) – UART read errorWrite(E) – UART write errorInvalidFrame – malformed frame structureUnknownReportType – unsupported report typeInvalidReport – report content too short or inconsistentBufferOverflow – received frame exceeds buffer sizeembedded-io traits (Read + Write)See ../hello-world-ld2410/ for a complete ESP32 example using esp-hal and embassy.
MIT