I need help coding for my automatic water change pump. I want to turn on port 2 every 6 hours for 18 min. I also want to use the two float switches in the saltwater container to have port 2 turn off when it reaches the low float switch and have it turn back on when the high is activated. This would act as a fail safe so when the saltwater bin gets too low it won't pump water out of the tank when there is no more water in the saltwater container. Here is my current code.
#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 <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 <PAR.h>
#include <ReefAngel.h>
////// Place global variable code below here
////// Place global variable code above here
void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
ReefAngel.Use2014Screen(); // Let's use 2014 Screen
ReefAngel.DDNS("Damien");
ReefAngel.AddMultiChannelWaterLevelExpansion(); // Multi-Channel Water Level Expanion Module
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = Port1Bit | Port6Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port6Bit | Port7Bit | Port8Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port5Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port3Bit;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
// Set the Overheat temperature setting
InternalMemory.OverheatTemp_write( 800 );
InternalMemory.WaterLevelMax_write(1800);
// Feeeding and Water Change mode speed
// Ports that are always on
ReefAngel.Relay.On( Port1 );
ReefAngel.Relay.On( Port6 );
ReefAngel.Relay.On( Port8 );
////// Place additional initialization code below here
////// Place additional initialization code above here
}
void loop()
{
ReefAngel.StandardHeater( Port3,780,785 );
ReefAngel.WaterLevelATO(4,Port4,240,36,38);
////// Place your custom code below here
if (ReefAngel.WaterLevel.GetLevel(1)>45) ReefAngel.PWM.SetActinic(50);
else
ReefAngel.PWM.SetActinic(100);
if (ReefAngel.WaterLevel.GetLevel(2)>85)
ReefAngel.Relay.Off(Port1);
else
ReefAngel.Relay.On(Port1);
////// Place your custom code above here
// This should always be the last line
ReefAngel.Portal( "Ismaclst" );
ReefAngel.ShowInterface();
}
This tells Port2 to turn on if the condition is met. The condition breaks down the current time into 6 hour chunks. If that time is less than 18 minutes then the port will be on. You can adjust the runtime by changing 18*SECS_PER_MINUTE and the repeat interval by changing the 6*SECS_PER_HOUR.
if (ReefAngel.LowATO.IsActive()) ReefAngel.Relay.Override(Port2,0); // Disable the port until overriden manually
if (ReefAngel.HighATO.IsActive()) ReefAngel.Relay.Override(Port2,2); // Set port back to auto
Great, thanks! I'm obviously not very good at coding! So does the first line go in the void setup and the other goes in the void loop? Can't wait to have this automated to reduce tank maintenance.
Last edited by Ismaclst on Sun Feb 14, 2016 11:56 am, edited 1 time in total.
Best thing I've ever done!!! Can't believe it took me so long to get the tubing run and everything mounted. Was sitting on all the equipment for almost 2 years...
if (ReefAngel.LowATO.IsActive()) ReefAngel.Relay.Override(Port2,0); // Disable the port until overriden manually
if (ReefAngel.HighATO.IsActive()) ReefAngel.Relay.Override(Port2,2); // Set port back to auto
What would I need to change this to if I was going to use channel 1 of the multi channel water expansion? I was going to use the float switches but it would require a fancy bracket. Since I had one channel left, I figured this would make it a lot easier to setup.
I finally got my pump and plumbing hooked up for my AWC last night. I put a bucket at the discharge tubing end to see if it was actually pumping water from the sump. I got home from work today to find that there was no water in the bucket when there should have been about a gallon. I checked the portal to see if that port turned on but it hadn't all day. Not sure if something is wrong with by code or not. Here is my most recent one.
#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 <Tide.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 <PAR.h>
#include <ReefAngel.h>
////// Place global variable code below here
////// Place global variable code above here
Tide tide;
void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
ReefAngel.Use2014Screen(); // Let's use 2014 Screen
ReefAngel.DDNS("Damien");
ReefAngel.AddMultiChannelWaterLevelExpansion(); // Multi-Channel Water Level Expanion Module
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = Port1Bit | Port6Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port6Bit | Port7Bit | Port8Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port5Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port3Bit;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
ReefAngel.Relay.Set(Port8, now()%6*SECS_PER_HOUR<30*SECS_PER_MIN);
// Set the Overheat temperature setting
InternalMemory.OverheatTemp_write( 800 );
InternalMemory.WaterLevelMax_write(1800);
// Feeeding and Water Change mode speed
// Ports that are always on
ReefAngel.Relay.On( Port1 );
ReefAngel.Relay.On( Port6 );
tide.Init(55,10,30);
tide.SetWaveLength(12+SECS_PER_HOUR);
////// Place additional initialization code below here
////// Place additional initialization code above here
}
void loop()
{
ReefAngel.StandardHeater( Port3,780,785 );
ReefAngel.WaterLevelATO(4,Port4,240,28,31);
////// Place your custom code below here
if (ReefAngel.WaterLevel.GetLevel(1)<5) //Disable the port until overriden manually
ReefAngel.Relay.Override(Port8,0); //Saltwater Reservoir
if (ReefAngel.WaterLevel.GetLevel(1)>80) // Set port back to auto
ReefAngel.Relay.Override(Port8,2);
if (ReefAngel.WaterLevel.GetLevel(2)>80) //Overflow
ReefAngel.Relay.Off(Port1);
else
ReefAngel.Relay.On(Port1);
if (ReefAngel.WaterLevel.GetLevel(3)>87) //ATO Reservoir
ReefAngel.Relay.Off(Port5);
if (ReefAngel.WaterLevel.GetLevel(3)<1)
ReefAngel.Relay.On(Port5);
////// Place your custom code above here
// This should always be the last line
ReefAngel.Portal( "Ismaclst" );
ReefAngel.ShowInterface();
}
byte setMaxspect(byte minSpeed, byte maxSpeed, boolean PulseSync)
{
int reverse_speed=0;
int forward_speed=45;
// swap between forward and reverse every X seconds
reverse_speed = ShortPulseMode(0,100,ReefAngel.DCPump.Duration*2,true);
if (reverse_speed == 100) {
//
// while we are going in reverse increase the speed by 10
forward_speed = ShortPulseMode(35+10, 60+10,ReefAngel.DCPump.Duration,true);
} else {
//
// while we are going forward set speed to 25-40 to keep
// from blowing corals off the rocks
forward_speed = ShortPulseMode(35,70, ReefAngel.DCPump.Duration, true);
}
if (PulseSync) {
return forward_speed;
} else {
return reverse_speed;
}
}
Sorry. Didn't see that because it was in the wrong section.
setup() only runs at the initialization of the controller.
It should be in the loop() section.
I think something is wrong with that line of code. I needed it to run for 30 minutes every 6 hours. Right now its turning off and on about every 6 seconds.
I think you need to some parenthesis to isolate the math.
You have to think it just like you would interpret it. If you have doubts, so does the controller.
So, now()%6*SECS_PER_HOUR<30*SECS_PER_MIN would be read like this:
now() modulo 6 * 3600 < 30 * 60
the first calculation is now() modulo 6. The result is multiplied by 3600. The result is checked if it is less than 30 and then the result is multiplied by 60.
Definitely not what you want.
Just like regular math, parenthesis is very important.
You math should be:
(now()%(6*SECS_PER_HOUR))<(30*SECS_PER_MIN)
#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 <Tide.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 <PAR.h>
#include <ReefAngel.h>
////// Place global variable code below here
////// Place global variable code above here
Tide tide;
void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
ReefAngel.Use2014Screen(); // Let's use 2014 Screen
ReefAngel.DDNS("Damien");
ReefAngel.AddMultiChannelWaterLevelExpansion(); // Multi-Channel Water Level Expanion Module
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = Port1Bit | Port6Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port6Bit | Port7Bit | Port8Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port5Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port3Bit;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
// Set the Overheat temperature setting
InternalMemory.OverheatTemp_write( 800 );
InternalMemory.WaterLevelMax_write(1800);
// Feeeding and Water Change mode speed
// Ports that are always on
ReefAngel.Relay.On( Port1 );
ReefAngel.Relay.On( Port6 );
tide.Init(55,10,30);
tide.SetWaveLength(12+SECS_PER_HOUR);
////// Place additional initialization code below here
////// Place additional initialization code above here
}
void loop()
{
ReefAngel.StandardHeater( Port3,780,785 );
ReefAngel.WaterLevelATO(4,Port4,240,28,31);
ReefAngel.Relay.Set(Port8, (now()%(6*SECS_PER_HOUR))<(30*SECS_PER_MIN);
////// Place your custom code below here
if (ReefAngel.WaterLevel.GetLevel(1)<5) //Disable the port until overriden manually
ReefAngel.Relay.Override(Port8,0); //Saltwater Reservoir
if (ReefAngel.WaterLevel.GetLevel(1)>80) // Set port back to auto
ReefAngel.Relay.Override(Port8,2);
if (ReefAngel.WaterLevel.GetLevel(2)>80) //Overflow
ReefAngel.Relay.Off(Port1);
else
ReefAngel.Relay.On(Port1);
if (ReefAngel.WaterLevel.GetLevel(3)>87) //ATO Reservoir
ReefAngel.Relay.Off(Port5);
if (ReefAngel.WaterLevel.GetLevel(3)<1)
ReefAngel.Relay.On(Port5);
////// Place your custom code above here
// This should always be the last line
ReefAngel.Portal( "Ismaclst" );
ReefAngel.ShowInterface();
}
byte setMaxspect(byte minSpeed, byte maxSpeed, boolean PulseSync)
{
int reverse_speed=0;
int forward_speed=45;
// swap between forward and reverse every X seconds
reverse_speed = ShortPulseMode(0,100,ReefAngel.DCPump.Duration*2,true);
if (reverse_speed == 100) {
//
// while we are going in reverse increase the speed by 10
forward_speed = ShortPulseMode(35+10, 60+10,ReefAngel.DCPump.Duration,true);
} else {
//
// while we are going forward set speed to 25-40 to keep
// from blowing corals off the rocks
forward_speed = ShortPulseMode(35,70, ReefAngel.DCPump.Duration, true);
}
if (PulseSync) {
return forward_speed;
} else {
return reverse_speed;
}
}
Copy and paste in place of the other one. You are missing one parenthesis.
It's just like when you did math in high school. One opening parenthesis needs to have its corresponding closing parenthesis to complete the formula.