Water level controller system

I’m about to buy my first arduino products for a project, but need help. I’m trying to build a system that allows me to maintain a certain water level, while simoultaneously draining “old” water from below and filling fresh water from above. I’ve attached a sketch.

So from what I’ve read, I need;
1 Arduino UNO
2 Solenoid valves
1 Water level sensor

So, am I missing something? How hard is this to write in terms of code?

Thank you!

You seem to have posted a picture. Please post your program as text and use the code button </>


I haven't written any code yet. I was just wondering what components I need in order for this to work

What you have is a good start but you need to pick specific examples. E.g. unless it's a really tiny system you'll probably need something to drive the water valves because the direct current available from an Arduino pin will almost certainly not be enough to operate the valves. And you'll definitely need a power supply of some sort.

The coding is unlikely to be very difficult, if only because so many other people have already written similar systems.


I haven't written any code yet. I was just wondering what components I need in order for this to work

Alas the Arduino world uses the word "sketch" to mean program so I misunderstood your Orginal Post. (Not your fault - it's a stupid idea to call a program a sketch :slight_smile: )

Here is the image from the Original Post so we don't have to download it. See this Simple Image Guide


You have valves for both Fill and Drain. Sounds like you only need to know if the water level is above or below a certain level so a float pushing a switch would be a sufficient "level sensor". You don't really need the Arduino at all. Just have the "level sensor" control a double-throw relay. If the level is high, close the Fill valve and open the Drain valve. If the level is not high, close the Drain valve and open the Fill valve. What would the Arduino add?

if you have a drain that has a manual valve so you can let it constantly run.....
you can add a float valve to maintain water lever.

no electronical bits needed.

what is missing is an overflow in case the supply is a run-away open valve

as for the electronificatiom of the project

ultrasonic water level sensors
2 electric ball valves
power supply for the two valves
relays to control the valves

ultrasonic level control in the supply tank
ultrasonic level control in the drain tank

wifi link to txt your cell phone when water in supply tank is low
wifi link to txt your cell phone when water in the drain tank is too full
wifi link to post data for long term graphing of the tank levels

LCD display to indicate the valve postings, time since last opening....

You might want to consider having a second water level sensor, at a slightly different height.

You then have an upper level sensor and a lower level sensor.

Fill until the water reaches the upper level sensor, then stop filling.
Then allow the water to drain (you don’t have to do this straight away - you can introduce a delay), until the lower sensor is clear of the water, then stop emptying.
Then after another (again optional) delay start filling again, until the upper level sensor is reached.
Then just repeat as necessary.

If you do decide to have delays, or want the filling/emptying to occur at certain times of day, then you might want to add a Real Time Clock (RTC) module to your “shopping list”

Good luck with your project.

water level :
a float switch will tell you if water if above a point, or below a point. think of ocean tides, of you have a high water sensor, the water can be 1mm lower or 3 meters lower, the switch would not know the value, just that it is lower.

an ultrasonic sensor can detect the distance from the sensor, so, it can offer a value of how much lower.
lots of code and sketches for that can be found on the web. easy to buy (cheap) and easy to use.

you could use one on the upper reservoir and one on the center tank.

as for the two solenoids, I will assume they are high power. you would use a relay board to turn the power off and on for them.

the Arduino puts out a lower power signal to turn the relays on and off, but the relay turns the high power on and off for the solenoids. These are very simple to control. very easy to write a sketch for them.

you would read the level of the water. say the empty tank is 200 and the full tank is 15.
the further away from the sensor, the higher the number.

the general idea of your sketch would be :

read the tank level

if the tank reading is greater than 30
then turn on the relay

if the tank reading is less then 20
then turn off the relay

this is a GREAT first project as you can buy the needed parts and then just assemble them.

Do you need to monitor the drain tank to make sure it doesn't overflow?

How frequently will you be activating the drain solenoid?

Make sure that both valves will default to closed when the power fails.

Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.

I agree a good starting project, but the interfacing will be very important, we need to know what power supply, voltage, you would possibly be running your project off.

Water level sensors come in many different guises but most are not for long period use. A float switch would work best and has been mentioned a lower level float switch as well.

I would imagine so as not to stir the water in the middle tank, you will first drain, then stop, then fill, so that you are draining only old water.

Tom... :slight_smile:

more notes :

the drain will turn on 4 times a day (or whatever you want)
the drain will remain on for 3 minutes (or whatever you want

the level sensor for the main tank will check level once per minute all day long.
if the level is lower than the correct value,
the solenoid will be turned on
if the level is higher
the solenoid will turn off
as a note, the water level can turn on for any reason at any time.

you can also monitor the level of the supply tank and the discharge tank will more sensors

you can light lights to show green red or yellow

Vote here for the ultrasonic sensor for measuring water level.
I am using a one of those cheap ultrasonic sensors(HC-SR04) in one of my projects as a water level sensor. It works great, no moving parts to go wrong. Measuring is accurate, as long your air temperature reading is accurate and your code calculates the speed of sound correctly in the current air temperature, humidity is also preferred to take in the equation.

If you don't use the current temperature and humidity to calculate the distance reading, your accuracy suffers quite a bit. These sensors are really better that their reputation is. I think most of the time people just don't use them correctly.

Just my two cents.

There are two versions of the ultrasonic one is car backup sensors with a special driver board
car backup

the other is the open ones
open sensor

if it’s project inside, and weather/water proof is not needed, the cheaper open ones will work great

Thank you for all the ideas! It seems that I have to check some previous projects to get a better understanding of how this platform works. I'll do so and get back to you soon!