Intelligent PH function for Calcium Reactor

Requests for new functions or software apps
Post Reply
lukeluke
Posts: 88
Joined: Mon Apr 04, 2011 4:12 am
Location: Rome, Italy

Intelligent PH function for Calcium Reactor

Post 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
lukeluke
Posts: 88
Joined: Mon Apr 04, 2011 4:12 am
Location: Rome, Italy

Re: Intelligent PH function for Calcium Reactor

Post 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;
}
}
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Intelligent PH function for Calcium Reactor

Post 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
lukeluke
Posts: 88
Joined: Mon Apr 04, 2011 4:12 am
Location: Rome, Italy

Re: Intelligent PH function for Calcium Reactor

Post 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....
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Intelligent PH function for Calcium Reactor

Post 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
lukeluke
Posts: 88
Joined: Mon Apr 04, 2011 4:12 am
Location: Rome, Italy

Re: Intelligent PH function for Calcium Reactor

Post 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
lukeluke
Posts: 88
Joined: Mon Apr 04, 2011 4:12 am
Location: Rome, Italy

Re: Intelligent PH function for Calcium Reactor

Post 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.
lukeluke
Posts: 88
Joined: Mon Apr 04, 2011 4:12 am
Location: Rome, Italy

Re: Intelligent PH function for Calcium Reactor

Post 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
Post Reply