https://github.com/ncmreynolds/ld2410
https://r0.hlktech.com/download/HLK-LD2410B-24G/1/LD2410B%20%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE%20V1.06%20230221.pdf
HLK-LD2410B
https://h.hlktech.com/Mobile/download/fdetail/204.html
























代码1

https://wiki.dfrobot.com/SKU_SEN0557_24GHz_Human_Presence_Sensing_Module

#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //Define soft serial port, define port 3 as TX and port 2 as RX,
size_t readN(uint8_t *buf, size_t len);
bool recdData(uint8_t *buf);
uint8_t Cache[23] = {0}; //Cache
void setup()
{
Serial.begin(115200);
mySerial.begin(57600); //Soft serial port
//Serial1.begin(256000);
}
void loop()
{
recdData(Cache);
}
size_t readN(uint8_t *buf, size_t len)
{
size_t offset = 0, left = len;
int16_t Tineout = 1500;
uint8_t *buffer = buf;
long curr = millis();
while (left) {
if (Serial1.available()) {
// buffer[offset] = Serial1.read();
buffer[offset] = Serial.read();
offset++;
left--;
}
if (millis() - curr > Tineout) {
break;
}
}
return offset;
}
bool recdData(uint8_t *buf)
{
int16_t Tineout = 50000;
long curr = millis();
uint8_t ch;
bool ret = false;
const char *P;
while (!ret) {
if (millis() - curr > Tineout) {
break;
}
if (readN(&ch, 1) == 1) {
if (ch == 0xF4) {
buf[0] = ch;
if (readN(&ch, 1) == 1) {
if (ch == 0xF3) {
buf[1] = ch;
if (readN(&ch, 1) == 1) {
if (ch == 0xF2) {
buf[2] = ch;
if (readN(&ch, 1) == 1) {
if (ch == 0xF1) {
buf[3] = ch;
if (readN(&buf[4], 19) == 19) {
// printdf(buf, 23); //Print raw data
uint16_t Adistance = buf[10] << 8 | buf[9];
uint16_t Sdistance = buf[13] << 8 | buf[12];
uint16_t Distance = buf[16] << 8 | buf[15];
switch (buf[8]) {
case 0x00 : Serial.println("Detected status: nobody"); break;
case 0x01 : Serial.println("Detected status: moving"); break;
case 0x02 : Serial.println("Detected status: stationary"); break;
case 0x03 : Serial.println("Detected status: moving & stationary object"); break;
}
// Serial.print("Energy value of moving object:");
// Serial.println(buf[11]);
// Serial.print("Energy value of stationary object:");
// Serial.println(buf[14]);
// Serial.print("Distance to the moving object in CM:");
// Serial.println(Adistance);
// Serial.print("Distance to the stationary object in CM:");
// Serial.println(Sdistance);
Serial.print("Detection distance CM:");
Serial.println(Distance);
break;
}
}
}
}
}
}
}
}
}
}
return ret;
}
void printdf(uint8_t *buf, int len)
{
for (int i = 0; i < len; i++) {
if (buf[i] < 0x10) {
Serial.print("0");
}
Serial.print(buf[i], HEX);
Serial.print(" ");
}
Serial.println();
}
代码2
https://github.com/ncmreynolds/ld2410

/*
* Example sketch for reporting on readings from the LD2410 using whatever settings are currently configured.
*
* This has been tested on the following platforms...
*
* On ESP32, connect the LD2410 to GPIO pins 32&33
* On ESP32S2, connect the LD2410 to GPIO pins 8&9
* On ESP32C3, connect the LD2410 to GPIO pins 4&5
* On Arduino Leonardo or other ATmega32u4 board connect the LD2410 to GPIO pins TX & RX hardware serial
*
* The serial configuration for other boards will vary and you'll need to assign them yourself
*
* There is no example for ESP8266 as it only has one usable UART and will not boot if the alternate UART pins are used for the radar.
*
* For this sketch and other examples to be useful the board needs to have two usable UARTs.
*
*/
#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("\nConnect 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"));
}
}
}
浙公网安备 33010602011771号