Can i turn on/off a port based on water level?

Do you have a question on how to do something.
Ask in here.
Post Reply
alexr54
Posts: 59
Joined: Mon Oct 01, 2018 5:55 pm

Can i turn on/off a port based on water level?

Post by alexr54 »

Is there a way to have a port turn on at water level 85 and turn off at water level 95 for example?

I am using a pressure senor for my ATO (tsunami At-1) which turns off and on a pump based on air pressure in a tube in the refugium.

Is there any way i can just have a port turn off when the water level sensor reaches a certain limit? And turn it back on when it gets anywhere below that high level?

Ive tried using this code for the ATO but it keeps timing out and does not seem to work for me. I cant keep my ATO plugged into this port or it simply wont fill up at all.
Currently i have it plugged into a 'always on' port and just hope it wont over fill based off of the ATO pressure sensor.

ReefAngel.WaterLevelATO( Port7,1600,85,95 );
User avatar
Loose
Posts: 90
Joined: Fri Sep 01, 2017 8:15 am
Location: Severna Park, MD

Re: Can i turn on/off a port based on water level?

Post by Loose »

This the ATO code that I use does what I think you're looking for. The time functions allow it to be active only twice a day. Hope it helps.

Code: Select all

    // ATO/Water functions - Begin
    
    if ( ( hour() == 6 ) && ( minute() >= 45 ) && ( hour() == 6 ) && ( minute() < 48 ) )
    {
        if ( ReefAngel.WaterLevel.GetLevel(2) <= 72 && ReefAngel.WaterLevel.GetLevel(2) >= 9 ) ReefAngel.Relay.On( TopOffH2O );
        if ( ReefAngel.WaterLevel.GetLevel(2) >= 81 || ReefAngel.WaterLevel.GetLevel(2) < 9 || ReefAngel.HighATO.IsActive() ) ReefAngel.Relay.Off( TopOffH2O );
    }

    if ( ( hour() == 18 ) && ( minute() >= 45 ) && ( hour() == 18 ) && ( minute() < 48 ) )
    {
        if ( ReefAngel.WaterLevel.GetLevel(2) <= 72 && ReefAngel.WaterLevel.GetLevel(2) >= 9 ) ReefAngel.Relay.On( TopOffH2O );
        if ( ReefAngel.WaterLevel.GetLevel(2) >= 81 || ReefAngel.WaterLevel.GetLevel(2) < 9 || ReefAngel.HighATO.IsActive() ) ReefAngel.Relay.Off( TopOffH2O );
    }

    if ( ReefAngel.WaterLevel.GetLevel(2) <= 36 ) ReefAngel.Relay.Off( ReturnDCP );
    if ( ReefAngel.WaterLevel.GetLevel(2) >= 63 ) ReefAngel.Relay.On( ReturnDCP );
    if ( ReefAngel.WaterLevel.GetLevel(2) >= 90 || ReefAngel.WaterLevel.GetLevel(1) >= 108 || ReefAngel.HighATO.IsActive() )
    {
        ReefAngel.Relay.Off( Skimmer );
        ReefAngel.Relay.Off( TopOffH2O );
    }    

    // ATO/Water functions - End
The code for just the return pump may be specific to what you are asking but mine works in the reverse - off if less than 36 and back on when above 63.
Try to learn something about everything and everything about something... Thomas Huxley
210gal DT | 50gal sump/refug | Jebao DCP 10000 pump | RO 200-int skimmer | DIY built stand | DIY 160 led, 12 channel, 458 watt, on MakersLED 72" heatsink
alexr54
Posts: 59
Joined: Mon Oct 01, 2018 5:55 pm

Re: Can i turn on/off a port based on water level?

Post by alexr54 »

Thanks!

This is very useful. Although its a bit much for me. I just want to do a simple on and off based on level and the time of day really is not a factor for me.
I have my RODI hooked up directly to a water line controlled by a zone valve which opens/closes based off of the ATO.

I suppose this would work?
Turn off if its above 95% and turn on if its below 85%?

Maybe i got this wrong.

Code: Select all

 
        if ( ReefAngel.WaterLevel.GetLevel(2) <= 85 && ReefAngel.WaterLevel.GetLevel(2) <= 85 ) ReefAngel.Relay.On( TopOff );
        if ( ReefAngel.WaterLevel.GetLevel(2) >= 95 || ReefAngel.WaterLevel.GetLevel(2) > 95 ) ReefAngel.Relay.Off( TopOff );
User avatar
Loose
Posts: 90
Joined: Fri Sep 01, 2017 8:15 am
Location: Severna Park, MD

Re: Can i turn on/off a port based on water level?

Post by Loose »

I think you only need:

Code: Select all

                 if ( ReefAngel.WaterLevel.GetLevel(2) <= 85 ) ReefAngel.Relay.On( Port7 );

                 if ( ReefAngel.WaterLevel.GetLevel(2) >= 95 ) ReefAngel.Relay.Off( Port7 );
The number in the ReefAngel.WaterLevel.GetLevel() statement would be the number of whatever level sensor your using for the reference. For me, it just happens to be '2.'

Edit: was missing a ')' in each statement.
Try to learn something about everything and everything about something... Thomas Huxley
210gal DT | 50gal sump/refug | Jebao DCP 10000 pump | RO 200-int skimmer | DIY built stand | DIY 160 led, 12 channel, 458 watt, on MakersLED 72" heatsink
User avatar
Loose
Posts: 90
Joined: Fri Sep 01, 2017 8:15 am
Location: Severna Park, MD

Re: Can i turn on/off a port based on water level?

Post by Loose »

I would suggest modifying the functions to account for a malfunction of the water level sensor/module combination.

Code: Select all

                 if ( ReefAngel.WaterLevel.GetLevel(2) <= 85 && ReefAngel.WaterLevel.GetLevel(2) > 0 ) ReefAngel.Relay.On( Port7 );

                 if ( ReefAngel.WaterLevel.GetLevel(2) >= 95 ||  ReefAngel.WaterLevel.GetLevel(2) = 0 ) ReefAngel.Relay.Off( Port7 );
The reason is that if a sensor comes out of the water, the air line to the module leaks, or a USB cable comes a loose (power/data), then the reading will be zero (0) or something close to it. In any of these cases, your pump would turn on and stay on regardless of actual water level. I use 9 in my code to give a little wiggle room. This and the 3 minute windows twice a day are the compensations for not having an ATO time-out using the ATO function. On the darker side, a broken tank could also cause the zero (or something close to it) reading.
Try to learn something about everything and everything about something... Thomas Huxley
210gal DT | 50gal sump/refug | Jebao DCP 10000 pump | RO 200-int skimmer | DIY built stand | DIY 160 led, 12 channel, 458 watt, on MakersLED 72" heatsink
alexr54
Posts: 59
Joined: Mon Oct 01, 2018 5:55 pm

Re: Can i turn on/off a port based on water level?

Post by alexr54 »

Loose wrote:I would suggest modifying the functions to account for a malfunction of the water level sensor/module combination.

Code: Select all

                 if ( ReefAngel.WaterLevel.GetLevel(2) <= 85 && ReefAngel.WaterLevel.GetLevel(2) > 0 ) ReefAngel.Relay.On( Port7 );

                 if ( ReefAngel.WaterLevel.GetLevel(2) >= 95 ||  ReefAngel.WaterLevel.GetLevel(2) = 0 ) ReefAngel.Relay.Off( Port7 );
The reason is that if a sensor comes out of the water, the air line to the module leaks, or a USB cable comes a loose (power/data), then the reading will be zero (0) or something close to it. In any of these cases, your pump would turn on and stay on regardless of actual water level. I use 9 in my code to give a little wiggle room. This and the 3 minute windows twice a day are the compensations for not having an ATO time-out using the ATO function. On the darker side, a broken tank could also cause the zero (or something close to it) reading.
That makes sense for sure. Another good safety measure i have is the leak detector. Which will shut off all the ports if a leak is detected.

So i will try this one out. I will eventually get to naming all my ports :)


Code: Select all

                 if ( ReefAngel.WaterLevel.GetLevel(2) <= 85 && ReefAngel.WaterLevel.GetLevel(2) > 9 ) ReefAngel.Relay.On( Port7 );

                 if ( ReefAngel.WaterLevel.GetLevel(2) >= 95 ||  ReefAngel.WaterLevel.GetLevel(2) = 0 ) ReefAngel.Relay.Off( Port7 );
libertyaquarium
Posts: 21
Joined: Fri Jan 12, 2018 6:33 am

Re: Can i turn on/off a port based on water level?

Post by libertyaquarium »

ReefAngel.Relay.Set(Port7, ReefAngel.WaterLevel.GetLevel(2) <= 85 && ReefAngel.WaterLevel.GetLevel(2) > 9);
User avatar
Loose
Posts: 90
Joined: Fri Sep 01, 2017 8:15 am
Location: Severna Park, MD

Re: Can i turn on/off a port based on water level?

Post by Loose »

Thanks libertyaquarium, I do like streamlined code. Is there an equivalent function for the ReefAngel.Relay.Off?
Try to learn something about everything and everything about something... Thomas Huxley
210gal DT | 50gal sump/refug | Jebao DCP 10000 pump | RO 200-int skimmer | DIY built stand | DIY 160 led, 12 channel, 458 watt, on MakersLED 72" heatsink
alexr54
Posts: 59
Joined: Mon Oct 01, 2018 5:55 pm

Re: Can i turn on/off a port based on water level?

Post by alexr54 »

libertyaquarium wrote:ReefAngel.Relay.Set(Port7, ReefAngel.WaterLevel.GetLevel(2) <= 85 && ReefAngel.WaterLevel.GetLevel(2) > 9);
I am new to this and trying to understand.

Does this mean that port 7 will turn off when water level shows above 85 and will turn on when water level shows above 9 but below 85?

That is really what i am trying to accomplish here, but possibly with different percentages.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Can i turn on/off a port based on water level?

Post by lnevo »

Yes. The && is a way of sending AND. So if both conditions are true (number between and inclusive 10-85) then Port 7 will get set to true which will be on. If either of those conditions is not true, (if it's 86 or higher or 9 or less) then the port will get set to false which will then be off. You can change the 85 and 9 as desired. The 2 needs to be the WaterLevel channel that your sensor is using.
User avatar
Loose
Posts: 90
Joined: Fri Sep 01, 2017 8:15 am
Location: Severna Park, MD

Re: Can i turn on/off a port based on water level?

Post by Loose »

Ahhh... still learning the functions too and the ReefAngel.Relay.Set() function is a logical TRUE/FALSE.

But how do you accomplish the range of port ON that is desired using it?

The original goal was on at or below 85 and off at 95. The first condition is met but the second isn't. I added the check for above 9 because I've had the overfill happen (with the associated shopvac usage :oops: ).

Also, if a TRUE/FALSE is used for this function the ATO relay is going to cycle often at the 85 mark; on at 85 off at 86. Correct?
Try to learn something about everything and everything about something... Thomas Huxley
210gal DT | 50gal sump/refug | Jebao DCP 10000 pump | RO 200-int skimmer | DIY built stand | DIY 160 led, 12 channel, 458 watt, on MakersLED 72" heatsink
alexr54
Posts: 59
Joined: Mon Oct 01, 2018 5:55 pm

Re: Can i turn on/off a port based on water level?

Post by alexr54 »

So this is working great when it comes to turning on the relay when water reached a certain level
However i ran into another issue, the water level tends to jump 1-3% from 89-92 back and forth.

Is there a way to put a delay on this relay as well?

I did try adding to the code:
ReefAngel.Relay.DelayedOn( Port7,1200 );

So it would delay to turn it on for 20 minutes, but it does not seem to be working.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Can i turn on/off a port based on water level?

Post by lnevo »

DelayedOn only works after reboot, feeding mode or waterchange mode.

What you want to do is set the relay override which you can do with

ReefAngel.Relay.Override(Port7, false);

That will turn the relay on definitively. However it won't go back on unless you do it manually or add additional logic to put it back on after 20 minutes or if the WL changes to something else.
alexr54
Posts: 59
Joined: Mon Oct 01, 2018 5:55 pm

Re: Can i turn on/off a port based on water level?

Post by alexr54 »

lnevo wrote:DelayedOn only works after reboot, feeding mode or waterchange mode.

What you want to do is set the relay override which you can do with

ReefAngel.Relay.Override(Port7, false);

That will turn the relay on definitively. However it won't go back on unless you do it manually or add additional logic to put it back on after 20 minutes or if the WL changes to something else.
Oh i see, so what i am trying to do will not work unless i figure out some other logic to turn it back on after 20 minutes or whatever time.

Just want this port to have a delayed on time based off any 'on' trigger.

Ideally it would work like this:
Water level gets to 90%
Port 7 (ATO port) Turns on RODI water. Until water level gets above 90% (91%)

What is happening is water level is jumpung from 89% to 92% every few seconds causing the relay to go crazy.

So ideally it would work like this:
Water level gets to 90%
Port 7 Turns on after a delayed time of 20 minutes to fill RODI water
Water level jumps betwen 89-92%
Port 7 turns off and has a delayed turn on time of 20 minutes
After 20 minutes Port 7 (ATO port) Turns on RODI water.


I dont care if my water level drops below 85% as long as it eventually gets filled to 90%. And it seems a delay on for the port would do the job. Maybe even a longer delay on time, which is something i can eventually mess with.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Can i turn on/off a port based on water level?

Post by rimai »

I'm not understanding why use the timer is the level is the best way to go.
Have you tried the code you said you would? Can you explain to me so I better understand why the code didn't work?

Code: Select all

                 if ( ReefAngel.WaterLevel.GetLevel(2) <= 85 && ReefAngel.WaterLevel.GetLevel(2) > 9 ) ReefAngel.Relay.On( Port7 );

                 if ( ReefAngel.WaterLevel.GetLevel(2) >= 95 ||  ReefAngel.WaterLevel.GetLevel(2) = 0 ) ReefAngel.Relay.Off( Port7 );
Relay would turn on only when goes below 85 and turn off when above 95. Even if it bounces around, it would not turn back on until it goes all the way down to 85 again.
Roberto.
alexr54
Posts: 59
Joined: Mon Oct 01, 2018 5:55 pm

Re: Can i turn on/off a port based on water level?

Post by alexr54 »

The code is throwing an error:

In function 'void loop()':
error: lvalue required as left operand of assignment


Looks like it does not like = 0
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Can i turn on/off a port based on water level?

Post by lnevo »

= is an assignment not a comparison. So here you are trying to set a function to equal 0. = by itself is used to set the value of a variable int i = 4; for example. What you want is to use a comparison, is it equal to which is represented by == alternatively if you ever need, you can use != along with < > <= >=
alexr54
Posts: 59
Joined: Mon Oct 01, 2018 5:55 pm

Re: Can i turn on/off a port based on water level?

Post by alexr54 »

Thank you for the explanation.

This is working perfectly now.
Post Reply