This repository was archived by the owner on Jan 24, 2026. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed
Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change 4848#define PING_TIMEOUT 6000
4949#define ROUNDTRIP_M 5800.0f
5050#define ROUNDTRIP_CM 58
51- #define SPEED_OF_SOUND_AT_0C_M_S 331.4 // Speed of sound in m/s at 0 degrees Celsius
51+ #define HALF_SPEED_OF_SOUND_AT_0C_M_S 165.7 // Half speed of sound in m/s at 0 degrees Celsius
5252
5353#if HELPER_TARGET_IS_ESP32
5454static portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED ;
@@ -147,8 +147,8 @@ esp_err_t ultrasonic_measure_temp_compensated(const ultrasonic_sensor_t *dev, fl
147147{
148148 CHECK_ARG (dev && distance );
149149
150- // Calculate the speed of sound in m/us based on temperature
151- float speed_of_sound = (SPEED_OF_SOUND_AT_0C_M_S + 0.6 * temperature_c ) / 1000000 ; // Convert m/s to m/us
150+ // Calculate half (because of roundtrip) speed of sound in m/us based on temperature
151+ float speed_of_sound = (HALF_SPEED_OF_SOUND_AT_0C_M_S + 0.6 * temperature_c ) / 1000000 ; // Convert m/s to m/us
152152
153153 uint32_t time_us ;
154154 // Adjust max_time_us based on the recalculated speed of sound
@@ -163,8 +163,8 @@ esp_err_t ultrasonic_measure_cm_temp_compensated(const ultrasonic_sensor_t *dev,
163163{
164164 CHECK_ARG (dev && distance );
165165
166- // Calculate the speed of sound in cm/us based on temperature
167- float speed_of_sound_cm_us = ((SPEED_OF_SOUND_AT_0C_M_S + 0.6 * temperature_c ) * 100 ) / 1000000 ; // Convert m/s to cm/us
166+ // Calculate half (because of roundtrip) speed of sound in cm/us based on temperature
167+ float speed_of_sound_cm_us = ((HALF_SPEED_OF_SOUND_AT_0C_M_S + 0.6 * temperature_c ) * 100 ) / 1000000 ; // Convert m/s to cm/us
168168
169169 uint32_t time_us ;
170170 // Adjust max_time_us based on the recalculated speed of sound in cm
You can’t perform that action at this time.
0 commit comments