solenoid valve

Hi there,
I wonder if you could help me with this project .
This is my first project and it's simple but it look hard for me :slight_smile:
There is a tank that has 2 solenoid valve one for incoming water and the other for outgoing water. When the tank reaches its maximum capacity the incoming water valve would close and the outgoing water valve will open. After tank got empty of water , the opposite things would happen. The incoming valve will open again and the outgoing valve will close and this cycle will never end until I press the off button.

I think that the components that i need are :

  1. Arduino
  2. Ultrasonic Sensor or prob maybe
  3. 2 12V or 5V Solenoid Valve

A float switch will be easier to use and more reliable to detect when the tank is full.

Does the tank always empty at the same rate? You could time the closing of the output valve.

You will need two relay modules to control the solenoid valves, or two MOSFETs (e.g. irl520 or stp16nf06l).

thanks for your help
The problem is the flow rate doesn't have the same amount and it may change by the time so i can't use the time for closing the valve
and thanks for the relay modules thank you very much

Just to clarify on the sequence, which will inform the coding, this is a never ending cycle of automatically emptying as soon as it's full, and only starting to let water in again when it's actually empty?

So it's not like say a toilet cistern which remains full until someone flushes, and which starts to fill as soon as the ball drops even a centimetre or so?

(I'm curious to know the application.)

there is no application for it :))
just i want to know how to do it

work it out on paper

if the fill_state is to fill. // filling is all under this if()
and if the tank is not filled
then the valve is open
else
if the tank is filled
then close the valve
change the fill_state to drain.

if the fill_state is to drain // draining is all under this if()
and the tank is not empty
then the drain valve is open
else
if the tank is empty
then close the drain valve
change the fill_state to fill

you just need to have that fill_state flag toggle and use that to select what part of the code to follow.

if you want to add a delay, or timer or introduce a button to make it manual, you can do that as well.