Hydroponic tank floats and Valve setup

Could someone help create a routine to empty and fill up the water is a hydroponic tank once a week automatically? I have 2 floats, one Solenoid valve and a 4 channel relay.
I also need to buy another Solenoid valve to fill up the tank
Sorry but I don’t have much experience programming. Thank you in advance.

Unless you have a Real Time Clock, Arduino may not be the best option for doing something “once a week”. The time counter counts since boot & the counter over-flows after about 50 days. If you are using delay node to determine when to run purge cycle, it MIGHT be smart enough to handle this for you.

I assume you will mount the two floats so one will turn off when tank is empty & 2nd will turn on when tank is full; these can be read using ‘button’ node (or just a digital-read node). The solenoids will connect to relay which can be controlled via ‘relay’ node in XOD.

The button, flip-flop, and relay on the left would be for the drain; those on the right are for the fill. When program starts, the drain is opened. Once the tank is empty, the drain solenoid is turned off & fill is turned on. When tank is full, fill solenoid is turned off and delay timer is started to repeat the process in one week. The puls… node for the drain is pulse-on-false (send pulse when tank is empty); the puls… node for the fill is pulse-on-true (send pulse when tank is full). Depending on how the floats are wired, you may need to change these.

I don’t know how well this handles the time over-flow. It might work fine. It might stop working after 50 days. It might start an extra cycle on day 50.

NOTE: There is sort-of a bug here. The delay timer is started when fill solenoid is turned on as well as when it is turned off. In this case, it should not be a problem since tank should fill in less than a week & delay timer will be restarted when tank fills, but could be an issue for shorter timer (you could use pulse-on-true output instead of relay-ACK to trigger delay-SET, or you could use the ‘any’ output so process restarts in one week instead of one week plus the time it takes to empty and refill the tank).

In case you don’t already know, The flip-flop nodes in this example are just used to remember current state of each relay. flip-flop-MEM is either True or False. The default on boot is for all of them to be False (which should mean both solenoids are closed). When flip-flop-SET gets a pulse, flip-flop-MEM becomes True and stays that way until a pulse is received on one of the other input pins. A pulse on flip-flop-RST will change flip-flop-MEM to False. flip-flop-TGL can be used to toggle the output between True and False. The TGL pin could be used for this program, but you run the risk of toggling it the wrong way (for example, if someone bumps the tank after it is full so fill float turns off and back on, using TGL pin instead of RST pin would turn the fill solenoid back on; since it has already detected full, it will never go “full” again to turn the solenoid back off, and you will have a mess). While TGL is a bad idea for this program, there are other cases where it is a great idea, like a single button to turn a light on and off each time it is pressed.

I do have an RTC module:

how would I use th RTC in this case?

There are several other threads for using the RTC. Basically, you write one patch to set the time, then you can use the RTC nodes for reading the time in other patches. You should only need to set time on the RTC once (or you might have to reset it occasionally if it is not very accurate, or change it for daylight saving time if that is important for you).

In your case, you could pick a day off week and hour/min to run your cycle. If the cycle will take longer than one minute to run and you code it so that it doesn’t check clock while cycle is running, you should be ok. Otherwise you could run into problems where it tries to run multiple times during that minute, or if you check for specific hour/minute/second, there is a chance you would miss the second if processor was busy with other things. There are times you need to be careful about checking for exactly equal, but you should be ok if you only need to check day of week, hour, and minute.

Thank you again you make everything so easy to understand.
I have one more question, is there a node I could use that will alert me if any of my components stopped working?

That is a very tricky question…

Arduino board will have no way of knowing if floats or valves are working since there is no feedback. It can only assume value returned by float is correct & valve is responding when it is told to change, so there is no way to alert on the hardware like this attached to Arduino.

If you know tank fills in about 20 seconds, you could add code to make sure it is not still filling after 25 seconds (or something similar). You could add a 3rd float to indicate the system is about to over-flow (which could be tied directly to a buzzer so it alarms even if Arduino crashes).

The next question is how do you want it to alert you. You could just add a buzzer; you could equip the Arduino with internet access & send a text message; you could probably come with with lots of other ways to alert. Each is likely to require a different solution.