HLK-LD2410 mmWave radar sensor connected to ESP32 for smart home presence detection

Figure 1: The HLK-LD2410 mmWave sensor can detect human presence even when the person is completely still, solving the biggest flaw of traditional PIR sensors.

🔒 Privacy-First & Safe

Unlike cameras, mmWave radar sensors do not capture optical images or video. They only detect micro-movements (like breathing or heartbeat) via radio waves, making them the ultimate privacy-safe solution for bedrooms, bathrooms, and offices.

Welcome back to TechFix Hub! If you've ever built a smart light that turns off while you're sitting still reading a book, you've been a victim of the traditional PIR (Passive Infrared) sensor. PIR sensors only detect changes in heat (movement). If you don't move, the lights go out, and you have to wave your arms like a maniac to turn them back on.

Enter the mmWave (millimeter-wave) radar sensor. Specifically, the incredibly affordable and powerful HLK-LD2410. In this guide, we will interface this 24GHz radar module with an ESP32 to create a rock-solid, latency-free presence detection system that knows you are in the room, even if you are asleep.

📡 1. mmWave vs. PIR: Why the Upgrade is Mandatory

The HLK-LD2410 uses FMCW (Frequency Modulated Continuous Wave) radar technology. Here is why it outperforms PIR in every metric:

Feature Traditional PIR Sensor HLK-LD2410 (mmWave)
Stationary Detection ❌ Fails (turns off) ✅ Detects breathing/heartbeat
Through Obstacles ❌ Blocked by walls/wood ✅ Penetrates drywall, plastic, wood
Distance & Zones Fixed, wide angle Configurable (up to 6m), multiple gates
Privacy High High (No optical data)

🛠️ 2. Bill of Materials (BOM)

  • Microcontroller: ESP32 DevKit V1 (or ESP32-C3 for smaller projects).
  • Sensor: Hi-Link HLK-LD2410 (24GHz Smart Wave Motion Sensor Module).
  • Output Indicator: 5V Relay Module or WS2812B LED strip (to visualize presence).
  • Wiring: Jumper wires (Female-to-Female) and a breadboard.
  • Power: Standard 5V USB power supply (the LD2410 draws ~80mA, well within ESP32 USB limits).

🔌 3. Wiring the HLK-LD2410 to ESP32

The LD2410 communicates via UART (Serial). We will use the ESP32's hardware Serial2 to keep the main USB serial port free for debugging.

HLK-LD2410 Pin  ➔  ESP32 Pin
--------------------------------
5V (VCC)        ➔  5V (or VIN)
GND             ➔  GND
TX              ➔  GPIO 16 (RX2)
RX              ➔  GPIO 17 (TX2)
OUT             ➔  Not connected (we use serial data for advanced control)
      

⚠️ Note: The LD2410's logic pins (TX/RX) are 3.3V tolerant, so connecting them directly to the ESP32's GPIOs is perfectly safe, even though the module is powered by 5V.

💻 4. The Code: Parsing Radar Data

While you can use the sensor's "OUT" pin for a simple HIGH/LOW signal, the real power lies in reading the serial data to get exact distance and confidence levels. Here is a streamlined Arduino sketch to parse the target data:

#include 

HardwareSerial RadarSerial(2); // Use UART2

void setup() {
  Serial.begin(115200);
  RadarSerial.begin(256000, SERIAL_8N1, 16, 17); // LD2410 default baud rate
  
  Serial.println("Initializing LD2410 mmWave Sensor...");
  delay(1000);
  
  // Enable engineering mode to get detailed distance data
  byte enableCmd[] = {0xFD, 0xFC, 0xFB, 0xFA, 0x02, 0x00, 0x62, 0x00, 0x04, 0x03, 0x02, 0x01};
  RadarSerial.write(enableCmd, sizeof(enableCmd));
}

void loop() {
  if (RadarSerial.available() >= 12) {
    byte header[4] = {RadarSerial.read(), RadarSerial.read(), RadarSerial.read(), RadarSerial.read()};
    
    // Check for valid data frame header
    if (header[0] == 0xF4 && header[1] == 0xF3 && header[2] == 0xF2 && header[3] == 0xF1) {
      byte targetType = RadarSerial.read(); // 0x01 = Moving, 0x02 = Stationary, 0x03 = Moving+Stationary
      int distance = RadarSerial.read();    // Distance in cm
      int energy = RadarSerial.read();      // Energy/Confidence level
      
      // Read remaining bytes and checksum (simplified for this example)
      for(int i=0; i<5 0x01="" 0x02="" 200="" 200cm="" arget:="" automation:="" cm="" distance="" else="" energy:="" energy="" example="" i="" if="" is="" istance:="" light="" on="" oving="" radarserial.read="" reathing="" serial.print="" serial.println="" someone="" stationary="" targettype="=" tationary="" turn="" within=""> 30) {
        // digitalWrite(RELAY_PIN, HIGH);
      }
    }
  }
}
      

🚀 5. The "TechFix Hub" Upgrade: Home Assistant & Multi-Zone

Don't just stop at the Serial Monitor. Elevate this project to a professional smart home component:

  • ESPHome Integration (Recommended): Instead of raw Arduino code, flash the ESP32 with ESPHome. The LD2410 has native, first-class support in ESPHome, allowing you to configure motion/stationary thresholds, distances, and timeouts via simple YAML, which then exposes directly to Home Assistant as a `binary_sensor`.
  • MQTT Automation: If using Arduino, use the `PubSubClient` library to publish the "Presence" state and "Distance" value to an MQTT broker. In Home Assistant, create an automation: "If presence is ON for > 30 seconds, keep lights on. If OFF for > 2 minutes, turn off."
  • Hidden Installation: Because 24GHz radar penetrates drywall and plastic, you can mount the sensor behind a wall painting, inside a ceiling fixture, or behind a TV, making your smart home truly invisible and aesthetic.

🔗 Complete Your Smart Home on TechFix Hub

Pair this presence sensor with our other automation guides:

✅ Conclusion

Upgrading from PIR to mmWave radar is the single most impactful change you can make to a DIY smart home. The HLK-LD2410, paired with the processing power of the ESP32, eliminates the frustration of lights turning off on stationary users. By parsing the serial data for distance and energy, you gain granular control over your environment, paving the way for truly intelligent, context-aware home automation.

🛠️ Building your own presence detection system?

Struggling with serial parsing, ESPHome YAML configuration, or Home Assistant automations? Drop your questions in the comments below, and the TechFix Hub community will help you troubleshoot!

Keywords: mmWave Radar HLK-LD2410 ESP32 Smart Home Presence Detection

Bottom Ad [Post Page]