Aller au contenu
Bamba IoT

LD2410 : câblage ESP32, code et brochage

Présence humaineUART

Le LD2410 est un capteur radar à ondes millimétriques pour la détection de présence humaine, prenant en charge la détection de cibles fixes et mobiles.

Photo du LD2410

Démarrer

Câblage vers l’ESP32

Câblage vers l’ESP32
Broche du capteurBroche ESP32StatutRôle
VCC5VRequisAlimentation (5V)
GNDGNDRequisSol
TXGPIO16 (RX2)RequisTransmission du capteur à la réception ESP32
RXGPIO17 (TX2)RequisLe capteur reçoit de la transmission ESP32
OUTGPIO18OptionnelSortie de présence numérique (en option)
Schéma de câblage du LD2410

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_MODE
MyLD2410 sensor(sensorSerial, true);
#else
MyLD2410 sensor(sensorSerial);
#endif

unsigned long nextPrint = 0, printEvery = 1000;  // print every second

void 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
BrocheTypeDescription
VCCPowerEntrée d'alimentation5 V CC
GNDPowerConnexion à la terre
TXCommunicationTransmission UARTEnvoie les données du capteur (se connecte à l'ESP32 RX)
RXCommunicationRéception UARTReçoit les commandes (se connecte à ESP32 TX)
OUTCommunicationSortie de présence numériqueÉLEVÉ lorsque présence détectée (facultatif)
Brochage du LD2410

Caractéristiques

Le LD2410 est un capteur radar à ondes millimétriques pour la détection de présence humaine, prenant en charge la détection de cibles fixes et mobiles. Il utilise la communication UART et est idéal pour les systèmes domotiques intelligents.

Caractéristiques
CaractéristiqueValeur
OutputUART, Optional GPIO
InterfaceUART (256000 baud)
Pin Width1.27mm
Dimensions35mm × 7mm
Resolution0.2m or 0.75m gate intervals
Power Supply5V DC
Detection Field±60°
Detection RangeUp to 5 meters
Operating Temperature-20°C to +85°C