ESP32 and LD2410 UART - Sensors unknown

Hi all,

I have passed the last 3 days completely immersed in making an ESP32 and an LD241oC work without success.

I have read tons of posts and flashed more than 30 differenct configs, without luck.

I tried also different ESP32 and LD2410C sensors.

The issue I have is that in HA, the sensors are shown as Unknown

image

My yaml config is:

esphome:
  name: ld2410-esp32
  friendly_name: ld2410-esp32

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:
  encryption:
    key: "IArm3ZGuqL1HLZXXbu4/L0ciw1TDSagu6THKP8LnFdo="

ota:
  platform: esphome
  password: "3373716c7967d461cf4bd0ce1ba42e9a"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Ld2410-Esp32 Fallback Hotspot"
    password: "AhxmD317i7r1"

captive_portal:
   
uart:
  id: ld2410_uart
  tx_pin: 1
  rx_pin: 3
  baud_rate: 256000
  parity: NONE
  stop_bits: 1
  debug:
    direction: BOTH
    dummy_receiver: false
    sequence:
      - lambda: UARTDebug::log_string(direction, bytes);

 
ld2410:
  uart_id: ld2410_uart
  throttle: 1500ms
  id: ld2410_comp
 
select:
  - platform: ld2410
    distance_resolution:
      name: distance resolution
    baud_rate:
      name: baud rate
    light_function:
      name: light function
    out_pin_level:
      name: out pin level
 
button:
  - platform: ld2410
    factory_reset:
      name: "factory reset"
    restart:
      name: "restart"
    query_params:
      name: query params
 
text_sensor:
  - platform: ld2410
    version:
      name: "presenece sensor version"
    mac_address:
      name: "presenece sensor mac address"
 
switch:
  - platform: ld2410
    engineering_mode:
      name: "engineering mode"
    bluetooth:
      name: control Bluetooth
 
sensor:
  - platform: ld2410
    moving_distance:
      name: "Moving distance (cm)"
    still_distance:
      name: "Still Distance (cm)"
    moving_energy:
      name: "Move Energy (%)"
    still_energy:
      name: "Still Energy (%)"
    detection_distance:
      name: "Distance Detection (cm)"

 
binary_sensor:
 
  - platform: ld2410
    has_target:
      name: Presence
    has_moving_target:
      name: Moving Target
    has_still_target:
      name: Still Target

My logs are the following:

INFO ESPHome 2024.10.0
INFO Reading configuration /config/esphome-web-25f128.yaml...
INFO Starting log output from ld2410-esp32.local using esphome API
INFO Successfully connected to ld2410-esp32 @ 192.168.68.90 in 3.018s
INFO Successful handshake with ld2410-esp32 @ 192.168.68.90 in 0.105s
[18:04:31][I][app:100]: ESPHome version 2024.10.0 compiled on Oct 18 2024, 17:49:18
[18:04:31][C][wifi:600]: WiFi:
[18:04:31][C][wifi:428]:   Local MAC: C8:2E:18:25:F1:28
[18:04:31][C][wifi:433]:   SSID: [redacted]
[18:04:31][C][wifi:436]:   IP Address: 192.168.68.90
[18:04:31][C][wifi:440]:   BSSID: [redacted]
[18:04:31][C][wifi:441]:   Hostname: 'ld2410-esp32'
[18:04:31][C][wifi:443]:   Signal strength: -58 dB ▂▄▆█
[18:04:31][C][wifi:447]:   Channel: 2
[18:04:31][C][wifi:448]:   Subnet: 255.255.252.0
[18:04:31][C][wifi:449]:   Gateway: 192.168.68.1
[18:04:31][C][wifi:450]:   DNS1: 80.58.0.33
[18:04:31][C][wifi:451]:   DNS2: 80.58.32.97
[18:04:31][C][logger:185]: Logger:
[18:04:31][C][logger:186]:   Level: DEBUG
[18:04:31][C][logger:188]:   Log Baud Rate: 0
[18:04:31][C][logger:189]:   Hardware UART: UART0
[18:04:31][C][uart.arduino_esp32:151]: UART Bus 0:
[18:04:31][C][uart.arduino_esp32:152]:   TX Pin: GPIO1
[18:04:31][C][uart.arduino_esp32:153]:   RX Pin: GPIO3
[18:04:31][C][uart.arduino_esp32:155]:   RX Buffer Size: 256
[18:04:31][C][uart.arduino_esp32:157]:   Baud Rate: 256000 baud
[18:04:31][C][uart.arduino_esp32:158]:   Data Bits: 8
[18:04:31][C][uart.arduino_esp32:159]:   Parity: NONE
[18:04:31][C][uart.arduino_esp32:160]:   Stop bits: 1
[18:04:31][C][ld2410:022]: LD2410:
[18:04:31][C][ld2410:024]:   TargetBinarySensor 'Presence'
[18:04:31][C][ld2410:024]:     Device Class: 'occupancy'
[18:04:31][C][ld2410:025]:   MovingTargetBinarySensor 'Moving Target'
[18:04:31][C][ld2410:025]:     Device Class: 'motion'
[18:04:31][C][ld2410:026]:   StillTargetBinarySensor 'Still Target'
[18:04:31][C][ld2410:026]:     Device Class: 'occupancy'
[18:04:31][C][ld2410:068]:   EngineeringModeSwitch 'engineering mode'
[18:04:31][C][ld2410:070]:     Icon: 'mdi:pulse'
[18:04:31][C][ld2410:079]:     Device Class: 'switch'
[18:04:31][C][ld2410:091]:     Restore Mode: always OFF
[18:04:31][C][ld2410:068]:   BluetoothSwitch 'control Bluetooth'
[18:04:31][C][ld2410:070]:     Icon: 'mdi:bluetooth'
[18:04:31][C][ld2410:079]:     Device Class: 'switch'
[18:04:31][C][ld2410:091]:     Restore Mode: always OFF
[18:04:31][C][ld2410:034]:   ResetButton 'factory reset'
[18:04:31][C][ld2410:034]:     Icon: 'mdi:restart-alert'
[18:04:31][C][ld2410:035]:   RestartButton 'restart'
[18:04:31][C][ld2410:035]:     Icon: 'mdi:restart'
[18:04:31][C][ld2410:036]:   QueryButton 'query params'
[18:04:31][C][ld2410:036]:     Icon: 'mdi:database'
[18:04:32][C][ld2410:040]:   MovingTargetDistanceSensor 'Moving distance (cm)'
[18:04:32][C][ld2410:075]:   Throttle_ : 1500ms
[18:04:32][C][ld2410:076]:   MAC Address : 
[18:04:32][C][ld2410:077]:   Firmware Version : 
[18:04:32][C][captive_portal:089]: Captive Portal:
[18:04:32][C][mdns:116]: mDNS:
[18:04:32][C][mdns:117]:   Hostname: ld2410-esp32
[18:04:32][C][esphome.ota:073]: Over-The-Air updates:
[18:04:32][C][esphome.ota:074]:   Address: ld2410-esp32.local:3232
[18:04:32][C][esphome.ota:075]:   Version: 2
[18:04:32][C][esphome.ota:078]:   Password configured
[18:04:32][D][uart_debug:158]: >>> "\xFD\xFC\xFB\xFA\x04\x00\xFF\x00\x01\x00\x04\x03\x02\x01\xFD\xFC\xFB\xFA\x02\x00\xA0\x00\x04\x03\x02\x01\xFD\xFC\xFB\xFA\x04\x00\xA5\x00\x01\x00\x04\x03\x02\x01\xFD\xFC\xFB\xFA\x02\x00\xAB\x00\x04\x03\x02\x01\xFD\xFC\xFB\xFA\x02\x00\xAE\x00\x04\x03\x02\x01\xFD\xFC\xFB\xFA\x02\x00a\x00\x04\x03\x02\x01\xFD\xFC\xFB\xFA\x02\x00\xFE\x00\x04\x03\x02\x01"
[18:04:32][C][safe_mode:018]: Safe Mode:
[18:04:32][C][safe_mode:020]:   Boot considered successful after 60 seconds
[18:04:32][C][safe_mode:021]:   Invoke after 10 boot attempts
[18:04:32][C][safe_mode:023]:   Remain in safe mode for 300 seconds
[18:04:32][C][api:140]: API Server:

I have tried TX and RX 1&3 and 17&16 without luck in any of them.

I don’t know what else to try, any idea?

Thanks

GPIO 1 and 3 are almost always shared with usb, and have logging enabled to it, so they may give problems. If you do use them, when usb flashing, disconnect the wires, and add this to the yaml. OTA flashing is no problem afterward.

 logger:
  baud_rate: 0

My advice is to go with gpio16/17. Furthermore, the most made mistake is that when connecting, RX should go to TX and TX should go to RX. If your config does not work, try switching the wires.

Second often made mistake: GPIO numbers are not always the same as pin numbers. Check if you:

  1. have the right documentation for the board. Also becasue there are many fake boards using popular names, but are very different
  2. check which pin is which gpio

Third: measure voltage of where you connect 5v. Is it really 5v? Make sure it is properly powered.

ps. I made all of these mistakes. So if you only did one or two wrong, you are ahead of me :wink:

1 Like

Hi Edwin_D thank you very much for your answer!!

I have done all of your recommendations, one by one, just to double check if I missed them before but no luck.

Any other clue to keep looking for? I have also tried with 2 different brand ESP32 boards and als an ESP8266, with the same result. I tested also 3 LD2410C.

Do you think it could be the HA implementation? is a docker one and the ESPHome is installed in a separate container, ut as per my understanding ESPHome container is just to manage and facilitate configuration of ESP devices…

Thanks

Send a picture of the wire connection

Here you go!

I have also tried modifying the settings like baud rate and distance resolution in HA and I can see them changed in the HLK App, so at least in one direction the communication is working.

ESPHome is not relevant other than for building and flashing the firmware. And if HA created the sensors, your HA api is working too. If you can communicate with the board and the app can see that through bluetooth, than at least the communication from the esp to the board is working. That leaves the communication the other way around as a possibility or a faulty sensor, as far as I can tell.

Did you check to see if you can get the out pin working? That does not rely on the UART but on the sensor alone. If you can get that to work, the sensor should work and the UART is still the problem. If you can’t then you either did that one wire wrong too :wink: or the sensor is dead.

You did not show the yaml for the uart you flashed with the picture, show that too just to be sure.

Thank you,

This is yaml I have configured now:

esphome:
  name: ld2410-esp32v2
  friendly_name: ld2410-esp32v2

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "IArm3ZGuqL1HLZXXbu4/L0ciw1TDSagu6THKP8LnFdo="

ota:
  platform: esphome
  password: "3373716c7967d461cf4bd0ce1ba42e9a"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Ld2410-Esp32 Fallback Hotspot"
    password: "AhxmD317i7r1"

captive_portal:
   
uart:
  id: ld2410_uart
  tx_pin: GPIO16
  rx_pin: GPIO17
  baud_rate: 256000
  parity: NONE
  stop_bits: 1
  debug:
    direction: BOTH
    dummy_receiver: false
    sequence:
      - lambda: UARTDebug::log_string(direction, bytes);

 
ld2410:
  uart_id: ld2410_uart
  throttle: 1500ms
  id: ld2410_comp
 
select:
  - platform: ld2410
    distance_resolution:
      name: distance resolution
    baud_rate:
      name: baud rate
    light_function:
      name: light function
    out_pin_level:
      name: out pin level
 
button:
  - platform: ld2410
    factory_reset:
      name: "factory reset"
    restart:
      name: "restart"
    query_params:
      name: query params
 
text_sensor:
  - platform: ld2410
    version:
      name: "presenece sensor version"
    mac_address:
      name: "presenece sensor mac address"
 
switch:
  - platform: ld2410
    engineering_mode:
      name: "engineering mode"
    bluetooth:
      name: control Bluetooth
 
sensor:
  - platform: ld2410
    moving_distance:
      name: "Moving distance (cm)"
    still_distance:
      name: "Still Distance (cm)"
    moving_energy:
      name: "Move Energy (%)"
    still_energy:
      name: "Still Energy (%)"
    detection_distance:
      name: "Distance Detection (cm)"

 
binary_sensor:
 
  - platform: ld2410
    has_target:
      name: Presence
    has_moving_target:
      name: Moving Target
    has_still_target:
      name: Still Target

An adittional test I’ve done is, when I change a config in HA it is updated in the APP, however when I updated it in the app it is not updated in HA, so communication is just working from the ESP to the sensor and not the other way around.

One question, how can I try the out pin? how should I connect and configure the esp?

It is very strange that all 3 sensors I have tried are wrong, maybe they are as they all where bought together

I have this for the out pin to create a binary presence sensor:

binary_sensor:
  - platform: gpio
    pin: 
      number: 25
      mode: 
        input: true
    name: Presence pin
    device_class: occupancy  

As for the RX/TX settings: I never can figure if in the yaml you need to name rx/tx on the esp side or what you connected to it. I figured you specify the ESP side, not the connected board. So I very well may have it wrong, but at least it works for me. And I have them opposite of yours. tx =17 and rx =16. Which also probably means I have the wires the other way around at the board side. But I do wonder how that could have worked sending data to your board if it was wrong.

 uart:
  stop_bits: 1
  parity: NONE
  tx_pin: 17
  rx_pin: 16
  baud_rate: 256000

Esp board pins.
Gpio17 is default UART2 Tx-pin, so the pin that is transmitting data . Gpio16 is default UART2 Rx-pin, receiving data from sensor.

Open the logger to see if you have serial traffic with sensor.

Changed the pins as suggested and include the binary sensor.

The Out pin is working.

When I send a change request for distance resolution from HA this is are the logs

[09:33:32][D][select:062]: 'distance resolution' - Setting
[09:33:32][D][select:115]: 'distance resolution' - Set selected option to: 0.2m
[09:33:32][D][select:015]: 'distance resolution': Sending state 0.2m (index 0)
[09:33:32][W][component:237]: Component api took a long time for an operation (119 ms).
[09:33:32][W][component:238]: Components should block for at most 30 ms.
[09:33:33][D][uart_debug:158]: >>> "\xFD\xFC\xFB\xFA\x04\x00\xFF\x00\x01\x00\x04\x03\x02\x01\xFD\xFC\xFB\xFA\x04\x00\xAA\x00\x01\x00\x04\x03\x02\x01"
[09:33:33][W][component:237]: Component ld2410 took a long time for an operation (101 ms).
[09:33:33][W][component:238]: Components should block for at most 30 ms.
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state OFF
[09:33:33][D][uart_debug:158]: >>> "\xFD\xFC\xFB\xFA\x04\x00\xFF\x00\x01\x00\x04\x03\x02\x01\xFD\xFC\xFB\xFA\x02\x00\xA3\x00\x04\x03\x02\x01"
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state ON
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state OFF
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state ON
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state OFF
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state ON
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state OFF
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state ON
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state OFF
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state ON
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state OFF
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state ON
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state OFF
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state ON
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state OFF
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state ON
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state OFF
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state ON
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state OFF
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state ON
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state OFF
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state ON
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state OFF
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state ON
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state OFF
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state ON
[09:33:33][D][binary_sensor:036]: 'Presence pin': Sending state OFF
[09:33:34][W][component:237]: Component ld2410 took a long time for an operation (351 ms).
[09:33:34][W][component:238]: Components should block for at most 30 ms.
[09:33:34][D][uart_debug:158]: >>> "\xFD\xFC\xFB\xFA\x04\x00\xFF\x00\x01\x00\x04\x03\x02\x01\xFD\xFC\xFB\xFA\x02\x00\xA0\x00\x04\x03\x02\x01\xFD\xFC\xFB\xFA\x04\x00\xA5\x00\x01\x00\x04\x03\x02\x01\xFD\xFC\xFB\xFA\x02\x00\xAB\x00\x04\x03\x02\x01\xFD\xFC\xFB\xFA\x02\x00\xAE\x00\x04\x03\x02\x01\xFD\xFC\xFB\xFA\x02\x00a\x00\x04\x03\x02\x01\xFD\xFC\xFB\xFA\x02\x00\xFE\x00\x04\x03\x02\x01"
[09:33:34][D][binary_sensor:036]: 'Presence pin': Sending state ON

@Karosm this is what you mean by open the logger?

Somewhere I read that the tx/rx voltage should be 3.3v, I have measured it on the LD2410 when disconnect from ESP and 2.63v, when connected is 3.3v.

I have changed USB C, cables and plug adapters as well with no luck

Yep.
So you have Gpio17 configured as tx in uart component? And it’s wired to rx pin of your sensor?

yes

[09:33:24][C][uart.arduino_esp32:152]:   TX Pin: GPIO17
[09:33:24][C][uart.arduino_esp32:153]:   RX Pin: GPIO16

Connected 17 to RX and 16 to TX

Your sensor has a voltage regulator. You need to power it at minimum 5V. And it regulates the voltage to 3.3V, so rx/tx voltages are compatible with Esp32.

ps. Don’t ever think that all other sensors work like that, most of them don’t have voltage regulator!

Something else entirely: is the presence pin actually showing presense? If I read your logs right changes value tens of times in one second?

Are you sure you don’t have sensor tx pin connected to Esp32 Presence pin???
Pull them out from the breadboard and wire them directly.

@Karosm This are the actual connections.

@Edwin_D the binary sensor works good, if I am not in the room it does not detect presence and if I am it does. In the app it behaves similarly, it goes on an off continuously

If you have female jumper wires, wire them directly, breadboards are not reliable.
Also, measure Vcc voltage of your sensor.

Until you receive uart data from the sensor, you have something wrong with hardware.

Same thing with female jumpers

voltage measured in the sensor is between 4.99v and 5.02v

Good.
And logger?