LD2410Async
Asynchronous Arduino ESP32 library for the LD2410 mmWave radar sensor
Loading...
Searching...
No Matches
Examples

The library has several example sketches that demonstrate typical usage as well as specialized test scenarios.
All examples reside in the examples/ folder of the library.

Example: Using callback for presence detection updates

radar.onDetectionDataReceived([](LD2410Async* sender, bool presenceDetetced, byte userData) {
sender->getDetectionDataRef().print(); // direct access, no copy
});
LD2410Async radar(RadarSerial)
Creates LD2410Async object bound to the serial port defined in RadarSerial.
Asynchronous driver class for the LD2410 human presence radar sensor.
Definition LD2410Async.h:38
void onDetectionDataReceived(DetectionDataCallback callback)
Registers a callback for new detection data.
const LD2410Types::DetectionData & getDetectionDataRef() const
Access the current detection data without making a copy.
void print() const
Debug helper: print detection data contents to Serial.

Commands used in this example:

Example: Clone config data, modify, and write back

ConfigData cfg = radar.getConfigData(); // clone
cfg.noOneTimeout = 60;
radar.configureAllConfigSettingsAsync(cfg, false, [](LD2410Async* sender, AsyncCommandResult result, byte) {
if (result == AsyncCommandResult::SUCCESS) {
Serial.println("Config updated successfully!");
}
});
bool configureAllConfigSettingsAsync(const LD2410Types::ConfigData &configToWrite, bool writeAllConfigData, AsyncCommandCallback callback)
Applies a full ConfigData struct to the LD2410.
LD2410Types::ConfigData getConfigData() const
Returns a clone of the current configuration data of the radar.
unsigned short noOneTimeout
Timeout (seconds) until "no presence" is declared.

Commands used in this example:

Usage Example Sketches

  • basicPresenceDetection.ino Minimal example showing how to detect presence and print state changes via Serial.
  • receiveData.ino Demonstrates continuous reception of detection frames and printing all available sensor data.
  • changeConfig.ino Shows how to request and modify configuration settings (e.g. timeouts, sensitivities) using async commands.
  • changeDistanceResolution.ino Illustrates how to change the sensor’s distance resolution (20 cm vs 75 cm) and handle the required reboot.
  • - simplePresenceDetectionWebservice.ino Integrates presence detection with a simple web service endpoint, useful as a starting point for IoT or home automation setups.

Test Sketches

  • enableConfigModeTest.ino Test sketch to explicitly measure entering configuration mode and handling success/failure cases. The main use of this test is to check, whther enableConfigMode experiences timeouts.
  • tortureTest.ino Stress test that issues random async commands in a loop, tracking execution times and statistics. Used to check whther any errors accour over time.
  • unitTest.ino Tests all methods of the lib. Useful for regression testing during development.