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
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();
}```
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.
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