Arduino waterproof sonar

Hi, I'm new to arduino. I made a project of water level indicator for 4m high tank using with JSN-SR04T-2.0. It's working fine till 334cm distance. After that Percentage goes to 181%. Hear is my codes. Please Help me.

tha_new.ino (3.61 KB)

Best guess: you're getting reflections from something inside that tank, or you're getting below the minimum range of your sensor.

Code is too messy to read, lack of code tags isn't helping.

Sorry for the durtyness of codes. I'm new to arduino.

Tharaka9:
Sorry for the durtyness of codes. I'm new to arduino.

In your IDE, hit "Ctrl+t" to format your code.

And place your code on this forum between [code] your code here [/code] tags.

You would also be doing yourself a favor by reading How to use this forum - please read.

ps.

you can edit your post and add the code tags

The code you posted (badly) hasn't got a hope of compiling, so it can't possibly produce any results, good or bad

I'm modified my post. can you please checkout and give me solution,

Do you expect the height of the tank to change from loop to loop?
Do you envisage using NewPing?
pulseIn returns an unsigned long, not an int.
I don't know why you're toggling the pullup resistor on pin 8.

Can you please show my mistakes on my project with highlight. I dont need to add tank hight loop to loop. Bit whir can i place that.

Tharaka9:
Hi, I'm new to arduino. I made a project of water level indicator for 4m high tank using with JSN-SR04T-2.0. It's working fine till 334cm distance. After that Percentage goes to 181%. Hear is my codes. Please Help me.

334 cm is over 10 feet, is that correct ? what does the data sheet show as the minimum and maximum ranges ?
I know that under about 9 inches the sensor cannot work due to timing issues.

Yes. Sensor range is - max 6m and min- 20cm

Can you please show my mistakes on my project with highlight

pulseIn returns an unsigned long, not an int.

https://www.arduino.cc/en/Reference/VariableDeclaration

Pay special attention to “Variable Rollover”

Your distance variable is an int. It should not be an int.

334 x 2 = 668 cm travel.

At 0.0343 cm/us (can't see your code on this device as it's attached, too much work to make it visible, formula should be the same) = about 20,000 us pulse time. That's not resulting in an overflow of an int, which would occur at just over 32,000.

using his equation, percentage can only equal 188 if distance is negative.

Algebra Calculator - MathPapa)%20%2F%20380)

distance would have to be -324.4 which would make duration
−18537.142857

Since pulsein only a positive number, duration must be rolling over.

Not great at math over here so i might be wrong.