Go Down

Topic: JSN-SR04T-2.0 (Read 20443 times) previous topic - next topic

distantkitty

Ping!

Anyone resolve this issue?  I spent the entire day trying to get this 2.0 sensor to work.  I had readings at one point.  The data was coming through fine and i was so excited.  Then the readings went erratic, then they stopped coming entirely.  I have no idea why.  Input_pullup has no effect.  No matter which version of the sketch i used, pullup or no-pillup, i got no readings.

Is anyone having luck with adding a resistor? 

I have a water storage tank and really need to be able to monitor the level.  Any alternative sensors or solutions?

If anyone has this working please post explicit details on how you did so.  Also, an example of a very basic sketch would be appreciated.

Thanks in advance.

-Tom
You can always use a float switch or a water level meter. The float switch would give you a variable resistance value, like a car fuel tank. They also make then where they close a switch at a certain height. Not sure if you need a distance feedback or just a If  thus Then do this when water reaches a level

560242

Dear All, I think I may have a solution for many of you.  I too was really disappointed to receive my JSN SR04T sensors this morning and discover that they were the Version 2.  About one reading in every 10-20 came back as zero.  However, thanks to pityuka I could see that the datasheet for this version states that a MINIMUM of 10microseconds is needed for each trigger pulse.  I can also also see that most Arduino libraries suggest a trigger pulse of 10microseconds.  All I did was MAKE THE TRIGGER PULSE 20MICROSECONDS, not 10microseconds and the problem was immediately fixed.

I'm using the same pin on a LOLIN D32 to provide a 3.3V trigger pulse and then listen for an echo.  I'm getting the same accurate and consistent results whether I use a 5V supply for the sensor or the board's own 3.3V output.  If I use a 5V supply then I am stepping the echo voltage down through a resistor pair voltage divider.  Setting pinMode as PULLUP or not makes no difference at all.  Code is pasted below for anyone who needs it.  Hope it helps this frustrating problem.

  pinMode(sensor1Pin, OUTPUT);
  digitalWrite(sensor1Pin, LOW);
  delayMicroseconds(2);
  digitalWrite(sensor1Pin, HIGH);
  delayMicroseconds(20);
  digitalWrite(sensor1Pin, LOW);
  pinMode(sensor1Pin, INPUT);
  duration = pulseIn(sensor1Pin, HIGH, timeout);
  distance1 = duration*0.0343/2;
  pinMode(sensor1Pin, OUTPUT);
 
  Serial.print("Sensor1");
  Serial.print(" = ");
  Serial.print(distance1);
  Serial.print("cm. ");
  Serial.println();
 
  delay(100);

tomlu2000

Thanks for the responses.  I have mine working now.  I'm not sure what made the difference but here's the code I use.  The information I'm getting tells me how far above or below my optimum sump tank level.  The goal is to prevent the tank from getting so low the submersible pump can't pump water to keep the fish alive and circulate water through the grow beds and towers. The calculated value is not the actual distance but a differential from 35cm.  I multiply it times -1 so a shorter distance is positive (fuller tank) and a negative distance is bad (empty tank).  This information gets published to my mqtt server.  I have rules in openhab that text and e-mail me when the levels go negative.  And, I'm not using PULLUP.  Works like a charm.

void getSumpDepth()
{
  Serial.println(" ");
  Serial.println("Reading Tank Depth");
  digitalWrite(TRIGPIN, LOW); // Set the trigger pin low for 2us
  delayMicroseconds(2);
  digitalWrite(TRIGPIN, HIGH);  // Send a 10us high to trigger ranging
  delayMicroseconds(20);
  digitalWrite(TRIGPIN, LOW); // Send Pin low again
  sump_distance = pulseIn(ECHOPIN, HIGH,26000); // Read in times pulse
  sump_distance = ((sump_distance/58) - 35) * -1;
  Serial.print(sump_distance);
  Serial.println("  cm");
}

ramkumar_d_d

The sample code here works for both V1.0 and V2.0
https://www.dfrobot.com/wiki/index.php/Weather-proof_Ultrasonic_Sensor_SKU_:_SEN0207
I have used this code and i am okay with the reading. But only issue is getting ZERO after every few correct readings. How to deal with this?

Thanks in Advance,
Ram

ramkumar_d_d

Dear All, I think I may have a solution for many of you.  I too was really disappointed to receive my JSN SR04T sensors this morning and discover that they were the Version 2.  About one reading in every 10-20 came back as zero.  However, thanks to pityuka I could see that the datasheet for this version states that a MINIMUM of 10microseconds is needed for each trigger pulse.  I can also also see that most Arduino libraries suggest a trigger pulse of 10microseconds.  All I did was MAKE THE TRIGGER PULSE 20MICROSECONDS, not 10microseconds and the problem was immediately fixed.

I brought these sensors from china alibaba. I did same as you and problem has been resolved thank you. I did changed only the delay to 20 microseconds. It is very useful

photogrammer

I have a related question... I have this same sensor and got it working with NewPing and 3.3v. Did not have to use the 20µs (vs 10) ping tweak. NewPing, in fact, uses 10µs.

Warning... stream-of-consciousness attempt to solve spurious results:

My water tank is 1500 gallons, rectangular with two round lids. I mounted the sensor in the center of the lid that had no obstructions to get in the way of measurements. When I close the lid I get spurious results... so on a whim I taped a 3cm section of toilet paper roll around the sensor. This did the trick so I designed and 3d printed a same-sized tube with mounting bracket using plastic, of course. Now that version doesn't work... unless I offset the lid by a few inches to any side. The bad results I'm getting around around 32cm which is about the distance from the sensor to the cylindrical wall that the lid sits on... so I'm thinking there is an early ping/echo that returns... and the paper roll maybe absorbed that early reflection. I could wrap the plastic with something soft... will try that.

Only posting this question to see if anyone else has clever solutions to their ultrasonic sensor issues!

Thanks!

photogrammer

#21
Sep 21, 2018, 01:37 am Last Edit: Sep 21, 2018, 01:37 am by photogrammer
Ok, I learned both empirically and now in a manufacturer's instruction manual that installing an ultrasonic sensor in the center of a tank (or in my case, lid and cylindrical flange) is the wrong spot!

https://blog.lesman.com/2012/01/27/best-location-for-installing-ultrasonic-level-transducer/

page 3 of this PDF:

http://www.lesman.com/unleashd/catalog/sensors/Milltronics-Echomax-transducers/Installing-Ultrasonic-Level-Sensors.pdf

Hope that helps somebody! It helped me! :-)

chillmeister93

Has anyone used several of these sensors together?

Also is it possible to use the analog pins on an Arduino for the Trig signal when using them in mode 1? Reason for this is I need 8 sensors wired up to 1 Arduino Uno (not enough digital IO pins for the 16 connections needed), or can I simply connect several of the trig wires to one digital pin?

Thanks in advance.

Wharto

Guys you have saved me a world of pain! Really appreciate the groups input, knowledge and time.

This is the code I ended up using with the updated TRIGPIN delay to 20uS. It's solid as a rock now, not throwing any random measurements.

  digitalWrite(TRIGPIN, LOW); // Set the trigger pin to low for 2uS
  delayMicroseconds(2);
  digitalWrite(TRIGPIN, HIGH); // Send a 10uS high to trigger ranging
  delayMicroseconds(20);
  digitalWrite(TRIGPIN, LOW); // Send pin low again
  int distance = pulseIn(ECHOPIN, HIGH,26000); // Read in times pulse
  distance= distance/58 - 20;
  Serial.print("Distance ");
  Serial.print(distance);
  Serial.println("cm");                   
  if(distance < 10 ){
    digitalWrite(relay[1], HIGH); Serial.println("Water Pump Off");
  }else{
    digitalWrite(relay[1], LOW); Serial.println("Water Pump On");
  }
  delay(5000);

I do have a question regarding minimum distance.

Is there a way to improve the accuracy within 20cm? I'm using it for a water tank which is 60cm deep. At the moment I'm using distance -20 to give me a 0cm starting point. Other than that I may just have to raise the sensor 20cm from the top of the tank. I'll have a go at working it to show as a % over the next few nights (have limited spare time with a young family).

Appreciate any advice on trying to improve the accuracy for <20cm.

Treath

photogrammer

I don't think the sensor is accurate or usable below 20cm... so the solution is to mount the sensor so there is at least 20cm of clearance. Here's a way of doing just that, a "stilling well".

https://www.apgsensors.com/about-us/blog/how-to-install-a-stilling-well

This has the added benefit of stilling the water so false readings are less likely. I have not installed one of these, however.

Wharto

Great reference thank you photogrammer!
Sorry for the late reply, I hadn't set up my alert preferences and have only just stumbled on your update.
I will try your suggestion this week and let you know of the outcome.

knx_domo

I had the same problem, the readings changed continuously. I have 3 sensors with their 3 cards JSN-SR04T-2.0. In my case the problem was due to interference in the SR04T card, the solution was to wrap it in plastic and cover it with aluminum foil. Now I have stable readings when the objects are less than 3 meters away. I'm happy with these sensors. (Yo tube el mismo problema, las lecturas cambiaban continuamente. Tengo 3 sensores con sus 3 tarjetas JSN-SR04T-2.0. En mi caso el problema era debido a interferencias en la tarjeta del SR04T, la solución fué envolverla en plastico y cubrirla con papel aluminio. Ahora tengo lecturas estables cuando los objetos estan a menos de 3 metros. Estoy contento con estos sensores.)

developerunify

I had the same problem, the readings changed continuously. I have 3 sensors with their 3 cards JSN-SR04T-2.0. In my case the problem was due to interference in the SR04T card, the solution was to wrap it in plastic and cover it with aluminum foil. Now I have stable readings when the objects are less than 3 meters away. I'm happy with these sensors. (Yo tube el mismo problema, las lecturas cambiaban continuamente. Tengo 3 sensores con sus 3 tarjetas JSN-SR04T-2.0. En mi caso el problema era debido a interferencias en la tarjeta del SR04T, la solución fué envolverla en plastico y cubrirla con papel aluminio. Ahora tengo lecturas estables cuando los objetos estan a menos de 3 metros. Estoy contento con estos sensores.)
I gave up on JSN SR04T v2.0 because the PCB is not waterproof and it has a blind spot of around 20cm. I went for this one instead: https://www.ebay.com/itm/253978673298

sundeepgoel

I gave up on JSN SR04T v2.0 because the PCB is not waterproof and it has a blind spot of around 20cm. I went for this one instead: https://www.ebay.com/itm/253978673298
can you post the link or the part details / model no - current link is broken

Ishrati

thank you photogrammer you just saved me from a costly mistake, i was going to make a 4 inch hole in the center of multiple tanks to place the sensor on a pvc pipe for clearance.

i was also facing the same problem of the occasional 0 reading but i solved it by ignoring 0 result and getting a fresh reading.

Code: [Select]
while (distance == 0) {
      delay(100);
      getDistance();
 
  }


i am also using 20 microseconds pulse.  it gives much better accuracy.
i also physically measured the distance and callibrated the multiplier to get a more accurate result.
Code: [Select]
distance = duration*0.0176249304641415;
its inaccurate at longer distances but for my purposes its good.

Go Up