# How to calculate the time it takes before the water valve stops dispensing water in an Automatic Water level controller?

I am making a project about an automated water level controller using ultrasonic, potentiometer and Arduino board. I need a mathematical calculation on how it works. So here's a simple scenario:

I have an open top cylindrical container with a radius of 7cm. The ultrasonic sensed that the half height of the container, which is 15cm, is filled with water. At the bottom part of it, a tube with a radius of 1cm is connected alongside with the water valve. How can I calculate the time needed for the water valve to stop dispensing water if I set the potentiometer to keep the level of water at 9cm only? Can you give me a mathematical formula??

• Wouldn't it be easier to measure it? Configure the system to stop at the desired point, run it, see where the water level actually ends up. Build in a correction based on the difference, and try it again. Modeling this is potentially academically interesting but requires information you have not presented about valve actuation time. Most fill systems don't try to maintain an exact level, but have a deadband to avoid premature wearout of the valve. Jan 8 '17 at 17:47
• One could use a peristaltic pump and skip the complications of using a sensor. Or, using the keep it simple rule, I would use a float switch. Or, simpler yet, a mechanical float as the one in your toilet. If you do use an electronic sensor be sure to add a bit of hysteresis so that your solenoid/valve will not prematurely fail. Jan 8 '17 at 18:12
• This looks like a high school physics question wrappen in an Arduino question. But why would you need to calculate the time, if you can just continually measure the distance and turn of the valve if the distance is 6cm? Jan 8 '17 at 18:25

The concept you have is more complicated than you can imagine. But to answer your question (which is not so arduino-based), the mathematical formula you looking for is Torricelli's Law.

My suggestion for you is design a system which use a feedback concept instead Sounds like it's the valve's time to close (t_vc) + half (statistically) the measurement interval (t_interval) + the software reaction time (t_sw). So

Add whatever measurement interval the software uses, if any, and the valve's time to close, once activated, and the software's time to react (from decision to actually making the valve-close signal) and you should have it. So:

T = t_sw + t_vc + 0.5*t_interval

Any software reaction time should be negilgible for practical purposes, so we're down to:

T = t_vc + 0.5*t_interval

If the software doesn't include sleeps or delays but loops continuously, measuring and deciding, then the half-interval reduces to negligibility leaving just the valve closure time:

T = t_vc