LD2451 anyone have had success in connecting it ?

Hi,
I'm trying to connect the LD2451 radar module, unfortunately the manual is in chinese and even automated translations works so and so... Was anyone able to get it working ?

I've also tried to contact the producer but no answer so far...

Thanks !

Yes, i have some example code in a thread I posted a few days ago.
I used the app to make the settings and connected it to an arduino Uno to receive the dataframe and output the data to the serial port.
It works, at least for debugging :slight_smile:

Hi, thanks. Will try but I have to find a "scapegoat" android device: the software is only available trough an obscure site ... :thinking:

çalışmalar sonunda çıktı alabildim test devam ediyor. Daha ileri taşımak için paylaşıyorum Kodu

#include <HardwareSerial.h>

HardwareSerial radarSerial(2);
#define RADAR_RX_PIN 16 
#define RADAR_TX_PIN 17 

const byte HEADER[4] = {0xF4, 0xF3, 0xF2, 0xF1};
const byte FOOTER[4] = {0xF8, 0xF7, 0xF6, 0xF5};

void setup() {
    Serial.begin(115200);
    radarSerial.begin(115200, SERIAL_8N1, RADAR_RX_PIN, RADAR_TX_PIN);
    radarSerial.setTimeout(10);
    Serial.println("HLK-LD2451 Radar Başlatıldı...");
}

void loop() {
    static byte buffer[128];
    static int index = 0;

    while (radarSerial.available()) {
        byte data = radarSerial.read();

        // 1. Adım: Başlık Tespiti (F4 F3 F2 F1)
        if (index < 4) {
            if (data == HEADER[index]) {
                buffer[index++] = data;
                if (index == 4) Serial.println("\nBaşlık Algılandı!");
            } else {
                index = 0;
            }
        } 
        // 2. Adım: Veri ve Footer Okuma
        else {
            buffer[index++] = data;

            // Veri Uzunluğu Okuma (6. ve 7. Byte)
            if (index == 6) {
                int dataLength = buffer[4] | (buffer[5] << 8);
                Serial.printf("Beklenen Veri Uzunluğu: %d\n", dataLength);
                if (dataLength < 0 || dataLength > 100) index = 0; // Geçersiz uzunluk
            }

            // Paket Tamamlama Kontrolü
            if (index >= 10) { 
                int dataLength = buffer[4] | (buffer[5] << 8);
                int totalLength = 4 + 2 + dataLength + 4;

                // Buffer Taşması Kontrolü
                if (totalLength > sizeof(buffer)) {
                    Serial.println("HATA: Buffer taşması!");
                    index = 0;
                    return;
                }

                // Kalan Veriyi Oku
                while (index < totalLength && radarSerial.available()) {
                    buffer[index++] = radarSerial.read();
                }

                // Footer Kontrolü (Son 4 Byte)
                bool footerOK = true;
                for (int i=0; i<4; i++) {
                    if (buffer[totalLength-4+i] != FOOTER[i]) {
                        footerOK = false;
                        Serial.printf("HATA: Footer[%d] = %02X (Beklenen: %02X)\n", i, buffer[totalLength-4+i], FOOTER[i]);
                        break;
                    }
                }

                if (!footerOK) {
                    Serial.println("HATA: Footer geçersiz!");
                    index = 0;
                    return;
                }

                // Ham Veriyi Yazdır
                Serial.print("Alınan Paket: ");
                for (int i=0; i<totalLength; i++) Serial.printf("%02X ", buffer[i]);
                Serial.println();

                // Veriyi İşle
                processData(buffer + 6, dataLength); // Veri bloğu 6. bytedan başlar
                index = 0;
            }
        }
    }
}

//--------------------------------------------------
//  VERİ İŞLEME
//--------------------------------------------------
void processData(byte* data, int length) {
    if (length <= 0) return;

    // Alarm Durumu (1. Byte)
    byte alarmStatus = data[0];
    Serial.printf("Alarm Durumu: %s\n", (alarmStatus == 0x01) ? "Hedef Var" : "Yok");

    // Hedef Sayısı (2. Byte)
    byte targetCount = data[1];
    Serial.printf("Hedef Sayısı: %d\n", targetCount);

    // Her Hedef 5 Byte: [Açı(1)][Mesafe(1)][Yön(1)][Hız(1)][SNR(1)]
    for (int i=0; i<targetCount; i++) {
        int offset = 2 + i*5; // Alarm (1) + HedefSayısı (1) + (i*5)
        if (offset + 4 >= length) {
            Serial.println("HATA: Veri boyutu yetersiz!");
            break;
        }

        // Açı: 0x80 çıkarılarak işaretliye çevrilir
        int8_t angle = data[offset] - 0x80; // Örn: 0x8A → 10°

        // Mesafe: 1 byte (direkt metre)
        uint8_t distance_m = data[offset + 1]; // Örn: 0x28 → 40m

        // Yön ve Hız
        byte direction = data[offset + 2]; // 0x01: Yaklaşan, 0x00: Uzaklaşan
        uint8_t speed_kmh = data[offset + 3]; // Direkt km/h

        // SNR
        uint8_t snr = data[offset + 4]; // 0-255

        Serial.printf("Hedef %d: Mesafe=%d m, Açı=%d°, Yön=%s, Hız=%d km/h, SNR=%d\n",
                     i+1, distance_m, angle, 
                     (direction == 0x01) ? "Yaklaşan" : "Uzaklaşan", 
                     speed_kmh, snr);
    }
}

Serial Monitor Çıktı



Başlık Algılandı!
Beklenen Veri Uzunluğu: 0
Alınan Paket: F4 F3 F2 F1 00 00 F8 F7 F6 F5 

Başlık Algılandı!
Beklenen Veri Uzunluğu: 7
Alınan Paket: F4 F3 F2 F1 07 00 01 01 85 02 01 03 CE F8 F7 F6 F5 
Alarm Durumu: Hedef Var
Hedef Sayısı: 1
Hedef 1: Mesafe=2 m, Açı=5°, Yön=Yaklaşan, Hız=3 km/h, SNR=206

Başlık Algılandı!
Beklenen Veri Uzunluğu: 7
Alınan Paket: F4 F3 F2 F1 07 00 01 01 80 02 01 04 CE F8 F7 F6 F5 
Alarm Durumu: Hedef Var
Hedef Sayısı: 1
Hedef 1: Mesafe=2 m, Açı=0°, Yön=Yaklaşan, Hız=4 km/h, SNR=206

Hi, sorry but I have some difficulties in understanding your suggestion. From the few things I get seems that you managed to connect it.

Merhaba, tam olarak anlamadığın nokta neresi yardımcı olabilirim senin için

you could start by telling us what language you're posting in. most English speaking people do not recognize Turkish.

I understand you. But not understanding the Turkish language is another issue, ''Not knowing'' is another issue. I know that the problem discussed in the form is the LD2451 data analysis and connection problem...

This code is designed to communicate with an HLK-LD2451 radar module using an ESP32 microcontroller. The radar module transmits data packets containing information about detected objects, such as their distance, angle, direction, speed, and signal-to-noise ratio (SNR). The ESP32 reads these packets, verifies their integrity, and processes the received data.

1. Serial Communication Setup

At the beginning of the code, the HardwareSerial library is used to define a second serial port (radarSerial) for communication with the radar module. The RX (receive) and TX (transmit) pins are set to GPIO 16 and GPIO 17, respectively. The predefined header (HEADER) and footer (FOOTER) values are used to identify valid radar data packets.

In the setup() function, both the primary serial port (Serial) and the secondary serial port (radarSerial) are initialized at a baud rate of 115200. The radarSerial.setTimeout(10) function ensures that read operations time out if no data is received within 10 milliseconds.

2. Reading and Validating Data Packets

The loop() function continuously checks for incoming data from the radar module. A static buffer (buffer) is used to store received bytes, and an index variable keeps track of the current position in the buffer.

  1. Detecting the Packet Header:
  • The first four bytes are compared against the HEADER (0xF4, 0xF3, 0xF2, 0xF1).
  • If the incoming data matches, it is stored in the buffer.
  • If a mismatch occurs, the index is reset to 0 to restart packet detection.
  1. Reading the Data Length:
  • Once the header is identified, bytes 5 and 6 contain the expected data length.
  • This length is extracted and validated to ensure it is within a reasonable range (0 to 100 bytes).
  • If the length is invalid, the index is reset.
  1. Completing the Data Packet:
  • The total expected packet length is calculated as:
    4.Header (4 bytes) + Data Length (extracted from packet) + Footer (4 bytes)*
  • The buffer is filled until this length is reached.
  1. Verifying the Packet Footer:
  • The last four bytes are compared against the predefined FOOTER (0xF8, 0xF7, 0xF6, 0xF5).
  • If the footer is incorrect, an error message is printed, and the buffer is reset.
  1. Processing the Valid Packet:
  • If the entire packet is received correctly, it is printed in hexadecimal format for debugging.
  • The actual data portion (excluding header and footer) is extracted and passed to the processData() function for analysis.

3. Processing Radar Data

The processData() function extracts useful information from the radar data:

  1. Alarm Status:
  • The first byte of the data indicates whether a target is detected (0x01 = "Target Detected", 0x00 = "No Target").
  1. Number of Targets:
  • The second byte specifies how many targets are detected.
  1. Iterating Through Target Data:
  • Each target has a 5-byte structure:
    • Angle (1 byte): The raw value is adjusted by subtracting 0x80 to convert it into a signed value (e.g., 0x8A → 10°).
    • Distance (1 byte): The value represents the distance in meters.
    • Direction (1 byte): 0x01 indicates an approaching object, and 0x00 indicates a receding object.
    • Speed (1 byte): The value represents the speed in km/h.
    • SNR (1 byte): The signal-to-noise ratio value (0-255), which helps determine detection quality.
  1. Displaying Target Data:
  • The extracted data is printed to the serial monitor in a structured format.
  • If the data size is insufficient, an error is reported.

Summary

This code enables an ESP32 to communicate with an HLK-LD2451 radar module, read and validate incoming data packets, and extract meaningful information about detected objects. It ensures data integrity using header and footer verification and processes each target’s distance, angle, direction, speed, and SNR for further application use.