pH controller
-
gaberosenfield
- Posts: 89
- Joined: Thu Mar 08, 2012 5:11 pm
- Location: Redwood City, California
pH controller
First, I am even less than a newb...I just got my reef angel today and I have never had any programming experience. I was able to use RAgen with some tweaking to get a few basic functions from my reef angel (temp, light, pump, skimmer). However, I won a reef angel dosing pump at a raffle at a DFWMAS event here in Dallas. I want to use it to dose calcium (CaCl2 + MgSO4) and alk (NaHCO3 mixed with NaOH for a pH~9). Here's the catch: I want the alk to be dosed based upon the pH in my system (if pH<8, then dose alk) and I want the calcium to be dosed based upon how much alk is dosed but with a delay. For example. Lets say my pH probe reads my pH = 8. Then I want my reef angel to dose alk until pH = 8.2, which should take X minutes of dosing. Then, like 10 minutes later, I want my reef angel to dose calcium for X minutes. Does this make sense? Anyone think they can help me? I haven't been able to find anything about pH control with the reef angel yet.
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: pH controller
Congratz on the raffle winning 
How much of a difference you would like to allow??
In the scenario above, you waited the pH drop from 8.2 to 8.0
How much of a difference you would like to allow??
In the scenario above, you waited the pH drop from 8.2 to 8.0
Roberto.
-
gaberosenfield
- Posts: 89
- Joined: Thu Mar 08, 2012 5:11 pm
- Location: Redwood City, California
Re: pH controller
Thanks 
I mean, in a perfect world the pH would stay at exactly 8.2, but I realize that is impossible. So I figure between 8 and 8.2 or 8.1 and 8.3 is an OK range. If you think it wouldn't be turning the dosing pump on every 5 minutes then I suppose between 8.1 and 8.2 would be good too.
I mean, in a perfect world the pH would stay at exactly 8.2, but I realize that is impossible. So I figure between 8 and 8.2 or 8.1 and 8.3 is an OK range. If you think it wouldn't be turning the dosing pump on every 5 minutes then I suppose between 8.1 and 8.2 would be good too.
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: pH controller
We can definitely create a way for you to dose it that way.
I don't know how big your tank is and how much you've got, but I dose 3 secs every hour and it's enough in my case.
What you are going to probably experiencing is the dosing only happening at night when pH drops.
So, try this code and let me know if it works:
I don't know how big your tank is and how much you've got, but I dose 3 secs every hour and it's enough in my case.
What you are going to probably experiencing is the dosing only happening at night when pH drops.
So, try this code and let me know if it works:
Code: Select all
#include <Salinity.h>
#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#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 <RF.h>
#include <IO.h>
#include <ORP.h>
#include <ReefAngel.h>
unsigned long startmillis;
unsigned long durationmillis;
boolean dosing=false;
void setup()
{
ReefAngel.Init();
ReefAngel.Timer[1].SetInterval(600);
}
void loop()
{
if (ReefAngel.Params.PH<800 && !dosing)
{
dosing=true;
startmillis=millis();
ReefAngel.Relay.On(Port1);
}
if (ReefAngel.Params.PH>820 && dosing)
{
dosing=false;
durationmillis=millis()-startmillis;
durationmillis/=1000;
ReefAngel.Relay.Off(Port1);
ReefAngel.Timer[1].Start();
ReefAngel.Timer[2].SetInterval(durationmillis);
}
if (ReefAngel.Timer[1].IsTriggered())
{
ReefAngel.Relay.On(Port2);
ReefAngel.Timer[2].Start();
}
if (ReefAngel.Timer[2].IsTriggered())
{
ReefAngel.Relay.Off(Port2);
}
ReefAngel.ShowInterface();
}
Roberto.
-
gaberosenfield
- Posts: 89
- Joined: Thu Mar 08, 2012 5:11 pm
- Location: Redwood City, California
Re: pH controller
Thanks in advance for all your help. I will try this, but I just realized a bigger problem. I just attempted to calibrate my pH probe for like 30 minutes. It will not calibrate properly. I have independently verified the pHs of my standards (7 and 10) and the probe reads both of them lower than my tank water. It reads that my tank water is pH = 15.5...something is terribly wrong. Any advice?
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
-
gaberosenfield
- Posts: 89
- Joined: Thu Mar 08, 2012 5:11 pm
- Location: Redwood City, California
Re: pH controller
around 340 for the pH 7 standard and around 360 for the pH 10 standard. In the tank water (ph~8) it read ~480
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: pH controller
Those numbers doesn't look correct.
Dit you take it out of the bottle and rinsed prior to calibrating?
Was the storage bottle dry?
Dit you take it out of the bottle and rinsed prior to calibrating?
Was the storage bottle dry?
Roberto.
-
gaberosenfield
- Posts: 89
- Joined: Thu Mar 08, 2012 5:11 pm
- Location: Redwood City, California
Re: pH controller
It came in a storage bottle with fluid in it. Before I removed the probe from the storage fluid it read pH=6.6. I removed it carefully from the bottle, rinsed it in DI water, hit the calibrate function, and put it in my pH=7 standard. Waited for the numbers to stabilize, removed it from the first standard and rinsed it in DI water, and placed it in the pH=10 standard. Waited again and hit OK. I also repeated that procedure without rinsing in between the 2 standards. I have some experience with this as I work in a genetics lab at a university (I am a student) and routinely calibrate pH probes.
-
gaberosenfield
- Posts: 89
- Joined: Thu Mar 08, 2012 5:11 pm
- Location: Redwood City, California
Re: pH controller
Also, I tried the code you posted. It didn't work. All I altered were the port numbers (7 and 8 instead of 1 and 2) and the trigger pH values (on under 13 and off over 14; I did this only to test the code because DI water reads at 12.3 and my tank water reads at 15.5 so I knew I could get to those trigger pH values). The dosing pumps don't turn on. I tested them and the pumps do work....
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
-
gaberosenfield
- Posts: 89
- Joined: Thu Mar 08, 2012 5:11 pm
- Location: Redwood City, California
Re: pH controller
CRAP! You're right. Its broken. How do I contact reef angel to get a replacement? Do I contact you
?
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
-
gaberosenfield
- Posts: 89
- Joined: Thu Mar 08, 2012 5:11 pm
- Location: Redwood City, California
Re: pH controller
Just wanted to let you know that your code and the pH probe work perfectly! Thanks Roberto 
-
gaberosenfield
- Posts: 89
- Joined: Thu Mar 08, 2012 5:11 pm
- Location: Redwood City, California
Re: pH controller
I think I spoke too soon saying the code works perfectly. Sometimes it seems to work perfectly, but occasionally the Alk dosing will not turn off at the set point. Just Yesterday I came home and my pH was over 8.6, even though I set the Alk dosing off point to pH=8. Here is my code (the pH controller part is directly copied from what Roberto wrote for me, with only the pH points for Alk dosing on and off changed):
Any idea why it would work sometimes and fail other times? I imagine it has something to do with how the timers are set up, but can't quite figure it out on my own...
Code: Select all
/* The following features are enabled for this File:
#define DisplayImages
#define DateTimeSetup
#define VersionMenu
#define DirectTempSensor
#define SIMPLE_MENU
#define DosingPumpSetup
*/
#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#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 <ReefAngel.h>
unsigned long startmillis;
unsigned long durationmillis;
boolean dosing=false;
void setup()
{
ReefAngel.Init(); //Initialize controller
ReefAngel.FeedingModePorts = Port4Bit | Port5Bit | Port7Bit | Port8Bit;
ReefAngel.WaterChangePorts = Port4Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit;
ReefAngel.OverheatShutoffPorts = 0;
ReefAngel.LightsOnPorts = Port1Bit;
ReefAngel.Timer[1].SetInterval(600);//Uncomment for Ca Dosing
// Ports that are always on
ReefAngel.Relay.On(Port4); // Return, Circulation Pump, and Aqualifter
// Initialize and start the RA Client logging timer
ReefAngel.Timer[4].SetInterval(15); // set interval to 15 seconds
ReefAngel.Timer[4].Start();
}
void loop()
{
// Specific functions
ReefAngel.StandardLights(Port1,9,30,20,30); // White Lights
ReefAngel.StandardLights(Port2,9,00,21,00); // Blue Lights
ReefAngel.StandardLights(Port3,21,00,9,00); // Refugium Light
ReefAngel.DosingPump1(Port7); //Alkalinity, pump 1
ReefAngel.DosingPump2(Port8); //Calcium, pump 2
ReefAngel.StandardHeater(Port5,783,787); //Heater
ReefAngel.Relay.On(Port6); // Skimmer
ReefAngel.ShowInterface();
if (ReefAngel.Params.PH<795 && !dosing)
{
dosing=true;
startmillis=millis();
ReefAngel.Relay.On(Port7);
}
if (ReefAngel.Params.PH>800 && dosing)
{
dosing=false;
durationmillis=millis()-startmillis;
durationmillis/=1000;
ReefAngel.Relay.Off(Port7);
ReefAngel.Timer[1].Start(); //Delay for Ca Dosing
ReefAngel.Timer[2].SetInterval(durationmillis); //Shutoff timer for Ca Dosing
}
if (ReefAngel.Timer[1].IsTriggered())//Ca dosing on
{
ReefAngel.Relay.On(Port8);
ReefAngel.Timer[2].Start();
}
if (ReefAngel.Timer[2].IsTriggered())//Ca dosing off
{
ReefAngel.Relay.Off(Port8);
}
// Dump Params
if(ReefAngel.Timer[4].IsTriggered())
{
Serial.flush();
Serial.print("<RA><T1>");
Serial.print(ReefAngel.TempSensor.ReadTemperature(ReefAngel.TempSensor.addrT1));
Serial.print("</T1><T2>");
Serial.print(ReefAngel.TempSensor.ReadTemperature(ReefAngel.TempSensor.addrT2));
Serial.print("</T2><T3>");
Serial.print(ReefAngel.TempSensor.ReadTemperature(ReefAngel.TempSensor.addrT3));
Serial.print("</T3><PH>");
Serial.print(ReefAngel.Params.PH);
Serial.print("</PH><R>");
Serial.print(ReefAngel.Relay.RelayData,DEC);
Serial.print("</R><RON>");
Serial.print(ReefAngel.Relay.RelayMaskOn,DEC);
Serial.print("</RON><ROFF>");
Serial.print(ReefAngel.Relay.RelayMaskOff,DEC);
Serial.print("</ROFF></RA>");
ReefAngel.Timer[4].Start();
}
}-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: pH controller
You need to remove this:
Or this code will also activate Port 7 and 8 according to the dosing pump schedule.
Code: Select all
ReefAngel.DosingPump1(Port7); //Alkalinity, pump 1
ReefAngel.DosingPump2(Port8); //Calcium, pump 2
Roberto.
-
gaberosenfield
- Posts: 89
- Joined: Thu Mar 08, 2012 5:11 pm
- Location: Redwood City, California
Re: pH controller
Ok, I removed the indicated code. I will post again after I have tested it out. I didn't realize that the DosingPump functions would dose for some standard time without inputting the cycle durations and dosing durations etc...
-
binder
- Posts: 2865
- Joined: Fri Mar 18, 2011 6:20 pm
- Location: Illinois
- Contact:
Re: pH controller
Those functions operate from the values in the Internal Memory. I believe the default values are 10 seconds each if you did not change them at all.gaberosenfield wrote:Ok, I removed the indicated code. I will post again after I have tested it out. I didn't realize that the DosingPump functions would dose for some standard time without inputting the cycle durations and dosing durations etc...
-
gaberosenfield
- Posts: 89
- Joined: Thu Mar 08, 2012 5:11 pm
- Location: Redwood City, California
Re: pH controller
I did not knowingly change the default values, but the dosing pumps must have been on for multiple minutes each in order to raise my pH by almost 0.7 units....
-
gaberosenfield
- Posts: 89
- Joined: Thu Mar 08, 2012 5:11 pm
- Location: Redwood City, California
Re: pH controller
Well, although I believe the code works, there are just too many problems with trying to use this pH controlled dosing scheme with my current setup. The biggest problem is that I am only using 2 liter bottles as my Ca and Alk supplement containers. If the Alk supplement is emptied, then the alk dosing pump stays on. If the pH then rises (like during the day or something) then the alk dosing pump shuts off and ten minutes later the Ca dosing pump turns on and stays on for the same amount of time as the alk pump was on which might have been all night! This tends to cause over doses of Ca and precipitous drops in alk, which makes my system less stable, defeating the purpose of this dosing scheme. I could solve this problem in 2 ways: 1) never let the alk or Ca supplement containers empty, or 2) code in a timer that prevents either pump from staying on longer than like 1 minute. But it's easier for me to remember to dose Ca and alk every day than it is for me to remember to refill the dosing containers at variable intervals depending on water changes and other factors. Also, I have decided that with the amount of water changes I do to my nano tank, I probably don't really need dosing at all, so I think I will just abandon the idea for now and measure my Ca and alk levels for the next few weeks to see if they get too low. Still, this code makes a good basis for a pH controlled dosing scheme, so if anyone else out there wants to try it and improve it, go for it!
