Ultrasonic sensor always reads 2.4 cm

I’m trying to get an ultrasonic sensor working HC-SR04.

I’m only seeing 2.4 cm on the dashboard of HA.

If I look at logs I see this coming back from the sensor. At this moment it is stationary with no movement at all around it.

[21:39:22][D][ultrasonic.sensor:040]: ‘Ultrasonic Sensor’ - Got distance: 0.000 m
[21:39:22][D][sensor:093]: ‘Ultrasonic Sensor’: Sending state 2.40041 cm with 2 decimals of accuracy
[21:39:23][D][ultrasonic.sensor:040]: ‘Ultrasonic Sensor’ - Got distance: 0.853 m
[21:39:23][D][sensor:093]: ‘Ultrasonic Sensor’: Sending state 3.42324 cm with 2 decimals of accuracy
[21:39:24][D][ultrasonic.sensor:040]: ‘Ultrasonic Sensor’ - Got distance: 0.000 m
[21:39:24][D][sensor:093]: ‘Ultrasonic Sensor’: Sending state 2.40041 cm with 2 decimals of accuracy
[21:39:25][D][ultrasonic.sensor:040]: ‘Ultrasonic Sensor’ - Got distance: 0.373 m
[21:39:25][D][sensor:093]: ‘Ultrasonic Sensor’: Sending state 2.84762 cm with 2 decimals of accuracy
[21:39:26][D][ultrasonic.sensor:040]: ‘Ultrasonic Sensor’ - Got distance: 0.000 m
[21:39:26][D][sensor:093]: ‘Ultrasonic Sensor’: Sending state 2.40041 cm with 2 decimals of accuracy

Any help would be appreciated.

1 Like

Same problem! I just get always the value: “0.009m” when connected to 3.3V. The pulses monitored with an oscilloscope are delayed constantly between Trigger and Echo (see picture below) independently from any obstacle.

5V: And when the sensor is powered by 5V echo is not delayed at all. Just like when disconnecting the whole sensor from power. This is strange. 5v Power does not make any sense.
I give up at this point.

3V: connected to 3v3 it receives an echo pulse always after 2.23ms without any change.
The correspondent distance for 2.23ms is about 38cm. What is going on here?

Solved! Ultrasonic distance works great!
I did change the board from ESP8266 (lolin) to ESP32 NodeMCU D1 R32 (WROOM). I used the same configuration. Just adopted the pins

Pinning:
Power to 5V next to GND
GPIO1 for Trigger and
GPIO3 for Echo

sensor:
  - platform: ultrasonic
    trigger_pin: GPIO1
    echo_pin: GPIO3
    name: "Ultrasonic Sensor"
#    pulse_time: 100us
    update_interval: 200ms
    timeout: 200cm


    filters:
      - filter_out: nan