Trouble with the JSN SR04T

  • Hi,

    I am having some trouble with the JSN SR04T - I am using it to measure the water level in a overhead tank. However, the readings keep varying between 20-30cm only. I assumed this was because of the wide beam spread / echo, so tried to build a stand pipe using design from

    However, this did not work out, key issue which i ran into was that the diameter to height ratio of beyond 1:1 is not working out, kept getting same erronious readings when i increased the height of the sensor in the pipe. With a bit of experimentation, worked out that a height of 1.2cm is the max you can go for inside 2cm inner diameter pipe.

    With this setup i.e taking the transducer out of its plastic casing, inserting it inside a 2cm tank nipple, keeping the sensor face at height of 1.2 from end, getting readings which are better but still not fully accurate.

    Please suggest

    • Proper standpipe design for this sensor to limit the angle of detection
    • Ways to trouble shoot the problem further.
    • any reading material on proper design of standpipe / waveguide for this sensor

  • @sundeep-goel
    Oh! This sounds a lot like the problems I have had for the past year. Like @zboblamont I have been pulling my hair trying to find a solution.

    The tank is a square profile septic tank, cross section 1 x 1 m. Access to the tank is through a manhole some 60 cm diameter.

    First i tried mounting the sensor in the lid of the manhole but all the time I ended up with measurements like 20 - 30 cm, no matter what the liquid level was.

    I then tried to mount a baffle around the sensor trying to limit the beam spread so that the sensor would not see the corrugated wall of the manhole. No luck!

    Next idea was to increase the powerfeed to the sensor. First it was powered from one of the digital pins of the Arduino, giving some 4.x volts. So, thinking this was below specs, I built a circuit that gave the sensor proper 5 V as needed. No luck!

    The final solution was to mount the sensor at the bottom end of a plastic tube, 30 mm outer dia and then feed the cable through the tube and out to the electronics. The tube is attached to the wall of the manhole using a plastic clip. Please see attached photos. Success!

    So clearly my problem was caused by the sensor getting reflexes from the corrugated wall of the manhole.
    1_1563737602774_IMG_0212.jpg 0_1563737602773_IMG_0211.jpg

  • @bgunnarb There are many confusing models with the same JSN-SR04T model name out there, the single button version (a la bumper mounted parking sensor) is the version we both settled on as it is a snug fit in the end of a 3/4" collar adapter.
    The JSN-SR04T-2.0 (sensor on cable type) was advertised as 3v capable (original non 2.0 was 5v only), but readings were weird. I even tried feeding it 5v which appeared to work, but which then caused other complications with dual voltages.
    Revisiting the problem I stumbled over a comment that the Trigger HIGH before reading should be 15 microseconds, reworked the sketch and it has worked flawlessly ever since on a 3.3v node.
    As you found, mounting on the end of a pipe to position the head for clear perpendicular flight to the surface >=200mm is crucial. During raw water tank recalibration this summer the exposed ledges caused no inconsistencies at all right down to the STOP-PUMP electrode, but it IS getting two consecutive readings and verifying within known range before sending anyway.

    @sundeep-goel Not quite clear what casing you removed from the ultrasonic, the waterproof button should fit directly into a 20mm socket, and the cable runs up the tube.
    So long as your sensor is >=200mm from the surface, side reflections should be minimal unless it is a very narrow overhead tank with ledges to reflect, in which case consider inserting plastic sheets into the tank to null them?

    Perhaps a little more detail would help understand the physical problem you are trying to address....

  • Yes, I take five consecutive readings 100 ms apart and calculate the median value of the readings that fall within allowed limits. Off-scale readings are discarded before calculating the median value.

    It has been running for two weeks now and seems to be accurate and stable.

  • @zboblamont said in Trouble with the JSN SR04T:

    Not quite clear what casing you removed from the ultrasonic, the waterproof button should fit directly into a 20mm socket, and the cable runs up the tube.

    Needed to remove the plastic to fit sensor inside a standpipe 1.5cm diameter (baffle) to reduce reflecting from side of the tank (which i assumed was causing most of the issues.

    Note : If i insert the sensor face more than 1.2cm away from the pipe edge, keep getting 20cm readings only. Same happening if i go for a pipe with a larger diameter.

    alt text

    Even after this, i keep getting erratic readings
    0_1563807843588_Screen Shot 07-22-19 at 08.31 PM.PNG

    The left one is not as erratic - but innaccurate , the right one is completely bonkers 🙂

  • @sundeep-goel I still don't understand why you didn't use a 2cm adaptor, it is a snug fit for the original waterproof sensor head. Fitting it inside a pipe may be perceived as narrowing the field of view, but mounting it to ensure it's emission axis is parallel to the pipe is no easy task.
    Details I meant were for your physical tank to verify why side reflections may be an issue, and consider alternatives. I was concerned initially over side reflections, but no actual problems were found with the sensor mounted on the end of a pipe.
    Clearly your standpipe experiments are not working, perhaps a fresh pair of eyes might help identify alternatives.
    For starters, is the JSN the 5v or 3v version, and is the pulse set for 15 microseconds, etc...

  • @bgunnarb I looked at that median methodology also, but plumped for two consecutive readings instead, again within verified limits. Both installs are fired by RTC hourly, the only refinement added was to limit attempts to 10 after discovering a condensation drip had the ultrasonic running continuously... An unforeseen effect of the steel pipe in sub-zeroes, may yet dismantle it and change to plastic inside the tank...

  • @zboblamont said in Trouble with the JSN SR04T:

    is the pulse set for 15 microseconds

    How do I check for this? Am using the ultrasonic Arduino library

  • @sundeep-goel
    Can we please establish a baseline of what you are using and the physical parameters, a fresh pair of eyes is only useful if the blinds are removed.

    No idea what trigger time the library you refer uses, but can confirm that the standard and improved Ping versions trialled originally were inconsistent. Hence I use a basic manual sketch where the parameters are set, the 15 microsecond trigger was modified later and found to give consistent and repeatable readings. From vague memory the original trigger was 150.
    I was/am using an original unmodified exposed button on the end of a pipe, and I don't suppose you have a spare original sensor head available.
    Perhaps we might establish the method you use was originally tested in free air before the install or stand-pipe were developed, and found reliable and consistent?

  • @zboblamont said in Trouble with the JSN SR04T:

    Can we please establish a baseline of what you are using and the physical parameters, a fresh pair of eyes is only useful if the blinds are removed

    I agree, let me try and address all the queries.

    1. This sensor is mounted on top of a 1000 ltr plastic tank (image attached)
    2. The sensor is a 5V version, which is feed from a 3.3V esp8266 (image attached) - Can this be an issue even though it si working fine outside the tank?
    3. Sensors work fine outside the tank, within orig mounting and also inside the standpipe (as long as the sensor face is no deeper than 1.2cm from end of standpipe - image attached)
    4. Looking into the code of the ultrasonic library, trigger pulse seems to be 10 microseconds which is as per the documentation. Should i increase this to 15ms?
      digitalWrite(trig, LOW);
      digitalWrite(trig, HIGH);
      digitalWrite(trig, LOW);

    Tank - total height say 130cm
    Mounting Hole - its offset from the side by 25cms
    Inside of the tank
    JSN 04T driver module
    Sensor head mounted inside standpipes

  • @sundeep-goel Excellent... Tank is typical eastern roof mounted PVC/GRP. That size and shape should give you no side reflections at all but your sensor would be better centralised - If you are using threaded couplers, I suggest a 90 degree under your current entry, a short extension to the centre, then down to just above 200mm from top water level. That way if you need clear access through the hatch, the pipe can be swung to one side.
    The inlet is usually direct discharge which will cause ripples, easily solved by attaching a drop pipe to push the discharge under water. In the discharge is flush on the inside, a small drain pipe with a Tee can be tied to it, but may need a brick tied to the bottom to keep it from moving.
    Can you confirm the JSN model number does not have 2.0 on the end which would make it 3v compatible. Otherwise you need level converter to 3.3v.
    I suggest flush facing the sensor to it's housing.
    From what I read the 15 microsecond is important.
    I've attached a water tank sketch which you will have to alter for your setup, pins and parameters... My apologies that it's a bit of a mess as it's been through 6 different itterations...

    #include <T2WhisperNode.h>
    #include <Wire.h>
    #include <RTClibExtended.h>
    // Enable debug prints to serial monitor
    //#define MY_DEBUG //Comment out once all working saving memory
    // Enable and select radio type attached
    #define MY_RADIO_RFM69
    #define MY_RFM69_FREQUENCY RFM69_433MHZ  // Define for frequency setting. Needed if you're radio module isn't 868Mhz (868Mhz is default in lib)
    #define MY_RFM69_NETWORKID 101  // Default is 100 in lib. Uncomment it and set your preferred network id if needed
    #define MY_NODE_ID 7  //Manually set the node ID here. Comment out to auto assign
    //A define should be added to provide minimum power output to provide decent RSSI to the Gateway if ATC not available
    #include <MyConfig.h>
    #include <SPI.h>
    #include <MySensors.h>
    #define SN "Node7water3vWNfinalRTC"
    #define SV "6"
    #define FIRST_CHILD_ID 1
    #define SECOND_CHILD_ID 2
    #define THIRD_CHILD_ID 3
    #define REED_PIN 3   // Arduino Digital I/O pin for button/reed switch
    #define BatteryOn 14
    #define BatteryIn A6
    #define Trigpin 17
    #define Echopin 16
    #define Ultrapin 15
    #define flasher 6
    int halfday=12;
    int tankdepth, tankpercent,tankvolume,distance,test,test2,counter;
    long duration;
    volatile int ultrasonic;
    RTC_DS3231 RTC;      //we are using the DS3231 RTC
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg1(FIRST_CHILD_ID, V_LEVEL);
    MyMessage msg2(SECOND_CHILD_ID, V_LEVEL);
    MyMessage msg3(THIRD_CHILD_ID, V_VOLTAGE);
    unsigned long SLEEP_TIME = 0;//1800000; Sleep time between reports (in milliseconds)
    void setup ()
       pinMode(REED_PIN, INPUT_PULLUP);//Output of DS3231 INT pin is connected to D3 INT1 for RTC wake-up
       pinMode(BatteryOn, OUTPUT);//WN battery sample activation
       pinMode(BatteryIn, INPUT);//WN ADC for battery read
       pinMode(Trigpin, OUTPUT);
       analogReference(INTERNAL);//All voltage reads are to 1.1 internal datum
       sleep(100);//Allow things to settle was 1000
       Wire.begin ();
       RTC.adjust(DateTime(__DATE__, __TIME__));   //set RTC date and time to COMPILE time
    //clear any pending alarms
       RTC.armAlarm(1, false);
       RTC.alarmInterrupt(1, false);
       RTC.armAlarm(2, false);
       RTC.alarmInterrupt(2, false);
      //Set SQW pin to OFF
      //Set alarm1 every hour at XX:50
       RTC.setAlarm(ALM1_MATCH_MINUTES, 0, 50, 0, 0);//set wake-up time here
       RTC.alarmInterrupt(1, true);//Alarm on
     void presentation(){
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo(SN, SV);
      // Register binary input sensor to sensor_node (they will be created as child devices)
      // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
      // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
      present(FIRST_CHILD_ID, S_DUST);
      present(SECOND_CHILD_ID, S_DUST);
    void loop(){
    // Power up US
       sleep(100);//Delay to stabilise
       sleep (100); 
       sleep(100);/// Allow decay of pulse
       int voltread;
       while ((tankdepth<350||tankdepth>1130)&&counter<=10){//10 attempts to get proper range, recalibrated 6/7/2019
    //Recalibrated 6/7/2019 -Depth to physical cut-off 1112, surface full 380, range 732, metered 1812L, factor 2.475
    //Recalculated-Sensor cut-off 1101, surface 362, range 739, metered 1812L, factor 2.45
      float tankpercent=100-((1101-tankdepth)/7.39);//750 effective range
       int tankvolume=(1101-tankdepth)*2.45;//Set to low level cut off Sensor-Recalibrated 6/7/2019 from 2.3727
       //Total recalulated volume 1812 litres
       if(tankdepth>350&&tankdepth<1150){//Don't report if value is outwith known range
       send(msg1.set(tankvolume));//This is actual volume
       send(msg2.set(tankpercent,1));//This is remainder to start of 39cm Freeboard
    //   }
       VOFF();//If 2nd flash, reading sent, only 1 is fail
    // Call for battery reading, send in every 12th RTC call?
       digitalWrite(BatteryOn, HIGH);
       voltread = analogRead(BatteryIn);
       float voltage = (7.272 * voltread) / 1024;
       digitalWrite(BatteryOn, LOW);
       halfday=0;//Reset for 12 hourly cycle
       halfday++;//Increment hourly cycle
    // Rearm alarm
       RTC.alarmInterrupt(1, true);
    //Go deep sleep until RTC interrups
       sleep(digitalPinToInterrupt(REED_PIN),FALLING, SLEEP_TIME);
    sleep(100);///Time to recover
    //First clear the alarm
       RTC.armAlarm(1, false);
       RTC.alarmInterrupt(1, false);
      }  // end of loop
    void VON(){
      digitalWrite(Ultrapin, HIGH);
      sleep (6);
    void VOFF(){
      digitalWrite(Ultrapin, LOW);
      sleep (10);
      sleep (6);
      void READULTRASONIC(){//JSN-SR04-2.0
    //Main loop checks valid range on a defined number of readings
    // Normal range should lie between 389 and 989 absolutely empty is 1520
    while (test!=test2){// Get two consecutive readings
      digitalWrite(Trigpin, LOW);
      delayMicroseconds(50);//Was 100
      digitalWrite(Trigpin, HIGH);
      delayMicroseconds(15);//Was 150
      digitalWrite(Trigpin, LOW);
      duration = pulseIn(Echopin, HIGH);
      distance = duration/5.82;//This is in mm
     if (test!=distance){

  • @zboblamont said in Trouble with the JSN SR04T:

    but your sensor would be better centralised

    I thought about this, however, our tanks have a typical float ball which will mess up the reflections from the center. This was one of the major reasons for putting the sensor off-center and also inside a standtube.


    @zboblamont said in Trouble with the JSN SR04T:

    I suggest a 90 degree under your current entry, a short extension to the centre, then down to just above 200mm from top water level

    Can you please elaborate on this? do you mean something like?

    if yes, wont there be reflections from the elbow ?

    @zboblamont said in Trouble with the JSN SR04T:

    Can you confirm the JSN model number does not have 2.0

    the board does not have a number on it. The link to the item is : link text. Seem to be a non 2.0 version. However, since the unit is getting trigged, and also detecting echos - can the operating voltage still be an issue ?

    @zboblamont said in Trouble with the JSN SR04T:

    From what I read the 15 microsecond is important.

    I'll try with 15 us, changing the library is not a big deal.

    I'll also try adding a voltage divider across the ECHO output into the GPIO pin to see if that makes a differnce.

  • @sundeep-goel Looking back at the tank photo your inlet is at the opposite side of the tank and presumably your sensor head is just over 200mm to the top water level when full? There should be no way that head is seeing the float when full even if the float is directly below the hatch.
    I'm confused by what you are saying about the board - Accepted it is the 5v version, but you say you are detecting echo away from the tank, but is the distance reliably and consistently correct?
    Presumably this is via a 5v-3.3v level converter?

    You misunderstood the bend suggestion - Ultrasonics don't handle bends well but cables do ;). I was looking at the possibility of extending the cable pipe with the sensor on the end pointing down nearer centre. Unfortunately that will be very close to the float if it's a long arm.
    What you could try is tying the float up until level drops and hang the sensor through the hatch and to see if it works reliably there.
    If it does, you may have to find a source a replacement float valve with a shorter arm, or possibly find a compact version usually marketed as "silent" (The float in these rises up a tube to close the valve, but unlike the arm type they run at full flow longer until the last few cm).
    Let's see what your tests reveal....

  • @zboblamont said in Trouble with the JSN SR04T:

    hang the sensor through the hatch and to see if it works reliably there

    Got you, will try this and a couple of others. Will post back the results.

    On a related topic, is this sensor good sensing water level [link text](GY-VL53L0XV2 Laser Distance Module I2C IIC 3.3V/5V

  • @sundeep-goel No idea !

  • @zboblamont said in Trouble with the JSN SR04T:

    The sensor is working perfect outside the tank - tested both with 10us and 15us. Also, same with / without a voltage divider.

    Saw a possible issue in the code

    Ultrasonic ultrasonic1(4, 13);  // An ultrasonic sensor HC-04
    Ultrasonic ultrasonic2(4, 12);  // An ultrasonic sensor HC-04

    Was using same trigger pins on the esp for both sensor, ideally this should not have been creating a problem. but just to be sure, tried with only one sensor - worked fine outside the tank

    Inside the tank in all cases, back to square one i.e. readings between 20-25cm only.

    For now , putting this sensor aside and switching to the IR laser sensor VL53L0X. Lets see how that does, will post back the results soon

  • @sundeep-goel said in Trouble with the JSN SR04T:

    putting this sensor aside and switching to the IR laser sensor VL53L0X.

    replaced JSN SR04T with VL53L0X

    So far the tests in a experimental setup (i.e. using a mug of water as a reflective surface are good), will install in the tank tomorrow morning, fingers crossed.

  • @sundeep-goel said in Trouble with the JSN SR04T:

    will install in the tank tomorrow morning, fingers crossed

    Installed under a tank nipple (needed to attach to lower end, was getting issues at the end)


    getting steady readings now
    0_1564315170092_Screen Shot 07-28-19 at 05.26 PM.PNG

    in brief, too many issues with the JSN SR04T sensor in my tank, Laser TOF Sensor VL53L0X is better and cheaper in given setup.

  • @sundeep-goel Glad you found a solution, hopefully it will continue to prove reliable over time in your environment, presumably dust is not a problem from the presence of water, nor condensation through ventilation (loose lid)
    Out of curiosity, what the range is that version, I've seen 1m and 2m quoted for the same model number..?

  • @zboblamont said in Trouble with the JSN SR04T:

    what the range is that version, I've seen 1m and 2m quoted for the same model number..?

    I have tested till around 2meters succesfully. I read somewhere that you can also switch to another mode to increase range, haven't tried that though.

    Let me know if you need more information, as of now I have added only one sensor, will be adding one more next week, so can run more tests then

  • Hello everyone, I am having problems with the jsn-sr04t V2 sensor and I came to this forum looking for a solution.

    In my case I am getting erroneous readings in a cylindrical water tank 3.5 meters high.

    I am measuring once a minute (below a sample) and the readings are disparate. Do not match the actual measurement.

    109 cm 2019-11-05 21:01:42
    141 cm 2019-11-05 21:00:42
    90 cm 2019-11-05 20:59:42
    168 cm 2019-11-05 20:58:41
    170 cm 2019-11-05 20:57:41
    111 cm 2019-11-05 20:56:41
    143 cm 2019-11-05 20:55:41

    I am using a 220V switching power source at 5V and 700 mA maximum. From the food source a Wemos D1 mini (with esp8266) and from the 5V and GND pins to the sensor.

    In tests outside the tank, I used the USB power of my notebook and the samples were wrong, however when I powered up with an original Motorola fast-charge charger, the samples were perfect.

    Is it possible to think that the 700mA source (from china) is not enough? Or that the power source may be putting some noise to the sensor signal?

  • @dmacros My guess would be noise, I had similar problems when I tried using a 5v booster only for the JSN, the boards seem quite "temperamental" over voltage supplies.
    I understood the Wemos to be 3.3v logic anyway, so powering the JSN off the 3.3v pin would be normal, and the regulator should kill noise sufficiently to allow the JSN to work reliably.

    I have two of these installed, one works perfectly on 3.3v to maximum range, the other has problems at maximum unless fed 5vDC from a battery, yet fine for closer range (<1.5m) at 3.3v.
    Have ordered another JSN in hopes it is better behaved at 3.3v, it must be a QC issue...

    Today the second (troublesome) one is working at range on 3.3v, but it is not reliable. I have it try max 10 times (I think) to get a valid reading every hour, so it does not kill the batteries much.
    Whether yours will work at 3.5m or not you can only test, but having a mains supply means battery power is no barrier..

  • @Sundeep-Goel did u face any issues due to water vapours or water in general?

Log in to reply

Suggested Topics

  • 3
  • 2
  • 3
  • 1
  • 15
  • 2