I guess you might be right but 2% from 5 meter is 100cm and for a river level it make lot of different. So i tried using average, and it seem to work(static value). So in order to measure the river level i took two point. The point I took is 3.72 meter and 4.76 meter. And build a formula using y=mx+c. But if the the real river level went 4.20 my calculation is less 2% that is 4.1. Is there other way? Thanks
I think 2% of 5 meters is 10 centimeters.
Is the water flowing?
Is the sensor ultrasonic?
Is it sensitive to movement in what is being monitored?
You might be better off with a filter on the input channel. This filter can be analog (someone suggested a simple capacitor and using the resistance of the circuit itself for an RC filter). Or it can be digital.
If you only need measurements every so often (say, every 10 seconds), then you can measure more often than that (say, every 1 second, or 10 times a second) and average the measurements. This will serve as one kind of filter that doesn't need analog components, but is implemented entirely digitally (as "DSP.")
Other kinds of filters go from the "leaky integrator" (technically a single-pole filter) through the "bi-quad" (technically a two-pole/two-zero filter) through more advanced cascades of filters, where the problem starts becoming precision loss in the digital math, or convolution filters, where the problem starts becoming the number of math operations needed per sample. Technically, taking 10 or 100 readings and then reporting the average of them is a simple form of convolution and down-sampling in a single operation. Not so good for fast signals (like sound, say), but probably very good for your particular use case :-)