Help! Inaccurate ultrasonic distance reading

I’m trying to get ESP8266-MOD to work with HS-SR04 sensor. The config file is very staighforward but the reading i’m getting from the sensor is inaccurate

[13:27:05][D][sensor:092]: 'Node2 Distance Sensor': Sending state 0.60025 cm with 0 decimals of accuracy
[13:27:06][D][sensor:092]: 'Node2 Opener Wifi': Sending state -54.00000 dB with 0 decimals of accuracy
[13:27:10][D][ultrasonic.sensor:029]: 'Node2 Distance Sensor' - Got distance: 0.01 m
[13:27:10][D][sensor:092]: 'Node2 Distance Sensor': Sending state 0.60025 cm with 0 decimals of accuracy
[13:27:15][D][ultrasonic.sensor:029]: 'Node2 Distance Sensor' - Got distance: 0.01 m
[13:27:15][D][sensor:092]: 'Node2 Distance Sensor': Sending state 0.60025 cm with 0 decimals of accuracy

Here is config file

esphome:
  name: node2
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: !secret wifi
  password: !secret wifi_pw


# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

# Enables status LED
status_led:
  pin: GPIO2

sensor:
  - platform: wifi_signal # Sensors that the ESPhome unit is capable of reporting
    name: "Node2 Opener Wifi"
    update_interval: 60s  
  - platform: ultrasonic
    trigger_pin: D6
    echo_pin: D5
    update_interval: 5s
    unit_of_measurement: cm
    accuracy_decimals: 0
    # apply a filter to change the distance to cm from metre #
    filters:  
      - multiply: 100
    name: "Node2 Distance Sensor"

I thought it is a sensor issue so I bought 5 new SR04 sensors and i’m getting the same results.

What am I doing wrong? #freakingout

What pin is the vcc on the sensor connected to?
I had a similar issue when I tried the same thing a few weeks ago with an ESP32. I found that the vcc needed to be connected to the 3.3V output even though the sensor is marked with 5V.

It is connected to 3V3 pin

Is the output always 0.60025?
Are you using a nodeMCU ESP8266?
Here is mine. Maybe try using the GPIO number? (mine is an ESP32 though)

sensor:
  - platform: ultrasonic
    id: sensor_cm1
    trigger_pin: GPIO15
    echo_pin: GPIO16
    name: "Oil Ultrasonic Sensor"
    icon: "mdi: arrow"
    update_interval: 10s
    accuracy_decimals: 2
    unit_of_measurement: "cm"

according to the documentation D0 -D8 are aliases used by nodeMCU ESP8266

Having exactly the same issue with nodemcu. No matter what I tried (D1 vs GPIO, switching boards). Tried 3 different SR4 sensors all reading the same. Did you managed to get this working already?

1 Like

Hi,
I have the same issue
was anyone able to find a reason/solution

I’m using and ESP32 Lan8720 POE and the HC-SR04 sensor

any help is really appreciated

Regards

This just helped me loads! Many thanks for sharing!

1 Like

Mine are working fine by supplying 5V (like stated in the datasheet)

Anyway a quiet and cheaper solution might be just use a ToF sensor in 2021 :rocket:

Hi, I’m having another problem related to this. Using an esp32 (ttgo) and i get good readings for the most part. But at times the readings become much longer and also very noisy. I’m measuring the level of pellets in a magasin and I don’t know if these errors are due to the shape of the material depending on how it is lying. When the sensor is at approximately 2dm from the pellets as of now, readings go up to at about 1m and stay there. The fix seems to be to recycle the power. Simply restarting the ESP does nothing. I have my sensor powered from the 5V pin.

I resolved my problem, and after reading about others with different strange errors with the same cause I wanted to write it here.
I was running the sensor from 5v but in fact it was giving 4.8 v on the ttgo board. I soldered a thin wire to get 5v directly from the USB port, without going through any diods or what not and my problems are gone. Other problems I’ve read about can be inconsistent or noisy readings, uncharged values and no readings at all

1 Like

I figured this out. What fixed it for me was changing the VCC → 3V3 to VCC-> Vin on my ESP8266. I hope this saves someone else some headache

That fixed it for me too! Thanx

I would appreciate some help here too.

I’ve tried several different boards and I’ve used power from a board pin and I’ve used a separate power supply to ensure 5v and I still get erroneous readings from these sensors.

I’ve got the “unit of measurement” set to cm on one sensor and to ft on the other sensor in my 2 car garage.

My readings on my dashboard for one are 1.12 cm and for the other one 1.05 ft. So these readings are complete garbage.

  - platform: ultrasonic
    trigger_pin: 4
    echo_pin: 6
    name: "Glen's Garage Space"
    update_interval: 30s
    unit_of_measurement: ft
    filters:
      - filter_out: nan

Other than unit_of_measurement the config is the same for both sensors.

Any help is appreciated.