Page 1 of 2
Turn on relay when WL is at 100% or >?
Posted: Sun Aug 03, 2014 12:20 pm
by Sacohen
This is probably simple for you guys.
I want to turn port 3 on thee main Relay on for 1 hour when WaterLevel 1 of the multi sensor is at 100% or above.
I think this is the basis for it, but I don't know know how to have it turn off after 1 hour.
Code: Select all
if (ReefAngel.WaterLevel.GetLevel(1)>=100) ReefAngel.Relay.On(Port3);
Thanks for your help.
Re: Turn on relay when WL is at 100% or >?
Posted: Sun Aug 03, 2014 12:57 pm
by 89delta
That looks about right. Not sure if you would need an Else statement in there or not also. I know from reading analog or digital pins i've added it.
Re: Turn on relay when WL is at 100% or >?
Posted: Sun Aug 03, 2014 1:04 pm
by binder
What you posted will keep the port on as long as the value is equal or above 100. As soon as it does not meet that criteria, it will not keep turning it on. You would want to put in an else statement to turn it off and also add in a timer to ensure that it shuts off after your specified time frame. You will also want to have a failsafe to prevent it from getting reactivated after the 1 hour time delay occurs.
that should be able to get you going in the right direction and maybe give you some tips for your coding. i'm sure others will be able to help more.
Re: Turn on relay when WL is at 100% or >?
Posted: Sun Aug 03, 2014 1:08 pm
by Sacohen
What I put will just turn the port on indefinitely, there needs to be something that will turn it off after 1hr.
Re: Turn on relay when WL is at 100% or >?
Posted: Sun Aug 03, 2014 1:13 pm
by Sacohen
binder wrote:What you posted will keep the port on as long as the value is equal or above 100. As soon as it does not meet that criteria, it will not keep turning it on. You would want to put in an else statement to turn it off and also add in a timer to ensure that it shuts off after your specified time frame. You will also want to have a failsafe to prevent it from getting reactivated after the 1 hour time delay occurs.
that should be able to get you going in the right direction and maybe give you some tips for your coding. i'm sure others will be able to help more.
Curt;
I agree with you.
I just have no idea how to code it.
Basically what I want to do is one I refill my ATO reservoir (either manually now or automatically in the future) I want the pump inside the reservoir to turn on for 1 hr (may change that later) to stir up and mix the Kalwasser that is either on the bottom of the reservoir that did not dissolve last time because it was above the saturation point or new Kalkwasser that I add to replenish what has been used up.
Re: Turn on relay when WL is at 100% or >?
Posted: Sun Aug 03, 2014 1:24 pm
by lnevo
time_t stopTime = 0;
if (ReefAngel.WaterLevel.GetLevel(1)<=100) stopTime=now()+3600;
if (stopTime-now() < 3600) { ReefAngel.Relay.On(Port3); } else ReefAngel.Relay.Off(Port4); }
You just may want a flag to set the stopTime... But essentially above is what you want..i believe
Re: Turn on relay when WL is at 100% or >?
Posted: Sun Aug 03, 2014 1:24 pm
by lnevo
time_t stopTime = 0;
if (ReefAngel.WaterLevel.GetLevel(1)<=100) stopTime=now()+3600;
if (stopTime-now() < 3600) { ReefAngel.Relay.On(Port3); } else ReefAngel.Relay.Off(Port4); }
You just may want a flag to set the stopTime... But essentially above is what you want..i believe
Re: Turn on relay when WL is at 100% or >?
Posted: Sun Aug 03, 2014 1:35 pm
by Sacohen
Thanks Lee.
I think that is what I want.
Basically the way I read it is if the Water Level is 100% or greater to turn on port 3 and start a 3600 (or 1 hr timer).
The stop time is checking if it is less then 3600 seconds or over and it will either leave port 3 on or turn off what I assume to be Port3 not Port4. Correct?
Code: Select all
time_t stopTime = 0;
if (ReefAngel.WaterLevel.GetLevel(1)<=100) stopTime=now()+3600;
if (stopTime-now() < 3600) { ReefAngel.Relay.On(Port3); } else ReefAngel.Relay.Off(Port3); }
Re: Turn on relay when WL is at 100% or >?
Posted: Sun Aug 03, 2014 2:05 pm
by Sacohen
I tried adding that code to the loop section right before my Auto Feeder code and it seems to be conflicting something.
I get the following error...
expected unqualified-id before 'if'
Here is my code...
Code: Select all
#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>fF
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>f
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <LED.h>
#include <RA_TempSensor.h>
#include <Relay.h>
#include <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <InternalEEPROM.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <Salinity.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <Humidity.h>
#include <DCPump.h>
#include <ReefAngel.h>
// Define Relay Ports by Name
#define Actinic_Lights 1
#define Day_Lights 2
#define Unused 3
#define Pumps 4
#define Sump_Fan 5
#define DeNit_Doser 6
#define DeNit_Pump 7
#define ATO_Pump 8
#define Unused Box1_Port1
#define Feeder Box1_Port2
#define Unused Box1_Port3
#define Unused Box1_Port4
#define Unused Box1_Port5
#define Unused Box1_Port6
#define Unused Box1_Port7
#define Dummy Box1_Port8
////// Place global variable code below here
// Does not need to be global.
// unsigned long ATOUpdate=0;
////// Place global variable code above here
void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = 0;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port4Bit;
ReefAngel.WaterChangePortsE[0] = Port1Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port1Bit | Port2Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit;
// Use T2 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
// Set the Overheat temperature setting
InternalMemory.OverheatTemp_write( 825 );
//Set Standard Menu
ReefAngel.AddStandardMenu();
// Feeeding and Water Change mode speed
ReefAngel.DCPump.FeedingSpeed=0;
ReefAngel.DCPump.WaterChangeSpeed=0;
ReefAngel.DCPump.ActinicChannel=Sync; // Now you're pump will be affected by the portal settings.
ReefAngel.DCPump.DaylightChannel=AntiSync; // Now you're pump will be affected by the portal settings.
// Ports that are always on
ReefAngel.Relay.On( Pumps );
ReefAngel.Relay.On( Dummy );
////// Place additional initialization code below here
////// Place additional initialization code above here
}
void loop()
{
ReefAngel.StandardLights( Actinic_Lights,12,0,22,0 );
ReefAngel.StandardLights( Day_Lights,13,0,21,0 );
ReefAngel.StandardLights( Sump_Fan,13,0,21,0 );
ReefAngel.WaterLevelATO(ATO_Pump,720,28,31);
if ( hour()>=13 && hour()<21 )
ReefAngel.PWM.SetChannel( 5, 0 );
else
ReefAngel.PWM.SetChannel( 5, PWMSlope(21,0,13,0,0,MoonPhase() ,60,0) );
time_t stopTime = 0;
if (ReefAngel.WaterLevel.GetLevel(1)<=100) stopTime=now()+3600;
if (stopTime-now() < 3600) { ReefAngel.Relay.On(Port3); } else ReefAngel.Relay.Off(Port3); }
////// Place your custom code below here
//AutoFeeder
static unsigned long autofeeding = 0;
if ((now()%SECS_PER_DAY==64800)) //if it is 6 pm
{
ReefAngel.FeedingModeStart(); //START FEEDING MODE
}
if (ReefAngel.DisplayedMenu==FEEDING_MODE)
{
if ( autofeeding == 0 ) {
autofeeding = now(); //set the time of the start of feeding to variable feeding
}
if ((now()-autofeeding>=60) && (now()-autofeeding<=61)) //if between 60 and 61 seconds has past
{
ReefAngel.Relay.On(Feeder); //TURN FEEDER RELAY ON
}
else
{
ReefAngel.Relay.Off(Feeder); //TURN FEEDER RELAY OFF
}
} else {
if ( autofeeding > 0 ) {
autofeeding = 0;
}
}
// DeNitrate Routine
int DeNit_Offset=3600;
int DeNit_Repeat=21600;
int DeNit_Doser_Offset=1200;
int DeNit_Doser_Runtime=600;
int DeNit_Pump_Runtime=1200;
int DeNit_ATO_Offtime=1500;
// Pump comes on first
ReefAngel.Relay.Set(DeNit_Pump,(now()-DeNit_Offset)%DeNit_Repeat<DeNit_Pump_Runtime); // Runs denitrator pump
// Doser comes on second
ReefAngel.Relay.Set(DeNit_Doser,((now()-DeNit_Offset)-DeNit_Doser_Offset)%DeNit_Repeat<DeNit_Doser_Runtime); // Runs denitrator doser
// Disable ATO
if ( (now()-3600)%21600<DeNit_ATO_Offtime) ReefAngel.WaterLevelATO(ATO_Pump,720,0,1);
// Delay WL ATO after water change and DeNit_Dosing
static time_t wcTimer=0;
if (ReefAngel.DisplayedMenu == WATERCHANGE_MODE) wcTimer=now();
// First 10 minutes after WC disable ATO
if (now()-wcTimer >= 0 && now()-wcTimer < 600)
ReefAngel.WaterLevelATO(ATO_Pump,720,0,1);
// Track Salinity low duration
static unsigned long lastGoodSal;
static boolean lowSalFlag;
// Salinity is good, update counter
if (ReefAngel.Params.Salinity>=335) lastGoodSal=now();
// Counter hasn't been updating in 300 seconds..
if (now()-lastGoodSal>300) {
lowSalFlag=true; // Salinity is definitely below 33.5
} else {
lowSalFlag=false; // Salinity back to normal
}
// Disable ATO if lowSalFlag is true
if (lowSalFlag) ReefAngel.WaterLevelATO(ATO_Pump,720,0,1);
// Disable ATO if ATO High IsActive()
if (ReefAngel.HighATO.IsActive())
ReefAngel.WaterLevelATO(ATO_Pump,720,0,1);
// Add random mode if we set to Mode to Custom in portal
static int rmode;
static boolean changeMode=true;
// Add Else Mode definition..
const int Else=16;
// These are the modes we can cycle through. You can add more and even repeat...
byte modes[] = { ReefCrest, Lagoon, Constant, TidalSwell, ShortPulse, LongPulse, Else };
if (now()%SECS_PER_DAY==0 || changeMode==true) { // Change at midnight or if controller rebooted
rmode=random(100)%sizeof(modes); // Change the mode once per day to pick from our array
changeMode=false;
}
// Set timer when in feeding mode
static unsigned long feeding;
if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();
if (now()-feeding<3600) {
// Continue NTM for the 60 minutes
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()%SECS_PER_DAY<43200 || now()%SECS_PER_DAY>=79200) { // 12pm / 10pm
// Night mode (go to 30%)
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
ReefAngel.DCPump.Mode=Constant;
ReefAngel.DCPump.Speed=30;
} else if (InternalMemory.DCPumpMode_read()==11) {
// Custom Mode and nothing else going on
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
if (modes[rmode]==Else) {
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.Mode=Constant;
ReefAngel.DCPump.Speed=ElseMode(InternalMemory.DCPumpSpeed_read(),20,true ); // ElseMode on sync mode, Portal Speed Setting +/- 20%
} else {
ReefAngel.DCPump.Mode=modes[rmode]; // Put the mode to the random mode :)
ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
}
} else {
ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
}
////// Place your custom code above here
// This should always be the last line
ReefAngel.Portal( "Sacohen","xxxxxxxx );
ReefAngel.ShowInterface();
}
void DrawCustomMain()
{
int x,y;
char text[10];
// Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 20, ReefAngel.Params,
ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 20, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
pingSerial();
// Water Level
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,75,57, "WL:" );
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,99,57, ReefAngel.WaterLevel.GetLevel() );
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,66,66, "WL 1:" );
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,99,66, ReefAngel.WaterLevel.GetLevel(1) );
//Salinity
ConvertNumToString(text, ReefAngel.Params.Salinity, 10);
strcat(text," ");
ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,39,75,"Salinity:");
ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,99,75,text);
pingSerial();
// Main Relay Box
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox( 12, 92, TempRelay );
pingSerial();
TempRelay = ReefAngel.Relay.RelayDataE[0];
TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
ReefAngel.LCD.DrawOutletBox(12, 104, TempRelay);
// Date and Time
ReefAngel.LCD.DrawDate( 6, 122 );
pingSerial();
}
void DrawCustomGraph()
{
}
byte ElseMode( byte MidPoint, byte Offset, boolean WaveSync )
{
// Static's only initialize the first time they are called
static unsigned long LastChange=millis(); // Set the inital time that the last change occurred
static int Delay = random( 500, 3000); // Set the initial delay
static int NewSpeed = MidPoint; // Set the initial speed
static int AntiSpeed = MidPoint; // Set the initial anti sync speed
if ((millis()-LastChange) > Delay) // Check if the delay has elapsed
{
Delay=random(500,5000); // If so, come up with a new delay
int ChangeUp = random(Offset); // Amount to go up or down
if (random(100)<50) // 50/50 chance of speed going up or going down
{
NewSpeed = MidPoint - ChangeUp;
AntiSpeed = MidPoint + ChangeUp;
}
else
{
NewSpeed = MidPoint + ChangeUp;
AntiSpeed = MidPoint - ChangeUp;
}
LastChange=millis(); // Reset the time of the last change
}
if (WaveSync)
{
return NewSpeed;
}
else
{
return AntiSpeed;
}
}
Re: Turn on relay when WL is at 100% or >?
Posted: Sun Aug 03, 2014 2:21 pm
by Sacohen
lnevo wrote:time_t stopTime = 0;
if (ReefAngel.WaterLevel.GetLevel(1)<=100) stopTime=now()+3600;
if (stopTime-now() < 3600) { ReefAngel.Relay.On(Port3); } else ReefAngel.Relay.Off(Port4); }
You just may want a flag to set the stopTime... But essentially above is what you want..i believe
Lee;
Is the time_t stop Time function in the 1.1.0 libraries or were they pur into the 1.1 1 libraries?
Re: Turn on relay when WL is at 100% or >?
Posted: Sun Aug 03, 2014 3:47 pm
by lnevo
Replace it with static unsigned long. Forgot to put the static in before. And i think for the test you just want to do see if now()<stopTime
You just need to protect the assignment of stopTime to make sure its only run once or it will contnue updating as long as the reservoir is full.
Re: Turn on relay when WL is at 100% or >?
Posted: Sun Aug 03, 2014 5:25 pm
by Sacohen
This is what I put in and I'm still getting the same error message...
Code: Select all
static unsigned long Kalk_Mixing = 0;
time_t stopTime = 0;
if (ReefAngel.WaterLevel.GetLevel(1)<=100) stopTime=now()+3600;
if (stopTime-now() < 3600) { ReefAngel.Relay.On(Port3); } else ReefAngel.Relay.Off(Port3); }
Error message is ...
expected unqualified-id before 'if'
Re: Turn on relay when WL is at 100% or >?
Posted: Sun Aug 03, 2014 6:07 pm
by lnevo
The error is not in that code IMO. Try going back...
Re: Turn on relay when WL is at 100% or >?
Posted: Sun Aug 03, 2014 6:08 pm
by lnevo
And theres still logic errors there, let me write you up something more comprehensive tomorrow.
Re: Turn on relay when WL is at 100% or >?
Posted: Sun Aug 03, 2014 6:17 pm
by Sacohen
The error is not in that code.
It comes up in the next line of code for my Auto Feeder. The part I may Blue.
//Mix Kalkwasser
static unsigned long Kalk_Mixing = 0;
time_t stopTime = 0;
if (ReefAngel.WaterLevel.GetLevel(1)<=100) stopTime=now()+3600;
if (stopTime-now() < 3600) { ReefAngel.Relay.On(Port3); } else ReefAngel.Relay.Off(Port3); }
//AutoFeeder
static unsigned long autofeeding = 0;
if ((now()%SECS_PER_DAY==64800)) //if it is 6 pm
{
ReefAngel.FeedingModeStart(); //START FEEDING MODE
}
if (ReefAngel.DisplayedMenu==FEEDING_MODE)
{
if ( autofeeding == 0 ) {
autofeeding = now(); //set the time of the start of feeding to variable feeding
}
if ((now()-autofeeding>=60) && (now()-autofeeding<=61)) //if between 60 and 61 seconds has past
{
ReefAngel.Relay.On(Feeder); //TURN FEEDER RELAY ON
}
else
{
ReefAngel.Relay.Off(Feeder); //TURN FEEDER RELAY OFF
}
} else {
if ( autofeeding > 0 ) {
autofeeding = 0;
}
}
Re: Turn on relay when WL is at 100% or >?
Posted: Mon Aug 04, 2014 4:28 am
by lnevo
Ok, the error is in my code
Code: Select all
if (stopTime-now() < 3600) { ReefAngel.Relay.On(Port3); } else ReefAngel.Relay.Off(Port3); }
to
Code: Select all
if (stopTime-now() < 3600) { ReefAngel.Relay.On(Port3); } else { ReefAngel.Relay.Off(Port3); }
But here's your better code :
Code: Select all
//Mix Kalkwasser
static unsigned long Kalk_Mixing = 0;
static unsigned long stopTime = 0;
static byte prevWL=0;
if (ReefAngel.WaterLevel.GetLevel(1)>=100 && preWL<100) {
stopTime=now()+3600; // Get time one hour from now.
}
prevWL = WaterLevel.GetLevel(1); // Store the water level
if (now() < 3600) { ReefAngel.Relay.On(Port3); } else { ReefAngel.Relay.Off(Port3); }
//AutoFeeder
static unsigned long autofeeding = 0;
if ((now()%SECS_PER_DAY==64800)) //if it is 6 pm
{
ReefAngel.FeedingModeStart(); //START FEEDING MODE
}
if (ReefAngel.DisplayedMenu==FEEDING_MODE)
{
if ( autofeeding == 0 ) {
autofeeding = now(); //set the time of the start of feeding to variable feeding
}
if ((now()-autofeeding>=60) && (now()-autofeeding<=61)) //if between 60 and 61 seconds has past
{
ReefAngel.Relay.On(Feeder); //TURN FEEDER RELAY ON
}
else
{
ReefAngel.Relay.Off(Feeder); //TURN FEEDER RELAY OFF
}
} else {
if ( autofeeding > 0 ) {
autofeeding = 0;
}
}
I added a variable for the previous water level to help make sure this only runs once it's been filled. Hopefully it works.
Re: Turn on relay when WL is at 100% or >?
Posted: Mon Aug 04, 2014 4:31 am
by Sacohen
Thanks. I'll try it tonight.
Re: Turn on relay when WL is at 100% or >?
Posted: Mon Aug 04, 2014 11:36 am
by Sacohen
Lee;
I just tried the code you put up yesterday and the error message I'm getting now is...
'preWL' was not declared in this scope
but I see static byte prevWL=0; in the code.
I tried it as static byte prevWL = 0; and got the same message.
Re: Turn on relay when WL is at 100% or >?
Posted: Mon Aug 04, 2014 1:22 pm
by lnevo
Because the error is preWL without the V... I made a typo somewhere else...
Change this:
Code: Select all
if (ReefAngel.WaterLevel.GetLevel(1)>=100 && preWL<100) {
to
Code: Select all
if (ReefAngel.WaterLevel.GetLevel(1)>=100 && prevWL<100) {
Re: Turn on relay when WL is at 100% or >?
Posted: Mon Aug 04, 2014 4:22 pm
by Sacohen
Now I'm getting 'WaterLevel' was not declared in this scope.
The line in Blue is the one that is highlighted...
//Mix Kalkwasser
static unsigned long Kalk_Mixing = 0;
static unsigned long stopTime = 0;
static byte prevWL=0;
if (ReefAngel.WaterLevel.GetLevel(1)>=100 && prevWL<100) {
stopTime=now()+3600; // Get time one hour from now.
}
prevWL = WaterLevel.GetLevel(1); // Store the water level
if (now() < 3600) { ReefAngel.Relay.On(Kalkwasser); } else { ReefAngel.Relay.Off(Kalkwasser); }
I changed it to this and it compiled with now errors.
Is this the way it should be?
prevWL = ReefAngel.WaterLevel.GetLevel(1); // Store the water level
Re: Turn on relay when WL is at 100% or >?
Posted: Mon Aug 04, 2014 5:04 pm
by Sacohen
It doesn't seem to be working.
I have the ATO reservoir filled and I re-calibrated the sensor because even full it was reading 95%
It's now reading 100% on the RA menu and on my phone, but is reading 0 on the Portal and Port3 has not turned on.

Re: Turn on relay when WL is at 100% or >?
Posted: Mon Aug 04, 2014 5:11 pm
by lnevo
Yes you got the code right. Here's the scenario. The water level needs to be below the 100 percent mark and then hit 100 and it will then set stopTime to 3600 seconds in the future. Also found and error. it should be now()<stopTime not 3600. Carryover from the initial example. Sorry for always clutzing up on you. I code on my phone...
Re: Turn on relay when WL is at 100% or >?
Posted: Mon Aug 04, 2014 5:37 pm
by Sacohen
That looks like it did it after I fixed that last coding issue.
No problem with the mess ups, I just appreciate the help.
Besides I did figured some things (well 1) out on my own.
I'm starting to pick this up, but still have a long way to go.
Re: Turn on relay when WL is at 100% or >?
Posted: Tue Aug 05, 2014 5:25 am
by binder
Sacohen wrote:That looks like it did it after I fixed that last coding issue.
No problem with the mess ups, I just appreciate the help.
Besides I did figured some things (well 1) out on my own.
I'm starting to pick this up, but still have a long way to go.
no worries there. it is a continuous learning experience. i even have issues at times too!
glad you were able to get things figured out.
Sent from my iPad mini
Re: Turn on relay when WL is at 100% or >?
Posted: Tue Aug 05, 2014 5:48 am
by Sacohen
Thanks. Curt. It was Lee that did it, but I was proud that I was able to figure out what was wrong when he mis-coded something. That's 1000x better then when I started in here.
Re: Turn on relay when WL is at 100% or >?
Posted: Wed Aug 06, 2014 5:53 am
by Sacohen
The final working code is...
Code: Select all
//Mix Kalkwasser
static unsigned long Kalk_Mixing = 0;
static unsigned long stopTime = 0;
static byte prevWL=0;
if (ReefAngel.WaterLevel.GetLevel(1)>=100 && prevWL<100) {
stopTime=now()+3600; // Get time one hour from now.
}
prevWL = ReefAngel.WaterLevel.GetLevel(1); // Store the water level
if (now() < stopTime) { ReefAngel.Relay.On(Kalkwasser); } else { ReefAngel.Relay.Off(Kalkwasser); }
Re: Turn on relay when WL is at 100% or >?
Posted: Sun Sep 14, 2014 6:18 am
by Sacohen
Lee thanks again for this code.
There seems to be some problems with it still.
When the Water Level reaches 0 the Kalkwasser pump (Port4) turns on.
That shouldn't happen because there is not enough water in the Reservoir to have it run without cavitating.
Also when the water is below 0 or at 0 for too long it starts reporting the WL at 200%.
This is not problem with the code I think it's an issue with the design of the WL sensors or when the ATO pulls more water and actually falls below the calibrated 0 level.
This causes another problem with the line of code that says and previous WL is less than 100, because it doesn't stay at less than 100.
I tried changing the code to equal to 100 and got "value required as left operand of assignment"
Code: Select all
static unsigned long Kalk_Mixing = 0;
static unsigned long stopTime = 0;
static byte prevWL=0;
if (ReefAngel.WaterLevel.GetLevel(1)=100 && prevWL<100) {
stopTime=now()+3600; // Get time one hour from now.
}
prevWL = ReefAngel.WaterLevel.GetLevel(1); // Store the water level
if (now() < stopTime) { ReefAngel.Relay.On(Kalkwasser); } else { ReefAngel.Relay.Off(Kalkwasser); }
Re: Turn on relay when WL is at 100% or >?
Posted: Sun Sep 14, 2014 6:39 am
by lnevo
You need == that causes the error you had.
Its an issue with the water level sensor code. I'll have to check but yeah it wraps around to 200...and at 0 its probably jumping to 200 where you can't see it.
Re: Turn on relay when WL is at 100% or >?
Posted: Sun Sep 14, 2014 7:13 am
by Sacohen
OK. That did it.
I don't think it's jumping to 200% right away, but that would make sense because it gets to 0, jumps to 200 and turn on the port since it is above 100 like the code says to.
That 200% thing is going to cause an issue since it will not start the hour stirring process if the last level was not below 100.
This is the first step in automating my RO/DI and SW container refills.
My thought was when WL reaches 0% the RO/DI water turns on and starts filling whichever reservoir is low and calling for it to be turned on.
When it reaches 100% it shuts of the RO/DI maker and turns on the pump for an hour (Maybe 2 for the SW) and then the water in each reservoir is ready to use.
Obviously I would try to build in something that disables the ATO or AWC while the reservoir is refiling and mixing.
Re: Turn on relay when WL is at 100% or >?
Posted: Sun Sep 14, 2014 7:43 am
by lnevo
I would not start anything at the 0% mark

i'd even suggest recalibrating so that 0% has some amount of liquid in it. But yeah it's like debouncing any other sensors, you may not see it because the screen refreshes every 5 seconds i believe but the sensor definitely has some bounce in it so it could be bouncing to 200 and you wouldnt se it necessarily. We need to fix that part. Maybe need to change the result to an int so we can get a negative percent.
Another thing we can do is read the raw value from the sensor and check if we're lower than the calibrated minimum...i'm not sure that function exists, but I've wanted it a few times...