LCENJ HC-SR04 examples, 2026-09-10
Create a separate Arduino sketch folder with the same base name as each .ino file.
No third-party library. Serial Monitor: 115200 baud.
Classic ESP32: Trig GPIO26; Echo GPIO27 via divider ONLY.
Divider: Echo -> 10k ohm (1%) -> GPIO27 node -> 15k ohm (1%) -> GND.
Arduino Uno: Trig D9, Echo D10 (5V logic). Do not apply this to other 3.3V boards.
VCC: regulated 5V for the standard compatible HC-SR04. Common ground.
Confirm board labels, module version and signal levels; never infer pin order from cable colors.
The divider example gives 3.0V for 5.0V Echo; check actual levels and MCU thresholds.
INVALID means unknown. Do not replace it with 0 cm, 400 cm or a previous good value.
Median filter requires three consecutive valid samples; an invalid sample resets it.
30/35 cm thresholds are educational application choices, not guaranteed detection limits.
pulseIn is blocking with a 30000 us timeout; the main loop is not fully nonblocking.
No physical sensor test performed. Compile results are recorded in the publication report.
Not intended for safety-critical collision avoidance, vehicle parking or pump control.
