Page 1 of 1

Ph Exp issue

Posted: Sun Apr 23, 2017 12:14 pm
by Armetas
Hello,

I have an issue with Ph expansion slot and co2 solenoid valve. CO2 solenoid valve keeps turning on/off a lot of times a day without reason. Actually there is a reason (there are two of them):

1st: as calcium reactor has feed pump ph changes during the seconds/minutes and this lead to that when ph reaches the border between limits - it switches co2 solenoid for a second and turns off, example: if solenoid should turn on when ph 6.50 and turn off when ph is 6.40 then when it reaches 6.49 and goes till 6.50 - it turns on solenoid just before it actually goes to 6.50

2nd: sometimes it just happens that you have ph in expansion 6.44 and suddenly it goes to 8.01 for a millisecond. Why - I don't know, but this triggers solenoid to turn on and off.

Here is the code that I'm using:

Code: Select all

if ( hour()>=7 && hour()<22 )            
    {if ( ReefAngel.Params.PHExp < 640 && ReefAngel.Params.PHExp >= 600) ReefAngel.Relay.Off(Box1_Port4); //CO2 Switch Off 635
     if ( ReefAngel.Params.PHExp >= 660 && ReefAngel.Params.PHExp < 800) ReefAngel.Relay.On(Box1_Port4); //CO2 Switch On 665
    } 
    else
    {ReefAngel.Relay.Off(Box1_Port4); //CO2 Switch Off
    }
Any ideas how to add some kind of criteria to measure ph exp for example few seconds and then decide - would be appreciated.

Re: Ph Exp issue

Posted: Sun Apr 23, 2017 4:58 pm
by rimai
You can average out the value over X amount of samples.

Code: Select all

static unsigned long lastmillis=millis();
static unsigned long avgphexp=0;
static unsigned int phexpvalues[] = {640,640,640,640,640};
static byte avgindex=0;
if ((millis() - lastmillis)>1000)
{
  lastmillis=millis();
  avgindex++;
  if (avgindex==5) avgindex=0;
  phexpvalues[avgindex)=ReefAngel.Params.PHExp;
  avgphexp=0;
  for (int a=0;a<5;a++)
  {
    avgphexp+=phexpvalues[a];
  }
  avgphexp=avgphexp/5;
}
// You can use avgphexp as the average value

Re: Ph Exp issue

Posted: Sun Apr 23, 2017 9:53 pm
by Armetas
Where should I put this code and what does it mean following:

if ((millis() - lastmillis)>1000)

Afterwards I should use just avgphexp instead of ReefAngel.Params.PHExp, yes?

if ( avgphexp >= 660 && avgphexp < 800) ReefAngel.Relay.On(Box1_Port4);

Re: Ph Exp issue

Posted: Mon Apr 24, 2017 9:25 pm
by rimai
custom section of your loop()
Correct use avgexp. The line is to grab reading every second.

Re: Ph Exp issue

Posted: Mon Apr 24, 2017 10:19 pm
by Armetas
Thank you, I will try that :)