Fishtank-002 Valve madness

Until now, september 2019, sea fish tank progress… valve madness.. 

klepje Motorized valve

A few weeks ago, I’ve made the choice for the valves to use in the fish tank control; motorized ball valves with indication for open/closed state. I bought motorized ball valves from AliExpress for about €60,- and that is much cheaper than buying in the Netherlands. The alternative magnetic NC direct working valves, are very expensive and NO valves are even more expansive. Magnetic indirect working valves (need some water pre-pressure to operate), are not expansive but cannot be used when there is no pre-pressure. Another reason; magnetic valves are mostly not equipped with indicators. So, motorized ball valves. Also came my wish to process the open/closed indicators. Imagine the challenges, this software was not yet part of my standard AFSM software (!) and had to be made.

Next issues apply: 

  1. A motorized valves has a certain runtime for opening/closing.

  2. implementation of automatic control of the valve with open/closed check
  3. I want a “comfortable” method to test/simulate the control

  4. I want to force a valve to open or close from HMI

  5. Simulation of indicators for testing

  6. Managing fault situations 

And then, busy programming, I run into the shortage of free RAM. With the MEGA 2560, runtime free RAM was lower than 1K and the behavior of the board was not stable anymore. I had to switch to the MEGA Amtel ARM DUE. The change cost me also one night programming; not everything in the software of a 2560 is compatible with the Amtel ARM. But at the moment the DUE is working perfect.

The software for handling valves is ready and stable and can probably be “used” in future applications. All 5 new valve issues are made and tested. I’ve made the following function for handling a valve (I just wanted only 1 “user” function in the UserFiniteStateMachine.h for handling valves):

CommandCompleted = CommandValve (“<Tagname>”,”<OPEN|CLOSE>”, Faulted)


  • CommandValve, this function must be called with the given variables (below)

  • CommandCompleted, during runtime of the valve opening/closing; returns false, when the command is completed returns true.

  • Tagname, the tagname has to begin with a “V”(alve)

  • The valve command; OPEN or CLOSE

  • When during runtime an error occurs, e.g. expiration of the maximum runtime, Faulted will be true, when everything runs as expected, this Boolean will return false. 

The following rules apply for the valve’s:

  • The valve tagname must start with a “V”. Tages starting with a “V” are always handled as valves!

  • Indicators belonging to a valve must be named OPN<valvename> and CLS<valvename>

In the software the code looks like the example below of state FILL-SUMP.
In this state the normal devices are activated; like the skimmer, the main pumps and heating. When both CommandValve functions are completed, there is a check on faults. When everything ok, Pump P03 is activated and the control is waiting for one of the three situations that can occur for making a transition to the state STOP-FILL-SUMP. Mention not handling the faults; this is not yet implemented.


In HMI the following situations can now be handled:

  • Normal operation. Valve and indicators are connected to the board. When commanded open/close, the indicators are checked on the maximum runtime (hardcoded for all valves in the sketch code; function CommandValve) and the indicator state.

  • Normal operation with simulation of the indicators. The valve is connected to the board and controlled by the FSM. Via HMI it is possible to right click on the indicator tag and set the input as masked (standard background color becomes yellow). Masked “1” or “0” is not important, the indicator is now simulated by the control. It is possible to simulated both or just one indicator.

  • Forced operation of the valve. Right click on the valve name and force the valve open (“1”) or close (“0”). Forcing the valve will command the valve. It is possible to simulate the indicators or check the indicators connected in the field.

  • Most tags -in the standard software presented as tagname with state or value-, are now replaced by symbols. For example a pump symbol; white when off, green when it is on. A valve is presented white when it’s open and black when closed. During opening/closing the symbol is blinking and when there is a failure it turns into a red symbol. That makes the HMI screen looks more like a P&ID. The following functionality is also added; you can still visualize the status of a tag by a check button. When checked; all information is presented and it is possible to mask and force I/O. Like the standard, a forced or marked tag’s background is yellow. When visualization of tag info is unchecked, you can still see a forced or marked tag by a little yellow dot on the tag. See also the pictures below.


fig 1. Enable hand mode, see all tag information.


Fig 2. Hand mode disabled, hide basic tag information

And now back to the fish tank…

For the relay's i 'am now using 8-channel 12Vdc relays with optocouplers. They can be controlled by the 3.3Vdc DUE board. Switching is inverted compared to the "normal" relays. When the output is switched to GND the relays are activated. I'am planning to use them for switching all 230Vac devices and the 24Vdc motorized valves. Also trying to apply the MPX5010DP (10kPa ~ 1m waterpressure), for measuring to water level. Not so enthusiastic at the moment; they are working, but not as stable as i want them to be... to be continued. For the TT's, i will use the waterproof version of the DS18B20.

Valve software is ready, so I can now proceed with the functionality of the fish tank. Busy with osmose supply (request for osmose water in case of water evaporation); commanding the osmose device and control of the osmose tank. With the evaporation of water the salt level will rise (all the salt stays behind in the remaining water), so osmose water must be added to the installation. Next step will be the time driven water renewal of salt water. Every week 10% of the water amount must be renewed by fresh made salt water.