LD2410C Human Presence Sensor Configuration with App, Circuit and Test with Arduino Micro
Quote from Matoo robot on 2024年7月10日, pm5:28Welcome to the tutorial on using the LD2410C human presence status detection module. This device, developed by Hi-link, is a versatile and highly sensitive tool that uses frequency modulated continuous waves (FMCW) to detect the presence of humans in a designated area.
Project description
Welcome to the tutorial on using the LD2410C human presence status detection module. This device, developed by Hi-link, is a versatile and highly sensitive tool that uses frequency modulated continuous waves (FMCW) to detect the presence of humans in a designated area.
Electronic components
Arduino micro
undefined
micro usb cable
undefined
female female dupont cables
undefined
male pins
undefined
Socket for arduino micro
undefined
PCB
undefined
Download gerber file –> $ https://rogerbit.com/wprb/wp-content/uploads/2022/03/teclado-arduino-micro.zip $
Circuit
undefined
undefined
Code
/* * Sketch example for reporting LD2410 readings using the currently configured setup. * * This has been tested on the following platforms... * * On ESP32, connect LD2410 to GPIO pins 32 and 33 * On ESP32S2, connect LD2410 to GPIO pins 8 and 9 * On ESP32C3, connect LD2410 to GPIO pins 4 and 5 * On Arduino Leonardo or other ATmega32u4 boards, connect LD2410 to the hardware serial TX and RX pins * * Serial configuration for other boards will vary and should be assigned by yourself * * There's no example for ESP8266 as it only has one usable UART and won't boot if alternative UART pins are used for the radar. * * For this sketch and other examples to be useful, the board must have two usable UARTs. * */ int redPin = 11; // Red pin int greenPin = 9; // Green pin int bluePin = 10; // Blue pin byte com = 0; #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 The CONFIG_IDF_TARGET 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) { pinMode(redPin, OUTPUT); // Set redPin as an output pinMode(greenPin, OUTPUT); // Set greenPin as an output pinMode(bluePin, OUTPUT); // Set bluePin as an output MONITOR_SERIAL.begin(115200); // Serial Monitor feedback // radar.debug(MONITOR_SERIAL); // Uncomment to show library debug info on Serial Monitor. By default, this does not show sensor readings as they are very frequent. #if defined(ESP32) RADAR_SERIAL.begin(256000, SERIAL_8N1, RADAR_RX_PIN, RADAR_TX_PIN); // UART for radar monitoring #elif defined(__AVR_ATmega32U4__) RADAR_SERIAL.begin(256000); // UART for radar monitoring #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("Initializing LD2410 radar sensor: ")); 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())//If a stationary target is detected, it turns blue { Serial.print(F("Stationary Target BLUE LIGHT: ")); Serial.print(radar.stationaryTargetDistance()); Serial.print(F("cm energy:")); Serial.print(radar.stationaryTargetEnergy()); Serial.println(' '); color(0, 0, 255); // RGB LED as blue } if(radar.movingTargetDetected())//If a moving target is detected, it turns red { Serial.print(F("MOVING TARGET DETECTED RED LIGHT!: ")); Serial.print(radar.movingTargetDistance()); Serial.print(F("cm energy:")); Serial.print(radar.movingTargetEnergy()); color(255, 0, 0);// RGB LED as red } Serial.println(); } else { Serial.println(F("No Target GREEN LIGHT"));//No target in range, turns green color(0,255, 0);// RGB LED as green } } } //Function for generating color void color (unsigned char red, unsigned char green, unsigned char blue) { analogWrite(redPin, red*102/255); analogWrite(bluePin, blue*173/255); analogWrite(greenPin, green*173/255); }
Welcome to the tutorial on using the LD2410C human presence status detection module. This device, developed by Hi-link, is a versatile and highly sensitive tool that uses frequency modulated continuous waves (FMCW) to detect the presence of humans in a designated area.
Project description
Welcome to the tutorial on using the LD2410C human presence status detection module. This device, developed by Hi-link, is a versatile and highly sensitive tool that uses frequency modulated continuous waves (FMCW) to detect the presence of humans in a designated area.
Electronic components
Arduino micro
undefined
micro usb cable
undefined
female female dupont cables
undefined
male pins
undefined
Socket for arduino micro
undefined
PCB
undefined
Download gerber file –> $ https://rogerbit.com/wprb/wp-content/uploads/2022/03/teclado-arduino-micro.zip $
Circuit
undefined
undefined
Code
/*
* Sketch example for reporting LD2410 readings using the currently configured setup.
*
* This has been tested on the following platforms...
*
* On ESP32, connect LD2410 to GPIO pins 32 and 33
* On ESP32S2, connect LD2410 to GPIO pins 8 and 9
* On ESP32C3, connect LD2410 to GPIO pins 4 and 5
* On Arduino Leonardo or other ATmega32u4 boards, connect LD2410 to the hardware serial TX and RX pins
*
* Serial configuration for other boards will vary and should be assigned by yourself
*
* There's no example for ESP8266 as it only has one usable UART and won't boot if alternative UART pins are used for the radar.
*
* For this sketch and other examples to be useful, the board must have two usable UARTs.
*
*/
int redPin = 11; // Red pin
int greenPin = 9; // Green pin
int bluePin = 10; // Blue pin
byte com = 0;
#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 The CONFIG_IDF_TARGET 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)
{
pinMode(redPin, OUTPUT); // Set redPin as an output
pinMode(greenPin, OUTPUT); // Set greenPin as an output
pinMode(bluePin, OUTPUT); // Set bluePin as an output
MONITOR_SERIAL.begin(115200); // Serial Monitor feedback
// radar.debug(MONITOR_SERIAL); // Uncomment to show library debug info on Serial Monitor. By default, this does not show sensor readings as they are very frequent.
#if defined(ESP32)
RADAR_SERIAL.begin(256000, SERIAL_8N1, RADAR_RX_PIN, RADAR_TX_PIN); // UART for radar monitoring
#elif defined(__AVR_ATmega32U4__)
RADAR_SERIAL.begin(256000); // UART for radar monitoring
#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("Initializing LD2410 radar sensor: "));
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())//If a stationary target is detected, it turns blue
{
Serial.print(F("Stationary Target BLUE LIGHT: "));
Serial.print(radar.stationaryTargetDistance());
Serial.print(F("cm energy:"));
Serial.print(radar.stationaryTargetEnergy());
Serial.println(' ');
color(0, 0, 255); // RGB LED as blue
}
if(radar.movingTargetDetected())//If a moving target is detected, it turns red
{
Serial.print(F("MOVING TARGET DETECTED RED LIGHT!: "));
Serial.print(radar.movingTargetDistance());
Serial.print(F("cm energy:"));
Serial.print(radar.movingTargetEnergy());
color(255, 0, 0);// RGB LED as red
}
Serial.println();
}
else
{
Serial.println(F("No Target GREEN LIGHT"));//No target in range, turns green
color(0,255, 0);// RGB LED as green
}
}
}
//Function for generating color
void color (unsigned char red, unsigned char green, unsigned char blue)
{
analogWrite(redPin, red*102/255);
analogWrite(bluePin, blue*173/255);
analogWrite(greenPin, green*173/255);
}