Although this is my first forum post, I have been working with Arduino and electronics for about three years now, so I am not what you would call a 'newbie'. I do however struggle with some of the more complex logic/mathematical aspects of programming, hence this post.
In the past twelve months, I have built a number of devices to increase efficiency and solve minor problems at the public aquarium where I work. The most recent of these is a flow-through control system on a group of small tanks, all connected together by a common sump. Water flows into these tanks all day, overflowing into this common sump where the water is then pumped out into an adjacent filter system. The pumps drain the sump tank until a 'low level' float switch indicates that the water level is sufficiently low; the tank then stops draining and starts to fill back up by gravity from the tanks above; when the sump tank is full, a 'high level' float switch is engaged, and the pumps then switch back on and drain the sump tank to the 'low level' float switch again. Now whilst all of this works perfectly, I would like to add some redundancy in the event that there is a mechanical failure with the pump or associated relays, and water continues to fill the sump tank causing a flood.
To do this, my plan was to create a timestamp when the 'high level' float switch was first engaged. I then planned to incorporate an 'if statement' that would activate an alarm sequence (loud buzzer and an LED) if the float switch remained engaged for, say, ten seconds (i.e. if the tank was draining too much, or about to overflow). I also have some solenoid valves connected to the inlets to each of the tanks, which can be closed to prevent undue flooding.
The problem I encountered is that in the event that the tank is overflowing, the float switch would remain in the same position, thus I am unable to compare an 'up time' and 'down time' to see if it exceeded ten seconds. Instead, I need to find a way of measuring how long the float switch has been engaged, performing a task if it exceeds ten seconds.
Could anyone give me some pointers? I would post the existing code but it is very long! If I can figure out how to code this part, I can then go back and add it into the existing code, and upload to the system for a full test.
I appreciate any and all help in advance!