Unknown value in ESP home ESP32 with AJ-SRO4M

Greeting all

I need your support to resolve an issue that faced me for my first ESPhome project to create water tank level sensor.

following this guide: Water tank monitoring with ESPHome

Parts in this project:
ESP32 Development Board Wireless WiFi Bluetooth module Ultra-Low Power Consumption Dual Core 30Pin ESP32-WROOM-32S 32D ESP 32

Waterproof Ultrasonic Module JSN-SR04T Water Proof Integrated Distance Measuring Transducer Sensor for Arduino

I tried many scripts and trils with no luck to get a any value for the level.
screen shot and code :

code:

esphome:
 name: "tank-level"
 friendly_name: "tank-level"

esp32:
 board: esp32dev
 framework:
   type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

wifi:
 ssid: 
 password: 

 # Enable fallback hotspot (captive portal) in case wifi connection fails
 ap:
   ssid: "tank-level Fallback Hotspot"
   password: "OFLmnY89P7zG"

captive_portal:
   

sensor:
# Wifi signal sensor.
- platform: wifi_signal
  name: garden_watertank_wifi
  update_interval: 600s
  unit_of_measurement: '%'
  filters:
   - lambda: |-
      if (x <= -100) {
        return 0;
      } else {
        if (x >= -50) {
          return 100;
        } else {
          return 2 * (x + 100);
        }
      }

# Templates for calculated liter & percent
- platform: template
  name: garden_watertank_liter
  id: garden_watertank_liter
  icon: 'mdi:water'
  unit_of_measurement: 'l'
  accuracy_decimals: 0

- platform: template
  name: garden_watertank_percent
  id: garden_watertank_percent
  icon: 'mdi:water-percent'
  unit_of_measurement: '%'

# The actual distance sensor
- platform: ultrasonic
  trigger_pin:
   number: GPIO12
   inverted: True
  echo_pin: GPIO14
  name: garden_watertank_distance
  update_interval: 600s
  pulse_time: 50us
  filters:
   - filter_out: nan
   - median:
      window_size: 7
      send_every: 4
      send_first_at: 3
   - calibrate_linear:
      - 0.23 -> 1.86
      - 2.41 -> 0.0
  on_value:
   then:
    - sensor.template.publish:
       id: garden_watertank_liter
       state: !lambda 'return x * 3141.592653589793238;'

    - sensor.template.publish:
       id: garden_watertank_percent
       state: !lambda 'return x * 53.979255216319471;'

kindly support me on how i can get the issue solved as i try it in tasmota and Arduino and both give a numeric value

What do the ESPHome logs say? What are the raw values without all the filters?

[12:18:47][D][ultrasonic.sensor:036]: ‘level’ - Distance measurement timed out!
[12:18:47][D][sensor:093]: ‘level’: Sending state nan m with 2 decimals of accuracy

What happens when you use the default 10us timeout?

Also, why is the trigger pin inverted?

appreciate your countians support

still the same even when changed to 10 and keep the basic code without any filters

Hmm. The only other thing is that you have a wiring issue, or the SR04 is faulty.

The VCC pin needs to connect to the 5V supply, not the 3.3V one. Also the distance you are measuring typically needs to be less than 2m. My cheap SR04 sensors timeout at 1.2m.

THANK YOUR FOR YOUR SUPPORT

you were right it was wiring issue