Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MPH Radar

PlatformIO / Arduino starter project for:

  • ESP32 DevKit v4 board
  • HLK-LD2451 24GHz vehicle radar module
  • 16x16 WS2812/WS2812B LED matrix
  • Serpentine matrix wiring, first pixel at top-left

This is meant to get the sign alive quickly, then you can tune the display and detection behavior.

File layout

mph_cam_ld2451_platformio/
├─ platformio.ini
├─ include/
│  ├─ Config.h
│  ├─ Ld2451.h
│  ├─ MatrixDisplay.h
│  └─ RuntimeConfig.h
├─ src/
│  ├─ main.cpp
│  ├─ Ld2451.cpp
│  ├─ MatrixDisplay.cpp
│  └─ RuntimeConfig.cpp
└─ README.md

Wiring

HLK-LD2451 to ESP32

Default pins are in include/Config.h.

LD2451 pin Connect to
5V Stable 5V supply, 200mA+
GND ESP32 GND and LED power supply GND
TX ESP32 GPIO13 / RADAR_RX_PIN
RX ESP32 GPIO14 / RADAR_TX_PIN
OT1 Optional, not used by this starter
OT2 Optional, not used by this starter

Important: UART crosses over. Radar TX goes to ESP32 RX. Radar RX goes to ESP32 TX.

WS2812 16x16 matrix

Matrix wire Connect to
+5V External 5V LED power supply
GND External PSU GND and ESP32 GND
DIN ESP32 GPIO33 / LED_DATA_PIN, preferably through 330 ohm resistor

A 16x16 WS2812 matrix can theoretically pull around 15A at full-white. This project uses FastLED brightness/current limiting, but you still want a real 5V supply. Do not power the matrix from the ESP32 board. That is how magic smoke gets hired full-time.

Recommended LED hardware bits:

  • 330 ohm resistor in series with the data line
  • 1000µF or larger capacitor across matrix 5V/GND
  • Common ground between ESP32, LD2451, and LED PSU
  • A 74AHCT/74HCT level shifter is recommended if the matrix is picky about 3.3V data

PlatformIO build/upload

  1. Open this folder in VS Code.
  2. Install the PlatformIO extension if needed.
  3. Connect the ESP32 DevKit v4 board by USB.
  4. Click PlatformIO: Upload.
  5. Open PlatformIO Serial Monitor at 115200 baud.

CLI:

pio run -t upload
pio device monitor -b 115200

If PlatformIO picks the wrong COM port, edit platformio.ini:

upload_port = COM5
monitor_port = COM5

Main config knobs

Edit include/Config.h.

#define LED_DATA_PIN 33
#define RADAR_RX_PIN 13
#define RADAR_TX_PIN 14

#define SPEED_LIMIT_MPH 25
#define SEVERE_OVER_LIMIT_MPH 10

#define IDLE_DISPLAY_MODE IDLE_DISPLAY_BLACK

#define MATRIX_FLIP_X 1
#define MATRIX_FLIP_Y 0

#define APPROACHING_ONLY 1
#define MIN_SPEED_KMH 0
#define MAX_USABLE_DISTANCE_M 100

Configuration AP and dashboard

The firmware starts an open Wi-Fi access point by default:

SSID: MPH-RADAR
URL:  http://192.168.4.1/

The AP also runs a captive portal. Most phones and computers will show a Sign in to network prompt after joining MPH-RADAR; opening it displays the live radar dashboard. Ordinary HTTP addresses are redirected to the dashboard. Browsers cannot redirect an HTTPS address without a certificate warning, so use the sign-in prompt or http://192.168.4.1/ if the portal does not open.

The dashboard shows current speed, target direction, distance, angle, SNR, radar-frame age, and connected-client count. It links to the password-protected admin page:

URL:      http://192.168.4.1/admin
Username: admin
Password: mphradar

Change the default login before deployment. The admin page stores settings in the ESP32's nonvolatile Preferences storage and exposes all operational options: display brightness/orientation, speed thresholds, target filtering, LD2451 configuration, AP credentials, and debug output. Physical GPIO assignments and matrix geometry remain compile-time settings in include/Config.h.

AP identity/password/channel changes are applied after using the admin page's reboot button; other settings apply immediately. The dashboard remains public to clients on the AP. The admin page, save, reboot, and OTA upgrade endpoints require HTTP Basic authentication. Because Basic authentication is not encrypted over HTTP, use a dedicated AP password if untrusted users may be nearby.

OTA firmware upgrade

Build the esp32dev environment, then open the admin page and upload:

.pio/build/esp32dev/firmware.bin

The admin page streams the binary directly into the ESP32 OTA partition. A failed or interrupted upload leaves the running firmware active. After a successful upload, the device responds to the browser and then reboots into the new firmware. Preferences-backed settings are preserved.

Matrix orientation

This starter assumes:

  • 16 columns x 16 rows
  • Pixel 0 is top-left
  • Row 0 goes left-to-right
  • Row 1 goes right-to-left
  • Alternates every row downward

Mapping lives in src/MatrixDisplay.cpp:

if (y & 0x01) {
  return (y * MATRIX_WIDTH) + (MATRIX_WIDTH - 1 - x);
}
return (y * MATRIX_WIDTH) + x;

If your display is upside-down or mirrored, first try MATRIX_FLIP_X and MATRIX_FLIP_Y in include/Config.h.

LD2451 parser behavior

The code parses LD2451 report frames:

Header:  F4 F3 F2 F1
Length:  2 bytes, little-endian
Payload: target count, alarm byte, then 5 bytes per target
Tail:    F8 F7 F6 F5

Each target is parsed as:

angle byte      -> angle degrees = byte - 0x80
distance byte   -> meters
direction byte  -> 1 = approaching, 0 = receding
speed byte      -> km/h
snr byte        -> signal-to-noise value

The sketch chooses the fastest valid approaching target by default, converts km/h to mph, smooths it slightly, and shows it on the matrix.

Optional radar configuration

By default this sketch does not rewrite your LD2451 settings.

To let the ESP32 configure the radar at boot, change:

#define CONFIGURE_RADAR_ON_BOOT 1

Then tune:

#define RADAR_CONFIG_MAX_DISTANCE_M 100
#define RADAR_CONFIG_DIRECTION 1        // 0=receding, 1=approaching, 2=both
#define RADAR_CONFIG_MIN_SPEED_KMH 0
#define RADAR_CONFIG_NO_TARGET_DELAY_S 2

First test checklist

  1. Upload firmware.
  2. Matrix should briefly show MPH, then go black or show an idle sweep depending on IDLE_DISPLAY_MODE.
  3. Serial monitor should show startup messages.
  4. Move the LD2451 near traffic or a moving target.
  5. Serial monitor should show active speed/distance values.
  6. Matrix should show MPH once a valid approaching target is detected.

If the matrix works but speed never updates:

  • Swap/check LD2451 TX/RX wiring.
  • Confirm LD2451 has 5V and common GND.
  • Confirm UART pins in Config.h match your wiring.
  • Temporarily set APPROACHING_ONLY to 0.
  • Temporarily set MIN_SPEED_KMH to 0.
  • Set DEBUG_FRAME_DUMP to 1 for full target prints.

Source references

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages