Waterproof ultrasonic distance sensors, jsn_sr04t, aj_sr04m or sr04m-2?


This sensor I bought from a chinese site made me loose about a day of work to get it up and running. At first glance it could be attributed to wrong documentation, this page in particular: https://esphome.io/components/sensor/jsn_sr04t
but I actually think that at the time of writing this particular board was not yet around, and then the chinese made a mess with the naming.

TLDR: this board (SR04M-2) has to be configured as a JSN-SR04T, from the resistor to set the operating mode, to the YAML

This is the relevant part of my working config (Mode 1 and heavy filtering to slow down the rate, prioritizing having no outlyers):

uart:
  tx_pin: GPIO14
  rx_pin: GPIO12
  baud_rate: 9600

sensor:
  - platform: "jsn_sr04t"
    name: "Livello Intercapedine"
    filters:
      - quantile:
          window_size: 10
          send_every: 50
          send_first_at: 1
          quantile: .9

I hope this can be of help to anyone like me that bought this board. Take care.

Hello!
Did you leave R19 free or solder a resistor?
Thank you.

(In this case, it seems that you are using an ESP32. I am using an ESP8266.)

I soldered a 47k resistor to get into Mode 1, lots of data that I then can filter a lot to mitigate outlyers. I’m planning to try Mode 2 by soldering a 120k resistor or another board.

I’m using too a ESP8266 (nodemcuv2), but it’s not relevant

Here is the board with the 47k resistor:


as you can see the RX (and TX on the ESP) pin is disconnected at the moment because not needed in Mode 1

Here the test for mode 2, with a 120k resistor (100k+22k):

and the updated YAML:

sensor:
  - platform: "jsn_sr04t"
    name: "Livello Intercapedine"
    id: livello_intercapedine
    update_interval: 1s
    filters:
      - clamp:
          min_value: 0.4
          max_value: 3.0
          ignore_out_of_range: true
      - sliding_window_moving_average:
          window_size: 7
          send_every: 3 # TODO slow down to 10sec
          send_first_at: 3

Note the update_interval now is mandatory to send the trigger packet, and the RX wire needs to be connected to the ESP TX.

I’ve also changed the filtering strategy, but still experimenting with it.

1 Like