Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Trouble with the JSN SR04T

Trouble with the JSN SR04T

Scheduled Pinned Locked Moved Troubleshooting
23 Posts 5 Posters 2.7k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Sundeep Goel

    @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 :)

    zboblamontZ Offline
    zboblamontZ Offline
    zboblamont
    wrote on last edited by
    #6

    @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...

    S 1 Reply Last reply
    0
    • bgunnarbB bgunnarb

      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.

      zboblamontZ Offline
      zboblamontZ Offline
      zboblamont
      wrote on last edited by
      #7

      @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...

      1 Reply Last reply
      0
      • zboblamontZ zboblamont

        @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...

        S Offline
        S Offline
        Sundeep Goel
        wrote on last edited by
        #8

        @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

        zboblamontZ 1 Reply Last reply
        0
        • S Sundeep Goel

          @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

          zboblamontZ Offline
          zboblamontZ Offline
          zboblamont
          wrote on last edited by zboblamont
          #9

          @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?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sundeep Goel
            wrote on last edited by Sundeep Goel
            #10

            @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);
              delayMicroseconds(2);
              digitalWrite(trig, HIGH);
              delayMicroseconds(10); 
              digitalWrite(trig, LOW);
            

            Tank - total height say 130cm
            0_1563950353958_IMG_20190724_114412.jpg
            Mounting Hole - its offset from the side by 25cms
            1_1563950353959_IMG_20190724_114522.jpg
            Inside of the tank
            2_1563950353959_IMG_20190724_114533.jpg
            JSN 04T driver module
            3_1563950353959_IMG_20190724_114804.jpg
            Sensor head mounted inside standpipes
            4_1563950353959_IMG_20190724_114859.jpg

            zboblamontZ 1 Reply Last reply
            1
            • S Sundeep Goel

              @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);
                delayMicroseconds(2);
                digitalWrite(trig, HIGH);
                delayMicroseconds(10); 
                digitalWrite(trig, LOW);
              

              Tank - total height say 130cm
              0_1563950353958_IMG_20190724_114412.jpg
              Mounting Hole - its offset from the side by 25cms
              1_1563950353959_IMG_20190724_114522.jpg
              Inside of the tank
              2_1563950353959_IMG_20190724_114533.jpg
              JSN 04T driver module
              3_1563950353959_IMG_20190724_114804.jpg
              Sensor head mounted inside standpipes
              4_1563950353959_IMG_20190724_114859.jpg

              zboblamontZ Offline
              zboblamontZ Offline
              zboblamont
              wrote on last edited by zboblamont
              #11

              @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(Ultrapin,OUTPUT);
                 pinMode(Trigpin, OUTPUT);
                 pinMode(Echopin,INPUT);
                 pinMode(flasher,OUTPUT);
                 analogReference(INTERNAL);//All voltage reads are to 1.1 internal datum
                 sleep(100);//Allow things to settle was 1000
                 Wire.begin ();
                 RTC.begin();
                 RTC.adjust(DateTime(__DATE__, __TIME__));   //set RTC date and time to COMPILE time
              
              //clear any pending alarms
                 RTC.armAlarm(1, false);
                 RTC.clearAlarm(1);
                 RTC.alarmInterrupt(1, false);
                 RTC.armAlarm(2, false);
                 RTC.clearAlarm(2);
                 RTC.alarmInterrupt(2, false);
              
                //Set SQW pin to OFF
                 RTC.writeSqwPinMode(DS3231_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);
                present(THIRD_CHILD_ID, S_MULTIMETER);
              }
              
              void loop(){
              // Power up US
                  VON();
                 sleep(100);//Delay to stabilise
                 digitalWrite(Trigpin,HIGH);
                 sleep (100); 
                 digitalWrite(Trigpin,LOW);
                 sleep(100);/// Allow decay of pulse
                 int voltread;
                 counter=0;
                 tankdepth=0;
                 while ((tankdepth<350||tankdepth>1130)&&counter<=10){//10 attempts to get proper range, recalibrated 6/7/2019
                 READULTRASONIC();
                 counter++;
                 } 
              //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
                 VOFF();
                 sleep(100);
                 send(msg1.set(tankvolume));//This is actual volume
                 sleep(100);
                 send(msg2.set(tankpercent,1));//This is remainder to start of 39cm Freeboard
                 sleep(100);  
                 }
              //   }
                 VOFF();//If 2nd flash, reading sent, only 1 is fail
              // Call for battery reading, send in every 12th RTC call?
                 if(halfday==12){
                 digitalWrite(BatteryOn, HIGH);
                 voltread = analogRead(BatteryIn);
                 float voltage = (7.272 * voltread) / 1024;
                 sleep(5);
                 digitalWrite(BatteryOn, LOW);
                 send(msg3.set(voltage,2));
                 sleep(50);
                 voltread=0;
                 sleep(50);
                 halfday=0;//Reset for 12 hourly cycle
              }
                 halfday++;//Increment hourly cycle
              
              // Rearm alarm
                 Wire.begin();
                 RTC.begin();
                 RTC.alarmInterrupt(1, true);
                 sleep(50);
                 Wire.end();
                 sleep(50);
              //Go deep sleep until RTC interrups
                 sleep(digitalPinToInterrupt(REED_PIN),FALLING, SLEEP_TIME);
              sleep(100);///Time to recover
              //First clear the alarm
                 Wire.begin();
                 RTC.begin();
                 RTC.armAlarm(1, false);
                 RTC.clearAlarm(1);
                 RTC.alarmInterrupt(1, false);
                }  // end of loop
              
              void VON(){
                digitalWrite(Ultrapin, HIGH);
                digitalWrite(flasher,HIGH);
                sleep (6);
                digitalWrite(flasher,LOW); 
              }
              
              void VOFF(){
                digitalWrite(Ultrapin, LOW);
                sleep (10);
                digitalWrite(flasher,HIGH);
                sleep (6);
                digitalWrite(flasher,LOW); 
              }
              
                void READULTRASONIC(){//JSN-SR04-2.0
              //Main loop checks valid range on a defined number of readings
                tankdepth=0;
                duration=0;
                distance=0;
                test=1;
                test2=3;
              // 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){
                  test=distance;
                  distance=0;
                 }
                 else{
                  test2=distance;
                }
                delay(100);
                }
                tankdepth=distance;
               }
              
              S 1 Reply Last reply
              0
              • zboblamontZ zboblamont

                @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(Ultrapin,OUTPUT);
                   pinMode(Trigpin, OUTPUT);
                   pinMode(Echopin,INPUT);
                   pinMode(flasher,OUTPUT);
                   analogReference(INTERNAL);//All voltage reads are to 1.1 internal datum
                   sleep(100);//Allow things to settle was 1000
                   Wire.begin ();
                   RTC.begin();
                   RTC.adjust(DateTime(__DATE__, __TIME__));   //set RTC date and time to COMPILE time
                
                //clear any pending alarms
                   RTC.armAlarm(1, false);
                   RTC.clearAlarm(1);
                   RTC.alarmInterrupt(1, false);
                   RTC.armAlarm(2, false);
                   RTC.clearAlarm(2);
                   RTC.alarmInterrupt(2, false);
                
                  //Set SQW pin to OFF
                   RTC.writeSqwPinMode(DS3231_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);
                  present(THIRD_CHILD_ID, S_MULTIMETER);
                }
                
                void loop(){
                // Power up US
                    VON();
                   sleep(100);//Delay to stabilise
                   digitalWrite(Trigpin,HIGH);
                   sleep (100); 
                   digitalWrite(Trigpin,LOW);
                   sleep(100);/// Allow decay of pulse
                   int voltread;
                   counter=0;
                   tankdepth=0;
                   while ((tankdepth<350||tankdepth>1130)&&counter<=10){//10 attempts to get proper range, recalibrated 6/7/2019
                   READULTRASONIC();
                   counter++;
                   } 
                //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
                   VOFF();
                   sleep(100);
                   send(msg1.set(tankvolume));//This is actual volume
                   sleep(100);
                   send(msg2.set(tankpercent,1));//This is remainder to start of 39cm Freeboard
                   sleep(100);  
                   }
                //   }
                   VOFF();//If 2nd flash, reading sent, only 1 is fail
                // Call for battery reading, send in every 12th RTC call?
                   if(halfday==12){
                   digitalWrite(BatteryOn, HIGH);
                   voltread = analogRead(BatteryIn);
                   float voltage = (7.272 * voltread) / 1024;
                   sleep(5);
                   digitalWrite(BatteryOn, LOW);
                   send(msg3.set(voltage,2));
                   sleep(50);
                   voltread=0;
                   sleep(50);
                   halfday=0;//Reset for 12 hourly cycle
                }
                   halfday++;//Increment hourly cycle
                
                // Rearm alarm
                   Wire.begin();
                   RTC.begin();
                   RTC.alarmInterrupt(1, true);
                   sleep(50);
                   Wire.end();
                   sleep(50);
                //Go deep sleep until RTC interrups
                   sleep(digitalPinToInterrupt(REED_PIN),FALLING, SLEEP_TIME);
                sleep(100);///Time to recover
                //First clear the alarm
                   Wire.begin();
                   RTC.begin();
                   RTC.armAlarm(1, false);
                   RTC.clearAlarm(1);
                   RTC.alarmInterrupt(1, false);
                  }  // end of loop
                
                void VON(){
                  digitalWrite(Ultrapin, HIGH);
                  digitalWrite(flasher,HIGH);
                  sleep (6);
                  digitalWrite(flasher,LOW); 
                }
                
                void VOFF(){
                  digitalWrite(Ultrapin, LOW);
                  sleep (10);
                  digitalWrite(flasher,HIGH);
                  sleep (6);
                  digitalWrite(flasher,LOW); 
                }
                
                  void READULTRASONIC(){//JSN-SR04-2.0
                //Main loop checks valid range on a defined number of readings
                  tankdepth=0;
                  duration=0;
                  distance=0;
                  test=1;
                  test2=3;
                // 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){
                    test=distance;
                    distance=0;
                   }
                   else{
                    test2=distance;
                  }
                  delay(100);
                  }
                  tankdepth=distance;
                 }
                
                S Offline
                S Offline
                Sundeep Goel
                wrote on last edited by Sundeep Goel
                #12

                @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.

                ![0_1563969848049_ball-float-valve-500x500.jpg]
                (/assets/uploads/files/1563969850870-ball-float-valve-500x500.jpg)

                @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?
                0_1563969864761_New.jpg

                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.

                zboblamontZ 1 Reply Last reply
                0
                • S Sundeep Goel

                  @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.

                  ![0_1563969848049_ball-float-valve-500x500.jpg]
                  (/assets/uploads/files/1563969850870-ball-float-valve-500x500.jpg)

                  @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?
                  0_1563969864761_New.jpg

                  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.

                  zboblamontZ Offline
                  zboblamontZ Offline
                  zboblamont
                  wrote on last edited by
                  #13

                  @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....

                  S 1 Reply Last reply
                  0
                  • zboblamontZ zboblamont

                    @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....

                    S Offline
                    S Offline
                    Sundeep Goel
                    wrote on last edited by Sundeep Goel
                    #14

                    @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
                    https://s.click.aliexpress.com/e/73Fe2bm)

                    zboblamontZ 1 Reply Last reply
                    0
                    • S Sundeep Goel

                      @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
                      https://s.click.aliexpress.com/e/73Fe2bm)

                      zboblamontZ Offline
                      zboblamontZ Offline
                      zboblamont
                      wrote on last edited by
                      #15

                      @sundeep-goel No idea !

                      S 1 Reply Last reply
                      0
                      • zboblamontZ zboblamont

                        @sundeep-goel No idea !

                        S Offline
                        S Offline
                        Sundeep Goel
                        wrote on last edited by
                        #16

                        @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

                        S 1 Reply Last reply
                        1
                        • S Sundeep Goel

                          @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

                          S Offline
                          S Offline
                          Sundeep Goel
                          wrote on last edited by
                          #17

                          @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
                          0_1564249378245_51IeEZEgrqL.SX425.jpg

                          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.

                          S 1 Reply Last reply
                          1
                          • S Sundeep Goel

                            @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
                            0_1564249378245_51IeEZEgrqL.SX425.jpg

                            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.

                            S Offline
                            S Offline
                            Sundeep Goel
                            wrote on last edited by Sundeep Goel
                            #18

                            @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)

                            0_1564315108561_VLX.jpg

                            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.

                            zboblamontZ 1 Reply Last reply
                            3
                            • S Sundeep Goel

                              @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)

                              0_1564315108561_VLX.jpg

                              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.

                              zboblamontZ Offline
                              zboblamontZ Offline
                              zboblamont
                              wrote on last edited by
                              #19

                              @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..?

                              S 1 Reply Last reply
                              0
                              • zboblamontZ zboblamont

                                @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..?

                                S Offline
                                S Offline
                                Sundeep Goel
                                wrote on last edited by
                                #20

                                @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

                                Papari DasP 1 Reply Last reply
                                1
                                • D Offline
                                  D Offline
                                  dmacros
                                  wrote on last edited by
                                  #21

                                  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?

                                  zboblamontZ 1 Reply Last reply
                                  0
                                  • D dmacros

                                    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?

                                    zboblamontZ Offline
                                    zboblamontZ Offline
                                    zboblamont
                                    wrote on last edited by
                                    #22

                                    @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..

                                    1 Reply Last reply
                                    0
                                    • S Sundeep Goel

                                      @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

                                      Papari DasP Offline
                                      Papari DasP Offline
                                      Papari Das
                                      wrote on last edited by
                                      #23

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

                                      1 Reply Last reply
                                      0
                                      Reply
                                      • Reply as topic
                                      Log in to reply
                                      • Oldest to Newest
                                      • Newest to Oldest
                                      • Most Votes


                                      19

                                      Online

                                      11.7k

                                      Users

                                      11.2k

                                      Topics

                                      113.1k

                                      Posts


                                      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                      • Login

                                      • Don't have an account? Register

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • MySensors
                                      • OpenHardware.io
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular