The HC-SR04 is a stopwatch attached to a loudspeaker, not a rangefinder. Wiring for Arduino, ESP32 and ESP8266, three levels of code, temperature compensation, beam limits and a troubleshooting table built from real failures.
HC-SR04 Ultrasonic Sensor: Wiring, Code and Real Accuracy