Measuring depth of pool with water pressure sensor

I have Gravity Water Pressure Sensor SKU SEN0257, i want to measure precision value of the water depth because i will use for my AUV's PID controller.
So the values are not stabilize, Here is my code.

I hope someone help, thanks :slight_smile:

void setup()
{
  Serial.begin(9600);        // open serial port, set the baud rate to 9600 bps
  Serial.println("/** Water pressure sensor demo **/");
p1=1;
p2=1;
k=0;
}
void loop()
{
 //Connect sensor to Analog 0
  V = analogRead(0) * 5.00 / 1024;     //Sensor output voltage
  P = (V-0.483) * 400;             //Calculate water pressure

  //// filtration
p1=(P+p1)/2;
p2=(p1+p2)/2;
p3=(p1+p2+P)/3;
d=(p3/9.81);
  
  
  
  Serial.print("Voltage:");
  Serial.print(V, 3);
  Serial.println("V");

  Serial.print(" Pressure:");
  Serial.print(p3, 1);
  Serial.println(" KPa");
  Serial.println();
  
Serial.print(" Depth:");
Serial.print(d);
Serial.println(" meter ");
  Serial.println();
}```

Please post all of your code.

(Why did I even have to write that?)

This code looks like a weak smoothing filter. Did you make this up or find it somewhere?

Many people have found a simple exponential smoothing filter to be useful. Something like this:


float p1=0;
float alpha = 0.05; //smaller for more smoothing
...
// in loop():
P = get_pressure();
p1 = p1*(1-alpha) + P*alpha;
...
1 Like

I just didnt post the declaration of V and P, this is my whole code for testing pressure sensor

Mate, thank you so much it worked but p1 value is keeping increase how can i solve that. Sorry it looks easy but i am newbie.

If you want help, ALWAYS post ALL of your code, as described in the How to Use the Forum post.

Ok sorry i will post now

You didn't subtract atmospheric pressure from the reading so you'll see about 10m depth, and due to the filtering this will be an exponential approach to 10m which may be what's confusing you?

Why are you low-pass filtering BTW - just to reduce noise? This will add a lag to the reading and any lag in response is bad news for a PID system.

1 Like

Just a SWAG but that is an analog sensor where power supplies need to be clean and stable. You might post a schematic showing how it is connected to your arduino. Also what is powering it. Try a small cap at the +5 and Gnd terminal of the sensor and see if that helps. I try to get my sensor outputs stable first, that keeps the code much simpler.

What are the minimum and maximum depths you want to measure? What liquid is in the pool? Why not use an ultrasonic distance measuring device located at the top of the pool? I am doing that for a swimming pool. The sensor is 7 cm above the top of the filled pool pointing down. It gives me the distance to the current water level. It works fine. I'm using A02YYUW Waterproof Ultrasonic Sensor SKU: SEN0311-DFRobot

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.