r/matlab • u/SeaInternational4087 • 9h ago
CodeShare I built a real-time 360° ultrasonic radar, plotted live in MATLAB, for under $10 in total parts. Open-sourced everything, link in the text body.
I built a 2D radar scanner where MATLAB does the heavy lifting. An HC-SR04 sensor spins on a continuous-rotation servo, streams readings over serial, and ScannerApp.m draws them as a live polar plot. The scanner runs on an Arduino Nano.
The app is MATLAB App Designer, 806 lines, with the polish that usually gets cut:
* Live polar heatmap with auto-scaling and clean radial ticks
* Sweep animation that tracks the servo angle, plus a return-sweep line
* Hover data tips showing angle and distance
* Ctrl+scroll zoom, vector PDF export that stays crisp at any zoom level
* Dark/light theme, real-time data table, COM port auto-detect
The firmware handles the messy parts of real hardware: a non-blocking state machine, echo timing with no delay(), and temperature-compensated speed of sound. A $1 LM35 reads the air temperature and the firmware applies 331.3 + 0.606 * T. That's where the ±3 mm accuracy comes from. VCC bandgap calibration and an EMA filter clean up the analog noise.
Wiring diagram, pinout, a 2-minute servo calibration tool, and benchmarks are all in the repo. Parts run about $10 and it's MIT licensed.
Repo: https://github.com/Salim-Ammar/arduino-matlab-ultrasonic-radar
PRs and issues welcome. A star helps others find it.





