I have two JSN-SR04T-2.0's with a waterproofed sensor unit that has a long (~2m) cable, bought from eBay in May 2017.
With the stock v1.9.1 (and v1.8) library and NewPingExample example, it returns occasionally a correct measurement, but mostly it returns 0.
When investigating this, I noticed that the sensor didn't make a ticking sound every time it was being triggered.
A datasheet specifies that the trigger pin needs to be given a 10us logic high pulse, but it does not specify how long the pin should be held low. (Datasheet: https://www.jahankitshop.com/getattach.aspx?id=4635&Type=Product)
With experimentation, I found that by increasing the default pin low delay value of 4us to 10us makes this sensor board work reliably with the NewPing library.
In NewPing.cpp (current master), change line 132:
delayMicroseconds(4); // Wait for pin to go low.
delayMicroseconds(10); // Wait for pin to go low.
Same for line 158.
Possibly a better fix could be to have a configurable
#define for low/high delay times, if you don't want to increase the delay time for all boards.
I tested the both sensor boards and the code fix on an Arduino Uno clone (AVR, 5V TTL logic levels) also, and observed the same behaviour.
I'm also happy to report that this library (and the fix) works on
esp8266 architecture, specifically on a Wemos D1 mini board (3.3V logic levels, just use a voltage divider with 1kohm resistors to 5V and GND for the Tx/Echo pin for JSN-SR04T-2.0 to make a crude level shifter). Currently, the Arduino IDE gives a warning that
esp8266 maybe incompatible with this library, but it seems to work well at least with the default settings.
It seems that with
ONE_PIN_ENABLED properly set to
false, the pulse high time needs to be increased from 10us to 13us. (lines 136 and 160)