Turn on relay when WL is at 100% or >?

Do you have a question on how to do something.
Ask in here.
User avatar
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL
PostPosted: Sun Aug 03, 2014 12:20 pm
This is probably simple for you guys.

I want to turn port 3 on thee main Relay on for 1 hour when WaterLevel 1 of the multi sensor is at 100% or above.

I think this is the basis for it, but I don't know know how to have it turn off after 1 hour.

Code: Select all
if (ReefAngel.WaterLevel.GetLevel(1)>=100) ReefAngel.Relay.On(Port3);


Thanks for your help.

Posts: 163
Joined: Mon Oct 15, 2012 7:21 pm
Location: Leesburg, GA
PostPosted: Sun Aug 03, 2014 12:57 pm
That looks about right. Not sure if you would need an Else statement in there or not also. I know from reading analog or digital pins i've added it.
User avatar
Posts: 2797
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
PostPosted: Sun Aug 03, 2014 1:04 pm
What you posted will keep the port on as long as the value is equal or above 100. As soon as it does not meet that criteria, it will not keep turning it on. You would want to put in an else statement to turn it off and also add in a timer to ensure that it shuts off after your specified time frame. You will also want to have a failsafe to prevent it from getting reactivated after the 1 hour time delay occurs.
that should be able to get you going in the right direction and maybe give you some tips for your coding. i'm sure others will be able to help more.
User avatar
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL
PostPosted: Sun Aug 03, 2014 1:08 pm
What I put will just turn the port on indefinitely, there needs to be something that will turn it off after 1hr.
User avatar
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL
PostPosted: Sun Aug 03, 2014 1:13 pm
binder wrote:What you posted will keep the port on as long as the value is equal or above 100. As soon as it does not meet that criteria, it will not keep turning it on. You would want to put in an else statement to turn it off and also add in a timer to ensure that it shuts off after your specified time frame. You will also want to have a failsafe to prevent it from getting reactivated after the 1 hour time delay occurs.
that should be able to get you going in the right direction and maybe give you some tips for your coding. i'm sure others will be able to help more.


Curt;

I agree with you.
I just have no idea how to code it.

Basically what I want to do is one I refill my ATO reservoir (either manually now or automatically in the future) I want the pump inside the reservoir to turn on for 1 hr (may change that later) to stir up and mix the Kalwasser that is either on the bottom of the reservoir that did not dissolve last time because it was above the saturation point or new Kalkwasser that I add to replenish what has been used up.
User avatar
Posts: 5423
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Sun Aug 03, 2014 1:24 pm
time_t stopTime = 0;
if (ReefAngel.WaterLevel.GetLevel(1)<=100) stopTime=now()+3600;

if (stopTime-now() < 3600) { ReefAngel.Relay.On(Port3); } else ReefAngel.Relay.Off(Port4); }

You just may want a flag to set the stopTime... But essentially above is what you want..i believe
User avatar
Posts: 5423
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Sun Aug 03, 2014 1:24 pm
time_t stopTime = 0;
if (ReefAngel.WaterLevel.GetLevel(1)<=100) stopTime=now()+3600;

if (stopTime-now() < 3600) { ReefAngel.Relay.On(Port3); } else ReefAngel.Relay.Off(Port4); }

You just may want a flag to set the stopTime... But essentially above is what you want..i believe
User avatar
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL
PostPosted: Sun Aug 03, 2014 1:35 pm
Thanks Lee.
I think that is what I want.

Basically the way I read it is if the Water Level is 100% or greater to turn on port 3 and start a 3600 (or 1 hr timer).
The stop time is checking if it is less then 3600 seconds or over and it will either leave port 3 on or turn off what I assume to be Port3 not Port4. Correct?

Code: Select all
time_t stopTime = 0;
if (ReefAngel.WaterLevel.GetLevel(1)<=100) stopTime=now()+3600;

if (stopTime-now() < 3600) { ReefAngel.Relay.On(Port3); } else ReefAngel.Relay.Off(Port3); }
User avatar
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL
PostPosted: Sun Aug 03, 2014 2:05 pm
I tried adding that code to the loop section right before my Auto Feeder code and it seems to be conflicting something.

I get the following error...

expected unqualified-id before 'if'

Here is my code...

Code: Select all
#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>fF
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>f
#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 <ReefAngel.h>

// Define Relay Ports by Name
#define Actinic_Lights     1
#define Day_Lights         2
#define Unused             3
#define Pumps              4
#define Sump_Fan           5
#define DeNit_Doser        6
#define DeNit_Pump         7
#define ATO_Pump           8

#define Unused             Box1_Port1
#define Feeder             Box1_Port2
#define Unused             Box1_Port3
#define Unused             Box1_Port4
#define Unused             Box1_Port5
#define Unused             Box1_Port6
#define Unused             Box1_Port7
#define Dummy              Box1_Port8


////// Place global variable code below here

// Does not need to be global.
// unsigned long ATOUpdate=0;

////// Place global variable code above here


void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = 0;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port4Bit;
ReefAngel.WaterChangePortsE[0] = Port1Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port1Bit | Port2Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit;
// Use T2 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
// Set the Overheat temperature setting
InternalMemory.OverheatTemp_write( 825 );
//Set Standard Menu
ReefAngel.AddStandardMenu();

// Feeeding and Water Change mode speed
ReefAngel.DCPump.FeedingSpeed=0;
ReefAngel.DCPump.WaterChangeSpeed=0;
ReefAngel.DCPump.ActinicChannel=Sync; // Now you're pump will be affected by the portal settings.
ReefAngel.DCPump.DaylightChannel=AntiSync; // Now you're pump will be affected by the portal settings.

// Ports that are always on
ReefAngel.Relay.On( Pumps );
ReefAngel.Relay.On( Dummy );

////// Place additional initialization code below here


////// Place additional initialization code above here
}

void loop()
{
  ReefAngel.StandardLights( Actinic_Lights,12,0,22,0 );
  ReefAngel.StandardLights( Day_Lights,13,0,21,0 );
  ReefAngel.StandardLights( Sump_Fan,13,0,21,0 );
  ReefAngel.WaterLevelATO(ATO_Pump,720,28,31);
  if ( hour()>=13 && hour()<21 )
  ReefAngel.PWM.SetChannel( 5, 0 );
  else
  ReefAngel.PWM.SetChannel( 5, PWMSlope(21,0,13,0,0,MoonPhase() ,60,0) );
 
  time_t stopTime = 0;
if (ReefAngel.WaterLevel.GetLevel(1)<=100) stopTime=now()+3600;

if (stopTime-now() < 3600) { ReefAngel.Relay.On(Port3); } else ReefAngel.Relay.Off(Port3); }
 
  ////// Place your custom code below here
 
  //AutoFeeder
static unsigned long autofeeding = 0;

if ((now()%SECS_PER_DAY==64800)) //if it is 6 pm
{
ReefAngel.FeedingModeStart(); //START FEEDING MODE
}

if (ReefAngel.DisplayedMenu==FEEDING_MODE)
{
if ( autofeeding == 0 ) {
autofeeding = now(); //set the time of the start of feeding to variable feeding
}

if ((now()-autofeeding>=60) && (now()-autofeeding<=61)) //if between 60 and 61 seconds has past
{
ReefAngel.Relay.On(Feeder); //TURN FEEDER RELAY ON
}
else
{
ReefAngel.Relay.Off(Feeder); //TURN FEEDER RELAY OFF
}
} else {
if ( autofeeding > 0 ) {
autofeeding = 0;
}
}
  // DeNitrate Routine
int DeNit_Offset=3600;
int DeNit_Repeat=21600;
int DeNit_Doser_Offset=1200;
int DeNit_Doser_Runtime=600;
int DeNit_Pump_Runtime=1200;
int DeNit_ATO_Offtime=1500;

// Pump comes on first
ReefAngel.Relay.Set(DeNit_Pump,(now()-DeNit_Offset)%DeNit_Repeat<DeNit_Pump_Runtime);  // Runs denitrator pump
// Doser comes on second
ReefAngel.Relay.Set(DeNit_Doser,((now()-DeNit_Offset)-DeNit_Doser_Offset)%DeNit_Repeat<DeNit_Doser_Runtime); // Runs denitrator doser
   
  // Disable ATO
if ( (now()-3600)%21600<DeNit_ATO_Offtime) ReefAngel.WaterLevelATO(ATO_Pump,720,0,1);

  // Delay WL ATO after water change and DeNit_Dosing
  static time_t wcTimer=0;
  if (ReefAngel.DisplayedMenu == WATERCHANGE_MODE) wcTimer=now();

  // First 10 minutes after WC disable ATO
  if (now()-wcTimer >= 0 && now()-wcTimer < 600)
    ReefAngel.WaterLevelATO(ATO_Pump,720,0,1);

    // Track Salinity low duration
    static unsigned long lastGoodSal;
    static boolean lowSalFlag;
   
    // Salinity is good, update counter
    if (ReefAngel.Params.Salinity>=335) lastGoodSal=now();
   
    // Counter hasn't been updating in 300 seconds..
    if (now()-lastGoodSal>300) {
      lowSalFlag=true; // Salinity is definitely below 33.5
    } else {
      lowSalFlag=false; // Salinity back to normal
    }
   
    // Disable ATO if lowSalFlag is true
    if (lowSalFlag) ReefAngel.WaterLevelATO(ATO_Pump,720,0,1);
   
  // Disable ATO if ATO High IsActive()
  if (ReefAngel.HighATO.IsActive())
    ReefAngel.WaterLevelATO(ATO_Pump,720,0,1);
   

// Add random mode if we set to Mode to Custom in portal
static int rmode;
static boolean changeMode=true;

// Add Else Mode definition..
const int Else=16;

// These are the modes we can cycle through. You can add more and even repeat...
byte modes[] = { ReefCrest, Lagoon, Constant, TidalSwell, ShortPulse, LongPulse, Else };

if (now()%SECS_PER_DAY==0 || changeMode==true) { // Change at midnight or if controller rebooted
rmode=random(100)%sizeof(modes); // Change the mode once per day to pick from our array
changeMode=false;
}

// Set timer when in feeding mode
static unsigned long feeding;
if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();

if (now()-feeding<3600) {
  // Continue NTM for the 60 minutes
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()%SECS_PER_DAY<43200 || now()%SECS_PER_DAY>=79200) { // 12pm / 10pm
  // Night mode (go to 30%)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=Constant;
  ReefAngel.DCPump.Speed=30;
} else if (InternalMemory.DCPumpMode_read()==11) {
  // Custom Mode and nothing else going on
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  if (modes[rmode]==Else) {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Mode=Constant;
    ReefAngel.DCPump.Speed=ElseMode(InternalMemory.DCPumpSpeed_read(),20,true );    // ElseMode on sync mode, Portal Speed Setting +/- 20%
  } else {
    ReefAngel.DCPump.Mode=modes[rmode];  // Put the mode to the random mode :)
    ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
  }
} else {
  ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
}

  ////// Place your custom code above here

  // This should always be the last line
  ReefAngel.Portal( "Sacohen","xxxxxxxx );
  ReefAngel.ShowInterface();
}

void DrawCustomMain()
{
int x,y;
char text[10];
// Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 20, ReefAngel.Params,
ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 20, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
pingSerial();

// Water Level
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,75,57, "WL:" );
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,99,57, ReefAngel.WaterLevel.GetLevel() );

ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,66,66, "WL 1:" );
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,99,66, ReefAngel.WaterLevel.GetLevel(1) );

//Salinity 
  ConvertNumToString(text, ReefAngel.Params.Salinity, 10);
  strcat(text,"  ");
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,39,75,"Salinity:");
  ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,99,75,text);
pingSerial();

// Main Relay Box
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox( 12, 92, TempRelay );
pingSerial();
TempRelay = ReefAngel.Relay.RelayDataE[0];
TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
ReefAngel.LCD.DrawOutletBox(12, 104, TempRelay);

// Date and Time
ReefAngel.LCD.DrawDate( 6, 122 );
pingSerial();
}

void DrawCustomGraph()
{
}
byte ElseMode( byte MidPoint, byte Offset, boolean WaveSync )
{
  // Static's only initialize the first time they are called
  static unsigned long LastChange=millis();        // Set the inital time that the last change occurred
  static int Delay = random( 500, 3000);           // Set the initial delay
  static int NewSpeed = MidPoint;                  // Set the initial speed
  static int AntiSpeed = MidPoint;                 // Set the initial anti sync speed
  if ((millis()-LastChange) > Delay)               // Check if the delay has elapsed
  {
    Delay=random(500,5000);                        // If so, come up with a new delay
    int ChangeUp = random(Offset);                 // Amount to go up or down
    if (random(100)<50)                            // 50/50 chance of speed going up or going down
    {
      NewSpeed = MidPoint - ChangeUp;
      AntiSpeed = MidPoint + ChangeUp;
    }
    else
    {
      NewSpeed = MidPoint + ChangeUp;
      AntiSpeed = MidPoint - ChangeUp;
    }
    LastChange=millis();                           // Reset the time of the last change
  }
  if (WaveSync)
  {
    return NewSpeed;
  }
  else
  {
    return AntiSpeed;
  }
}
User avatar
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL
PostPosted: Sun Aug 03, 2014 2:21 pm
lnevo wrote:time_t stopTime = 0;
if (ReefAngel.WaterLevel.GetLevel(1)<=100) stopTime=now()+3600;

if (stopTime-now() < 3600) { ReefAngel.Relay.On(Port3); } else ReefAngel.Relay.Off(Port4); }

You just may want a flag to set the stopTime... But essentially above is what you want..i believe

Lee;

Is the time_t stop Time function in the 1.1.0 libraries or were they pur into the 1.1 1 libraries?
Next

Return to How do I code ...

Who is online

Users browsing this forum: Google [Bot] and 2 guests