Page 1 of 1
Intelligent PH function for Calcium Reactor
Posted: Tue Nov 22, 2011 2:38 am
by lukeluke
Hi,
i'ld want make a function that start the electric vlave for CO2 when the PH is >6.50 and >6.20 .
But i don't want continuos on & off for little variation. Like the temp function:
void ReefAngelClass::StandardHeater(byte HeaterRelay, int LowTemp, int HighTemp)
{
if (Params.Temp1 == 0) return; // Don't turn the heater on if the temp is reading 0
if (Params.Temp1 <= LowTemp && Params.Temp1 > 0) Relay.On(HeaterRelay); // If sensor 1 temperature <= LowTemp - turn on heater
if (Params.Temp1 >= HighTemp) Relay.Off(HeaterRelay); // If sensor 1 temperature >= HighTemp - turn off heater
}
I make so:
void CO2(byte CO2Relay, int LowPH, int HighPH)
{
if (Params.PH == 0) return; // Don't turn the heater on if the temp is reading 0
if (Params.PH >= HighPH && Params.PH > 0 && Params.PH >= LowPH ) Relay.On(CO2Relay); // If sensor PH >= LowPH and <= HighPH - turn on the CO2
if (Params.PH <= LowPH) Relay.Off(CO2Relay); // If sensor PH <= HighPH - turn off the CO2
}
What do you think ? IS CORRECT ?
Thanks
Re: Intelligent PH function for Calcium Reactor
Posted: Tue Nov 22, 2011 3:04 am
by lukeluke
With help of my firend Siro
static bool co2on = false;
int LowPH;
int HighPH;
void CO2(byte CO2Relay, int LowPH, int HighPH)
{
if (Params.PH == 0) return; // Don't turn the heater on if the temp is reading 0
if (Params.PH >= HighPH ) co2on=true;
if (co2on) {
Relay.On(CO2Relay);
if (Params.PH <= LowPH){
Relay.Off(CO2Relay); // If sensor PH <= HighPH - turn off the CO2
co2on = false;
}
}
Re: Intelligent PH function for Calcium Reactor
Posted: Tue Nov 22, 2011 5:19 am
by binder
I haven't reviewed the code, so I'm not going to comment on accuracy. I will say that just looking at the code, if you keep this function inside your PDE file, you will have to make changes to it for it to work properly.
Code: Select all
static bool co2on = false;
void CO2(byte CO2Relay, int LowPH, int HighPH)
{
if (ReefAngel.Params.PH == 0) return;
if (ReefAngel.Params.PH >= HighPH ) co2on=true;
if (co2on) {
ReefAngel.Relay.On(CO2Relay);
if (ReefAngel.Params.PH <= LowPH){
ReefAngel.Relay.Off(CO2Relay); // If sensor PH <= HighPH - turn off the CO2
co2on = false;
}
}
This way you can actually reference the proper parameters and everything will compile for you.
To keep things a little simpler, I would have done something like this:
Code: Select all
void CO2(byte CO2Relay, int LowPH, int HighPH)
{
if (ReefAngel.Params.PH == 0) return;
// If sensor PH >= LowPH and PH >= HighPH - turn on the CO2
if (ReefAngel.Params.PH >= LowPH && ReefAngel.Params.PH >= HighPH) Relay.On(CO2Relay);
// If sensor PH < LowPH - turn off the CO2
if (ReefAngel.Params.PH < LowPH) Relay.Off(CO2Relay);
}
From your scenario you gave, you want the valve turned on when your PH exceeds your HighPH. Then you want it to run until the PH goes below the LowPH and not turn back on until the PH gets above the HighPH. Your code looked like it was close initially but was just off a little.
Hopefully this will work for you, if not, I'm sure somebody will correct it.
curt
Re: Intelligent PH function for Calcium Reactor
Posted: Tue Nov 22, 2011 5:52 am
by lukeluke
binder wrote:I haven't reviewed the code, so I'm not going to comment on accuracy. I will say that just looking at the code, if you keep this function inside your PDE file, you will have to make changes to it for it to work properly.
Code: Select all
static bool co2on = false;
void CO2(byte CO2Relay, int LowPH, int HighPH)
{
if (ReefAngel.Params.PH == 0) return;
if (ReefAngel.Params.PH >= HighPH ) co2on=true;
if (co2on) {
ReefAngel.Relay.On(CO2Relay);
if (ReefAngel.Params.PH <= LowPH){
ReefAngel.Relay.Off(CO2Relay); // If sensor PH <= HighPH - turn off the CO2
co2on = false;
}
}
This way you can actually reference the proper parameters and everything will compile for you.
ok...
To keep things a little simpler, I would have done something like this:
Code: Select all
void CO2(byte CO2Relay, int LowPH, int HighPH)
{
if (ReefAngel.Params.PH == 0) return;
// If sensor PH >= LowPH and PH >= HighPH - turn on the CO2
if (ReefAngel.Params.PH >= LowPH && ReefAngel.Params.PH >= HighPH) Relay.On(CO2Relay);
// If sensor PH < LowPH - turn off the CO2
if (ReefAngel.Params.PH < LowPH) Relay.Off(CO2Relay);
}
From your scenario you gave, you want the valve turned on when your PH exceeds your HighPH. Then you want it to run until the PH goes below the LowPH and not turn back on until the PH gets above the HighPH. Your code looked like it was close initially but was just off a little.
Hopefully this will work for you, if not, I'm sure somebody will correct it.
curt
imho this is wrong the second if is never true....
Re: Intelligent PH function for Calcium Reactor
Posted: Tue Nov 22, 2011 6:59 am
by binder
i will have to look at this more when i get home tonight. i'm at work and checking this during my short breaks so i may be a little off.
curt
Re: Intelligent PH function for Calcium Reactor
Posted: Tue Nov 22, 2011 7:19 am
by lukeluke
don't worry... i can use this :
static bool co2on = false;
void CO2(byte CO2Relay, int LowPH, int HighPH)
{
if (ReefAngel.Params.PH == 0) return;
if (ReefAngel.Params.PH >= HighPH ) co2on=true;
if (co2on) {
ReefAngel.Relay.On(CO2Relay);
if (ReefAngel.Params.PH <= LowPH){
ReefAngel.Relay.Off(CO2Relay); // If sensor PH <= HighPH - turn off the CO2
co2on = false;
}
}
logically it seems to work... :-d
Re: Intelligent PH function for Calcium Reactor
Posted: Wed Nov 23, 2011 5:01 am
by lukeluke
lukeluke wrote:don't worry... i can use this :
static bool co2on = false;
void CO2(byte CO2Relay, int LowPH, int HighPH)
{
if (ReefAngel.Params.PH == 0) return;
if (ReefAngel.Params.PH >= HighPH ) co2on=true;
if (co2on) {
ReefAngel.Relay.On(CO2Relay);
if (ReefAngel.Params.PH <= LowPH){
ReefAngel.Relay.Off(CO2Relay); // If sensor PH <= HighPH - turn off the CO2
co2on = false;
}
}
logically it seems to work... :-d
I was using this , and it work right.
Re: Intelligent PH function for Calcium Reactor
Posted: Wed Nov 23, 2011 8:39 am
by lukeluke
For the community, below the #include i put this:
static bool co2on = false;
void CO2(byte CO2Relay, int LowPH, int HighPH)
{
if (ReefAngel.Params.PH == 0) return;
if (ReefAngel.Params.PH >= HighPH ) co2on=true;
if (co2on) {
ReefAngel.Relay.On(CO2Relay);
if (ReefAngel.Params.PH <= LowPH){
ReefAngel.Relay.Off(CO2Relay); // If sensor PH <= HighPH - turn off the CO2
co2on = false;
}
}
}
and in the void loop() , this:
CO2(Port2,620,650);
Bye