Le LD2410B est un capteur radar à ondes millimétriques pour la détection de présence humaine avec une prise en charge de configuration Bluetooth améliorée.
Démarrer
Câblage vers l’ESP32
Câblage vers l’ESP32
Broche du capteur
Broche ESP32
Statut
Rôle
VCC
5V
Requis
Alimentation (5V)
GND
GND
Requis
Sol
TX
GPIO16 (RX2)
Requis
Transmission du capteur à la réception ESP32
RX
GPIO17 (TX2)
Requis
Le capteur reçoit de la transmission ESP32
OUT
GPIO18
Optionnel
Sortie de présence numérique (en option)
Code
Bibliothèques à installer
MyLD2410 · Iavor Veltchev
Depuis le gestionnaire de bibliothèques de l’IDE Arduino.
basic.ino
#if defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_AVR_LEONARDO)//ARDUINO_SAMD_NANO_33_IOT RX_PIN is D1, TX_PIN is D0//ARDUINO_AVR_LEONARDO RX_PIN(RXI) is D0, TX_PIN(TXO) is D1#define sensorSerial Serial1#elif defined(ARDUINO_XIAO_ESP32C3) || defined(ARDUINO_XIAO_ESP32C6)//RX_PIN is D7, TX_PIN is D6#define sensorSerial Serial0#elif defined(ESP32)//Other ESP32 device - choose available GPIO pins#define sensorSerial Serial1#if defined(ARDUINO_ESP32S3_DEV)#define RX_PIN 18#define TX_PIN 17#else#define RX_PIN 16#define TX_PIN 17#endif#else#error "This sketch only works on ESP32, Arduino Nano 33IoT, and Arduino Leonardo (Pro-Micro)"#endif// User defines// #define DEBUG_MODE#define ENHANCED_MODE#define SERIAL_BAUD_RATE 115200//Change the communication baud rate here, if necessary//#define LD2410_BAUD_RATE 256000#include "MyLD2410.h"#ifdef DEBUG_MODEMyLD2410 sensor(sensorSerial, true);#elseMyLD2410 sensor(sensorSerial);#endifunsigned long nextPrint = 0, printEvery = 1000; // print every secondvoid printValue(const byte &val) { Serial.print(' '); Serial.print(val);}void printData() { Serial.print(sensor.statusString()); if (sensor.presenceDetected()) { Serial.print(", distance: "); Serial.print(sensor.detectedDistance()); Serial.print("cm"); } Serial.println(); if (sensor.movingTargetDetected()) { Serial.print(" MOVING = "); Serial.print(sensor.movingTargetSignal()); Serial.print("@"); Serial.print(sensor.movingTargetDistance()); Serial.print("cm "); if (sensor.inEnhancedMode()) { Serial.print(" signals->["); sensor.getMovingSignals().forEach(printValue); Serial.print(" ] thresholds:["); sensor.getMovingThresholds().forEach(printValue); Serial.print(" ]"); } Serial.println(); } if (sensor.stationaryTargetDetected()) { Serial.print(" STATIONARY= "); Serial.print(sensor.stationaryTargetSignal()); Serial.print("@"); Serial.print(sensor.stationaryTargetDistance()); Serial.print("cm "); if (sensor.inEnhancedMode()) { Serial.print(" signals->["); sensor.getStationarySignals().forEach(printValue); Serial.print(" ] thresholds:["); sensor.getStationaryThresholds().forEach(printValue); Serial.print(" ]"); } Serial.println(); } if (sensor.inEnhancedMode() && (sensor.getFirmwareMajor() > 1)) { Serial.print("Light level: "); Serial.println(sensor.getLightLevel()); Serial.print("Output level: "); Serial.println((sensor.getOutLevel()) ? "HIGH" : "LOW"); } Serial.println();}void setup() { Serial.begin(SERIAL_BAUD_RATE);#if defined(ARDUINO_XIAO_ESP32C3) || defined(ARDUINO_XIAO_ESP32C6) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_AVR_LEONARDO) sensorSerial.begin(LD2410_BAUD_RATE);#else sensorSerial.begin(LD2410_BAUD_RATE, SERIAL_8N1, RX_PIN, TX_PIN);#endif delay(2000); Serial.println(__FILE__); if (!sensor.begin()) { Serial.println("Failed to communicate with the sensor."); while (true) {} }#ifdef ENHANCED_MODE sensor.enhancedMode();#else sensor.enhancedMode(false);#endif delay(nextPrint);}void loop() { if ((sensor.check() == MyLD2410::Response::DATA) && (millis() > nextPrint)) { nextPrint = millis() + printEvery; printData(); }}
Brochage
Brochage
Broche
Type
Description
VCC
Power
Entrée d'alimentation5 V CC
GND
Power
Connexion à la terre
TX
Communication
Transmission UARTEnvoie les données du capteur (se connecte à l'ESP32 RX)
RX
Communication
Réception UARTReçoit les commandes (se connecte à ESP32 TX)
OUT
Communication
Sortie de présence numériqueÉLEVÉ lorsque présence détectée (facultatif)
Caractéristiques
Le LD2410B est un capteur radar à ondes millimétriques pour la détection de présence humaine avec une prise en charge de configuration Bluetooth améliorée. Il maintient la communication UART tout en offrant une configuration et un réglage sans fil via BLE.