I would like to use the JSN-SR04T 2.0 in order to find the depth of a body of water. Once I test the sensor in a body of water, the distance measurements are then constant at about 20 cm. I then changed my distance formula to account for the speed of sound in water, but the measurements are still constant despite change in the body of water. Does anyone have any recommendations on how to obtain better measurements underwater?

#define trigPin 2
#define echoPin 3

// Define variables:
long duration;
int distance;

void setup() {
  // Define inputs and outputs
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  // Begin Serial communication at a baudrate of 9600:
void loop() {
  // Clear the trigPin by setting it LOW:
  digitalWrite(trigPin, LOW);

 // Trigger the sensor by setting the trigPin high for 10 microseconds:
  digitalWrite(trigPin, HIGH);
  digitalWrite(trigPin, LOW);

  // Read the echoPin. pulseIn() returns the duration (length of the pulse) in microseconds:
  duration = pulseIn(echoPin, HIGH);

  // Calculate the distance:
  distance = duration*0.034/2;

  // Print the distance on the Serial Monitor (Ctrl+Shift+M):
  Serial.print("Distance = ");
  Serial.println(" cm");

  • What is the approx depth of the water? That sensor seems to be good to about 20 ft. Also since you didnt post your code, or anything about how your using the sensor, its hard for anyone to give you an answer.
    – Chad G
    Sep 23, 2019 at 20:37
  • Sorry. Here is the code.
    – Edwin Choi
    Sep 23, 2019 at 21:24
  • @ChadG the body of water im testing has a depth of 50 cm
    – Edwin Choi
    Sep 23, 2019 at 21:25

1 Answer 1


According to the data sheet the minimum target distance is 20cm in the open air at a 343 m/s

The speed of sound in water is 1481 m/s so the minimum distance would be 20cm x 1481 / 343 = 86cm.

enter image description here

You cannot measure distances under 83cm in water.

  • Thanks. I'll try the sensor out in a 4 foot deep pool.
    – Edwin Choi
    Sep 24, 2019 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.