JSN-SR04T and nodemcu

did anyone get this JSN-SR04T working with ESPHome?
i followed the instruction n template from here Ultrasonic Distance Sensor — ESPHome
the numbers changes so i know something is working but the numbers are not accurate. they are much much smaller than the expected value in meters.
i feed the 5v and ground of the sensor into a 5v 1Amp power supply. i feed the trigger and echo into the D3 and D4 as seen here:

sensor:
  - platform: ultrasonic
    trigger_pin: D3
    echo_pin: D4
    name: "Ultrasonic Sensor"
    update_interval: 5s

any help is greatly appreciated

1 Like

The first thing I’d try is using different pins. According to the ESP8266 pinout documentation, D3 and D4 are both pulled high and have special purposes, so that all may interfere with your ultrasonic sensor.

I can confirm that the sensor does work in principle. I am using one for 3+ years now - initially with a Wemos D1 Mini Pro, connected to pins D5 and D6, and recently switched to an ESP32.

And, is this the same 5V/GND that your NodeMCU is connnected to?

i changed trigger to D1, echo to D2,
image

and the result is even worse:


let me try D5 and D6 next on my 8266.

the sensor gets power from the wall outlet. the nodemcu gets its power by plugging a micro USB cord to a USB power bank

I would avoid powering the sensor from a different power sources. I believe they would at least need to share the same GND, but better share the whole power supply.

Following this closely, my next project will be using a JSN-SR04T.

I notice that the link you posted (thank you, BTW, I hadn’t seen that) is for a different type of sensor. Are they functionally equivalent? Just thinking of future projects.

I was looking at doing something like what’s described in this link:

I’ve also found this link and this link describing similar projects.

I’ve started experimenting with the JSN-SR04T recently. I got it working without any trouble and i’ve got to say that the sensor is more accurate than i expected (+/- 1cm i would say).

I’ve got everything almost set up in the same way, except i’m using an esp32. Also my JSN-SR04T is powered directly from the ESP32 via the 5v and GND pins.

sensor:
  - platform: ultrasonic
    trigger_pin: D1
    echo_pin: D2
    name: "oillevel measured distance"
    id: oillevel_measured_distance
    update_interval: 5s

please also keep in mind that there are different versions of this sensor. I’m not sure what the differences are, but apparently the 3.0 has “better stability”; whatever that means.

@CaptTom : that’s funny, i’m exactly working on that → a level gauge for my heating oil tank. On my testbench i got everything working fine and even mapped the entire conversion from cm to liters for my oiltank (which isn’t any normal mathematical shape unfortunately). I had read that many people have problems with the wide angle of the ultrasonic signal which is about 75°. So i tested this as well by holding the Sensor in a corner of the room, about 10 cm from both walls in the upward position, towards the ceiling. Surprisingly the sensor still worked fine and gave the right measurements. Encouraged by this i installed it in a free filler cap of my tank and installed it in the tank. Unfortunately it now only reads 0.23m, which basicly means that there is something wrong. The signal is probably bouncing of the tank-walls or perhaps even of the edge of the filler cap. I will do some more testing in the coming days (i’m still determined to get this to work one way or the other), so if you’re intererested i can keep you up to date.

1 Like

Thanks assembly for posting on your progress!

I wonder if putting the sensor in a cylinder of some sort might direct the beam better and prevent it bouncing off the walls. My tank is metal, although I know many newer ones are plastic. That may make a difference, too.

My two JSN-SR0-4Ts will be arriving tomorrow. If it works in my oil tank at home, I have four fuel tanks, a water tank and two waste tanks on the boat I’d like to adapt this for next. Boat fuel gauges are notoriously inaccurate, when they’re working at all.

ok. happy to say it works!!!
the 4 wires from the sensor is plugged directly to my nodemcu. even though the nodemcu only outputs 3.3v and the sensor requires 5v, everything still works fine. phewww.
thanks for your help everyone!

1 Like

See this link, there you will have the answer you are looking for.

Hi all,
I have also switched my ultrasonic sensor to a JSN-SR04T and connected it like an HC-SR04 to my ESP32 via the following pins:

trigger_pin: GPIO5
echo_pin: GPIO18

Why so ever, I can only get any values with the sensor max distances between 50-60 cm. On low distances it is working perfectly.
Any idea what can cause such an issue?

Hi @assembly
Did you figure out how to solve it?
I am also getting 0.23m no matter the real distance.
Thanks!

Yeah, I did manage to get it working. I have mine installed in a plastic cap of a fuel tank. There wasn’t enough space around the sensor so the signal would bounce against the side of the cap and therefore return a very short distance. The minimum distance the sensor can measure is approximately 20cm, if below that it will automatically return 23.
I solved it by installing it a bit further down, so it’s just barely no longer in the cap, but rather in the tank. The clearance to al sides must be quite large (depending on some other factors, like materials and depth you are trying to measure). Just try is out by holding it in a corner of a room. At some point if you come too close to the walls it will give you value 23, even though there theoretically still is a clear line of sight to the ceiling.

yes, this video should help you. How to build your own Distance Sensor, via sonar technology - YouTube

Thanks guys.
Does not work for me.
Maybe sensor is broken. I will try another one.

How it goes? No problems with getting proper signals back despite powering sensor from 5v? (are esp32 input pins 5v tolerant?)

Yeah. It has been in the oil tank for a little over a year now and it’s still working perfectly.
I have set the update interval on the sensor to once every hour or so. That’s more than enough for something which drains this slowly :wink:

Does anyone knows if there are limitations with a d1 mini. Mine doesn’t seem to work…

Hello @assembly . Mine also has values close to 23. Initially I placed it in position 1 (drawing below) and later, to test it, I placed it in position 2. It still does not give the desired values. Effectively, there is about 0.5m of the electric cable and water pipe from the pump, but the walls are about 1m away.
Unless you’re having trouble, I don’t see why!
Any tips?
Thanks

Sorry to hear you’re having trouble. If you just hold it in your hand in a room, are you then able to measure anything else than 23cm?
Mine is still reporting 23 occasionally but I filter it out in code. So just perhaps you could try to get some more measurements. If you’re able to get one measurement in lets say 20 that’s correct, you can then just ignore the other 19.

Thanks.
Yes, the problem is that I can’t get any measurements greater than 23, not even in open spaces. Everything indicates that you have problems.