# esp32-HLK-LD2410C-example

> Test an HLK-LD2410C motion & presence sensor over WiFi via a captive portal

- Author: Mikrobot.pl
- Platform: ESP32
- Board: ESP32 Dev Module (`esp32:esp32:esp32`)
- SDK version: 3.3.6
- Tags: #esp32, #example, #captive portal, #wifi, #sensor, #hlk-ld2410c, #ld2410c
- Created: 2026-08-14
- Updated: 2026-08-14
- Favorites: 0, forks: 0
- Project page (view, flash from the browser, fork): https://flashesp.com/explore/o1fh73WFuwycEq7uObxVM
- Download all sources (zip): https://flashesp.com/api/public-projects/o1fh73WFuwycEq7uObxVM/download-sources/

## Source files

- [libraries_lock.json (85 B)](https://flashesp.com/explore/o1fh73WFuwycEq7uObxVM/files/qGf79RMqtE4oUTw2CX2Fv.md)
- [main.ino (10.2 KB)](https://flashesp.com/explore/o1fh73WFuwycEq7uObxVM/files/saA6ENWKKc8AKSOI6ieHY.md)
- readme.md (4.5 KB)

## README

# ESP32 LD2410C Radar Tester — Captive Portal
### Verify an HLK-LD2410C 24 GHz presence radar over WiFi with a captive portal

This project turns an **ESP32 Dev Board** into a small WiFi-based
**tester for the HLK-LD2410C 24 GHz radar module**.
When powered, the ESP32 creates an **open WiFi Access Point** and a **captive portal**.
As soon as a device connects to the AP, a live dashboard appears that shows whether the
radar is **working correctly** — connection status, human presence/motion detection,
target distances and signal energy.

---

## ⭐ Features

- **Open WiFi Access Point** (no password)
  - SSID: `ESP32-LD2410C`
- **Captive portal**
  - Any URL request (e.g. `google.com`) is redirected to the tester page
  - Works with Android / iOS / Windows / Linux
- **Live radar dashboard** (auto-refreshes every 500 ms, no page reload)
  - **Module health** — green dot = the module is streaming valid UART data (= healthy)
  - **Presence detection** — shows if a person is detected (motion or micro-motion)
  - **Moving target** — distance + signal energy (with bar graph)
  - **Stationary target** — distance + signal energy for a motionless person
  - **Detection distance** — overall measured distance
- **On-board LED** lights up whenever presence is detected (extra at-a-glance indicator)
- No external network or internet required

---

## 📦 Hardware requirements

- **ESP32 Dev Board** (e.g. ESP32-DevKitC)
- **HLK-LD2410C** 24 GHz presence radar module
- Jumper wires

The LD2410C output logic level is **3.3 V**, so it connects directly to the ESP32
without a level shifter.

### Wiring

| LD2410C | ESP32 (DevKitC)   | Notes                                     |
|---------|-------------------|-------------------------------------------|
| VCC     | 5V / VIN          | Module runs on 5–12 V DC                   |
| GND     | GND               | Common ground (required!)                  |
| TX      | **GPIO16 (RX2)**  | Radar → ESP (hardware UART2)              |
| RX      | **GPIO17 (TX2)**  | ESP → Radar (hardware UART2)             |
| OUT     | *(optional)* GPIO | Hardware presence signal (not required)   |

---

## ⚙️ Key configuration in the code

```cpp
#define RADAR_SERIAL   Serial2     // hardware UART2
#define RADAR_BAUD     256000      // LD2410C default baud rate (8N1)
#define RADAR_RX_PIN   16          // ESP32 RX2  <- LD2410C TX
#define RADAR_TX_PIN   17          // ESP32 TX2  -> LD2410C RX
#define LED_PIN        2           // on-board LED (GPIO2), active HIGH

const char* ap_ssid = "ESP32-LD2410C"; // open AP, no password
```

---

## 🚀 How to use

1. Wire the LD2410C to the ESP32 as shown above.
2. Connect the board to your computer.
3. Click **Flash to Device**.
4. Select the appropriate port in the popup window.
5. Click **Install main**.
6. Power the board. On your phone/laptop, connect to the WiFi network
   **`ESP32-LD2410C`** (open, no password).
7. A captive portal page opens automatically (or browse to `http://192.168.4.1`).
8. Watch the dashboard:
   - **Green dot + "Module HEALTHY"** → the module is alive and streaming data.
   - Walk in front of the sensor → **presence / moving target** updates.
   - Stand still → after a moment the **stationary (micro-motion)** target reacts.

---

## 🧪 What "working" looks like

| Indicator            | Healthy result                                          |
|----------------------|---------------------------------------------------------|
| Connection dot       | Green — UART frames received continuously               |
| Presence             | Toggles between "Presence detected" and "No presence"   |
| Moving distance       | Changes as you move (up to ~5 m, ±60°)                 |
| Stationary distance  | Non-zero when a motionless person is nearby             |
| On-board LED         | Lights up while presence is detected                    |

If the dot stays **red** ("No data from module"), check the wiring (TX↔RX swapped?),
the 5 V supply, the common ground, and that the baud rate is `256000`
(some LD2410C units ship at `115200`).

---

## 📝 Notes

- Detection: up to **5 m**, configurable in **0.75 m** range gates, **±60°** coverage.
- The LD2410C also supports BLE and a configuration protocol; this sketch only reads the
  default cyclic reporting frames, which is enough to confirm the module is functional.
- This is the **ESP32 twin** of the ESP8266 version. The only real differences are the
  WiFi/WebServer libraries and the UART: the ESP32 uses a dedicated **UART2 (GPIO16/17)**,
  so no `Serial.swap()` trick is needed.
