Simple if/then statements not working

Do you have a question on how to do something.
Ask in here.
Post Reply
jcjrogersstar
Posts: 43
Joined: Thu Jan 04, 2018 10:47 pm

Simple if/then statements not working

Post by jcjrogersstar »

I just added my Ca Reactor and was adding code to shut it down if tank pH (not Expansion pH) gets below 7.75. Even though my pH is well above that, the ports turn-off immediately once code is loaded and even after a second reboot. I verified it was these statements by remming them out. What am I missing?

if ( ReefAngel.Params.PH <= 775 ) ReefAngel.Relay.Off( Box1_Port1 ); ///Turns off Carbon Doser if tank pH <= 7.75.
if ( ReefAngel.Params.PH <= 775 ) ReefAngel.Relay.Off( Box1_Port6 ); //Turns off Ca Reactor Ca Pump if tank pH <= 7.75.
if ( ReefAngel.Params.PH <= 775 ) ReefAngel.Relay.Off( Box2_Port8 ); //Turns off Ca Reactor Fill Pump if tank pH <= 7.75.

Code: Select all

#include <ReefAngel_Features.h>
#include <Salinity.h>
#include <Globals.h>
#include <RA_TS.h>
#include <RA_TouchLCD.h>
#include <RA_TFT.h>
#include <RA_TS.h>
#include <Font.h>
#include <RA_Wifi.h>
#include <RA_Wiznet5100.h>
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetDHCP.h>
#include <PubSubClient.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_ATO.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 <RA_CustomLabels.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <Humidity.h>
#include <PAR.h>
#include <DCPump.h>
#include <ReefAngel.h>
#include <SoftwareSerial.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.Star();
    ReefAngel.AddWaterLevelExpansion();  // Water Level Expansion Module
    ReefAngel.AddMultiChannelWaterLevelExpansion();  // Multi-Channel Water Level Expanion Module
    ReefAngel.AddPHExpansion();  // pH Expansion Module
    ReefAngel.AddRANet();  // RANet Add-On Module
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = 0;
    ReefAngel.FeedingModePortsE[0] = Port7Bit | Port8Bit;  //UV and UV Pump-off.
    ReefAngel.FeedingModePortsE[1] = Port7Bit;  //Skimmer-off.
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = 0;
    ReefAngel.WaterChangePortsE[0] = Port1Bit | Port2Bit | Port3Bit | Port6Bit | Port7Bit | Port8Bit;
    ReefAngel.WaterChangePortsE[1] = Port4Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit;  
    ReefAngel.WaterChangePortsE[2] = Port1Bit | Port2Bit; 
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = 0;
    ReefAngel.OverheatShutoffPortsE[0] = Port1Bit | Port2Bit | Port6Bit | Port7Bit | Port8Bit;
    ReefAngel.OverheatShutoffPortsE[1] = Port1Bit | Port3Bit | Port5Bit | Port7Bit | Port8Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = 0;
    ReefAngel.LightsOnPortsE[1] = Port1Bit;  // Powermodule Fixture On.
    // Use T2 probe as temperature and overheat functions
    ReefAngel.TempProbe = T2_PROBE;
    ReefAngel.OverheatProbe = T2_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_read();  // trying this code to see if it pulls internal memory overheat temp.

    // Ports that are always on
    
    ReefAngel.Relay.On( Box1_Port1 );  // Carbon Doser (CaR CO2 Doser) always on. 
    ReefAngel.Relay.On( Box1_Port3 );  // Gyres always on.
    ReefAngel.Relay.On( Box1_Port6 );  // Calcium Reactor Recirculation Pump (CaR Recirc Pump) always on. 
    ReefAngel.Relay.On( Box1_Port8 );  // UV Pump always on.
    ReefAngel.Relay.On( Box2_Port1 );  // Powermodule Lights/Fans always on.
    ReefAngel.Relay.On( Box2_Port4 );  // Return Pump always on.
    ReefAngel.Relay.On( Box2_Port8 );  // Calcium Reactor Fill Pump (CaR Fill Pump) always on.
    
    ////// Place additional initialization code below here

    InternalMemory.FeedingTimer_write(7200);  // sets feeding mode to 2 hours (only used for coral feeding)... shuts down UV bulb, UV pump, and skimmer.
    ////// Place additional initialization code above here
}

void loop()
{
    ReefAngel.StandardLights( Box2_Port3 ); //Using Internal Memory Standard Lights to run Refugium Light.
    ReefAngel.StandardHeater2( Box1_Port2 );
    ReefAngel.StandardHeater2( Box2_Port5 );
    ReefAngel.StandardFan2( Box2_Port6 );  //Sump Fans
    ReefAngel.Relay.DelayedOn( Box2_Port7 ); //Skimmer
    ReefAngel.WaterLevelATO( 1,Box3_Port1); //ATO pump-DC relay box-new program.    
    //ReefAngel.PWM.DaylightPWMSlope(); - not using PWM for main LEDs
    //ReefAngel.PWM.ActinicPWMSlope(); - not using PWM for main LEDs
    ReefAngel.StandardHeater( Box1_Port7,788,796 ); //Manages UV bulb on/off based on tank temp.  
    ReefAngel.DosingPumpRepeat1( Box3_Port2 );  // Pump dosing kalk-DC Relay Box.
    ReefAngel.DosingPumpRepeat( Box1_Port4,0,60,2700 );  // Stirrer on/off.

   boolean buzzer=false;
   // if ( ReefAngel.isATOTimeOut() ) buzzer=true;
   if ( ReefAngel.isOverheat() ) buzzer=true;
   if ( buzzer ) ReefAngel.BuzzerOn(2); else ReefAngel.BuzzerOff();
   if ( ReefAngel.Params.PH > 844 ) ReefAngel.Relay.Off( Box3_Port2 );   //Turns off Kalk Stirrer dosing if tank pH > 8.44.
   if ( ReefAngel.Params.PH <= 775 ) ReefAngel.Relay.Off( Box1_Port1 );  ///Turns off Carbon Doser if tank pH <= 7.75.
   if ( ReefAngel.Params.PH <= 775 ) ReefAngel.Relay.Off( Box1_Port6 );  //Turns off Ca Reactor Ca Pump if tank pH <= 7.75.
   if ( ReefAngel.Params.PH <= 775 ) ReefAngel.Relay.Off( Box2_Port8 );  //Turns off Ca Reactor Fill Pump if tank pH <= 7.75.

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

    ReefAngel.Network.Cloud();
    // This should always be the last line
    ReefAngel.ShowTouchInterface();
}

   
// RA_STRING1=U2FsdGVkX1+BrIhUnNJiKHbFL6wohK41+33EQ2nHfFo=
// RA_STRING2=U2FsdGVkX1+EmuJjuPrMWBEHac9zWSjiW8ZytHk/q+M=
// RA_STRING3=Chloe's House-2.4
// RA_LABEL LABEL_ACTINIC=Actinic
// RA_LABEL LABEL_DAYLIGHT=Daylight
// RA_LABEL LABEL_PORT11=Main LEDs
// RA_LABEL LABEL_PORT12=Heater 2
// RA_LABEL LABEL_PORT13=Gyre Pumps
// RA_LABEL LABEL_PORT14=Kalk Stirrer
// RA_LABEL LABEL_PORT15=Salt Mix Tank
// RA_LABEL LABEL_PORT16=Co2 Control
// RA_LABEL LABEL_PORT17=Unused
// RA_LABEL LABEL_PORT18=Unused
// RA_LABEL LABEL_PORT21=Main T5s
// RA_LABEL LABEL_PORT22=Light Fans
// RA_LABEL LABEL_PORT23=Refugium LED
// RA_LABEL LABEL_PORT24=Return Pump
// RA_LABEL LABEL_PORT25=Heater 1
// RA_LABEL LABEL_PORT26=Sump Fans
// RA_LABEL LABEL_PORT27=Skimmer
// RA_LABEL LABEL_PORT28=ATO Pump
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Simple if/then statements not working

Post by rimai »

I don't see nothing wrong.
Are you saying that if you comment these lines, the port remains on?
Roberto.
jcjrogersstar
Posts: 43
Joined: Thu Jan 04, 2018 10:47 pm

Re: Simple if/then statements not working

Post by jcjrogersstar »

Yes, a couple of "//" in front of each one, and they are all on. I even changed one to < only (no =), and they were all still off. I wondered if they needed a > statement as well, but I've never noticed having to do that.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Simple if/then statements not working

Post by rimai »

Are they on the RANet or USB connected relay boxes?
Roberto.
jcjrogersstar
Posts: 43
Joined: Thu Jan 04, 2018 10:47 pm

Re: Simple if/then statements not working

Post by jcjrogersstar »

rimai wrote:Are they on the RANet or USB connected relay boxes?
Both boxes. 2 on an Expansion Box, and 1 on my old original box with a serial cable (looks like a serial cable).
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Simple if/then statements not working

Post by rimai »

Why do you have RANet on your code then?
Roberto.
jcjrogersstar
Posts: 43
Joined: Thu Jan 04, 2018 10:47 pm

Re: Simple if/then statements not working

Post by jcjrogersstar »

rimai wrote:Why do you have RANet on your code then?
Good question. I'm not sure what RA Net is, but my original code was on a RA+ with Cloud wifi. I then migrated to RA* and use the ethernet connection. I do most programming with the Web Wizard and then a little code I've gotten help with. Now, I also run a D/C Expansion module if that might have anything to do with it. My guess is, it was in my original code, and I never messed with it. Do I need to remove?
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Simple if/then statements not working

Post by rimai »

If you are not using it, remove it.
But the issue you are having still is a mystery.
It should work as you posted.
I am not understanding why it is not.
Roberto.
jcjrogersstar
Posts: 43
Joined: Thu Jan 04, 2018 10:47 pm

Re: Simple if/then statements not working

Post by jcjrogersstar »

rimai wrote:If you are not using it, remove it.
But the issue you are having still is a mystery.
It should work as you posted.
I am not understanding why it is not.
I removed it but same thing... all three ports are "auto" off.

Also, this is the code that allows all 3 ports to default to "auto" on.

Code: Select all

#include <ReefAngel_Features.h>
#include <Salinity.h>
#include <Globals.h>
#include <RA_TS.h>
#include <RA_TouchLCD.h>
#include <RA_TFT.h>
#include <RA_TS.h>
#include <Font.h>
#include <RA_Wifi.h>
#include <RA_Wiznet5100.h>
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetDHCP.h>
#include <PubSubClient.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_ATO.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 <RA_CustomLabels.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <Humidity.h>
#include <PAR.h>
#include <DCPump.h>
#include <ReefAngel.h>
#include <SoftwareSerial.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.Star();
    ReefAngel.AddWaterLevelExpansion();  // Water Level Expansion Module
    ReefAngel.AddMultiChannelWaterLevelExpansion();  // Multi-Channel Water Level Expanion Module
    ReefAngel.AddPHExpansion();  // pH Expansion Module
    //ReefAngel.AddRANet();  // RANet Add-On Module (don't know why I had this).
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = 0;
    ReefAngel.FeedingModePortsE[0] = Port7Bit | Port8Bit;  //UV and UV Pump-off.
    ReefAngel.FeedingModePortsE[1] = Port7Bit;  //Skimmer-off.
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = 0;
    ReefAngel.WaterChangePortsE[0] = Port1Bit | Port2Bit | Port3Bit | Port6Bit | Port7Bit | Port8Bit;
    ReefAngel.WaterChangePortsE[1] = Port4Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit;  
    ReefAngel.WaterChangePortsE[2] = Port1Bit | Port2Bit; 
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = 0;
    ReefAngel.OverheatShutoffPortsE[0] = Port1Bit | Port2Bit | Port6Bit | Port7Bit | Port8Bit;
    ReefAngel.OverheatShutoffPortsE[1] = Port1Bit | Port3Bit | Port5Bit | Port7Bit | Port8Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = 0;
    ReefAngel.LightsOnPortsE[1] = Port1Bit;  // Powermodule Fixture On.
    // Use T2 probe as temperature and overheat functions
    ReefAngel.TempProbe = T2_PROBE;
    ReefAngel.OverheatProbe = T2_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_read();  // trying this code to see if it pulls internal memory overheat temp.

    // Ports that are always on
    
    ReefAngel.Relay.On( Box1_Port1 );  // Carbon Doser (CaR CO2 Doser) always on. 
    ReefAngel.Relay.On( Box1_Port3 );  // Gyres always on.
    ReefAngel.Relay.On( Box1_Port6 );  // Calcium Reactor Recirculation Pump (CaR Recirc Pump) always on. 
    ReefAngel.Relay.On( Box1_Port8 );  // UV Pump always on.
    ReefAngel.Relay.On( Box2_Port1 );  // Powermodule Lights/Fans always on.
    ReefAngel.Relay.On( Box2_Port4 );  // Return Pump always on.
    ReefAngel.Relay.On( Box2_Port8 );  // Calcium Reactor Fill Pump (CaR Fill Pump) always on.
    
    ////// Place additional initialization code below here

    InternalMemory.FeedingTimer_write(7200);  // sets feeding mode to 2 hours (only used for coral feeding)... shuts down UV bulb, UV pump, and skimmer.
    ////// Place additional initialization code above here
}

void loop()
{
    ReefAngel.StandardLights( Box2_Port3 ); //Using Internal Memory Standard Lights to run Refugium Light.
    ReefAngel.StandardHeater2( Box1_Port2 );
    ReefAngel.StandardHeater2( Box2_Port5 );
    ReefAngel.StandardFan2( Box2_Port6 );  //Sump Fans
    ReefAngel.Relay.DelayedOn( Box2_Port7 ); //Skimmer
    ReefAngel.WaterLevelATO( 1,Box3_Port1); //ATO pump-DC relay box-new program.    
    //ReefAngel.PWM.DaylightPWMSlope(); - not using PWM for main LEDs
    //ReefAngel.PWM.ActinicPWMSlope(); - not using PWM for main LEDs
    ReefAngel.StandardHeater( Box1_Port7,788,796 ); //Manages UV bulb on/off based on tank temp.  
    ReefAngel.DosingPumpRepeat1( Box3_Port2 );  // Pump dosing kalk-DC Relay Box.
    ReefAngel.DosingPumpRepeat( Box1_Port4,0,60,2700 );  // Stirrer on/off.

   boolean buzzer=false;
   // if ( ReefAngel.isATOTimeOut() ) buzzer=true;
   if ( ReefAngel.isOverheat() ) buzzer=true;
   if ( buzzer ) ReefAngel.BuzzerOn(2); else ReefAngel.BuzzerOff();
   if ( ReefAngel.Params.PH > 844 ) ReefAngel.Relay.Off( Box3_Port2 );   //Turns off Kalk Stirrer dosing if tank pH > 8.44.
   //if ( ReefAngel.Params.PH <= 775 ) ReefAngel.Relay.Off( Box1_Port1 );  //Turns off Carbon Doser if tank pH <= 7.75.
   //if ( ReefAngel.Params.PH <= 775 ) ReefAngel.Relay.Off( Box1_Port6 );  //Turns off Ca Reactor Ca Pump if tank pH <= 7.75.
   //if ( ReefAngel.Params.PH <= 775 ) ReefAngel.Relay.Off( Box2_Port8 );  //Turns off Ca Reactor Fill Pump if tank pH <= 7.75.

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

    ReefAngel.Network.Cloud();
    // This should always be the last line
    ReefAngel.ShowTouchInterface();
}

   
// RA_STRING1=U2FsdGVkX1+BrIhUnNJiKHbFL6wohK41+33EQ2nHfFo=
// RA_STRING2=U2FsdGVkX1+EmuJjuPrMWBEHac9zWSjiW8ZytHk/q+M=
// RA_STRING3=Chloe's House-2.4
// RA_LABEL LABEL_ACTINIC=Actinic
// RA_LABEL LABEL_DAYLIGHT=Daylight
// RA_LABEL LABEL_PORT11=Main LEDs
// RA_LABEL LABEL_PORT12=Heater 2
// RA_LABEL LABEL_PORT13=Gyre Pumps
// RA_LABEL LABEL_PORT14=Kalk Stirrer
// RA_LABEL LABEL_PORT15=Salt Mix Tank
// RA_LABEL LABEL_PORT16=Co2 Control
// RA_LABEL LABEL_PORT17=Unused
// RA_LABEL LABEL_PORT18=Unused
// RA_LABEL LABEL_PORT21=Main T5s
// RA_LABEL LABEL_PORT22=Light Fans
// RA_LABEL LABEL_PORT23=Refugium LED
// RA_LABEL LABEL_PORT24=Return Pump
// RA_LABEL LABEL_PORT25=Heater 1
// RA_LABEL LABEL_PORT26=Sump Fans
// RA_LABEL LABEL_PORT27=Skimmer
// RA_LABEL LABEL_PORT28=ATO Pump
jcjrogersstar
Posts: 43
Joined: Thu Jan 04, 2018 10:47 pm

Re: Simple if/then statements not working

Post by jcjrogersstar »

I used the CO2 control code below, and that appears to work... meaning it recognizes the 'on' value as all three ports default "auto" on with my pH well over 7.85. However, I don't know if they will shut-off at a pH of 7.75

Code: Select all

ReefAngel.CO2Control( Box1_Port1,775,785 );  //Turns off Carbon Doser (CaR CO2 Doser) if tank pH <= 7.75 and back on at 7.85.
    ReefAngel.CO2Control( Box1_Port6,775,785 );  //Turns off Ca Reactor Recirculation Pump (CaR Recirc Pump) if tank pH <= 7.75 and back on at 7.85.
    ReefAngel.CO2Control( Box2_Port8,775,785 );  //Turns off Ca Reactor Fill Pump (CaR Fill Pump) if tank pH <= 7.75 and back on at 7.85. 
Another question. If I were to lose one of 3 connections to my Ca reactor, I would have a nasty flood as the feed pump would keep running. Therefore, I want to add a failsafe based on my sump water level (e.g. ATO water level). I use the Multichanel water level expansion for my ATO (channel 1). Would this be the correct failsafe code?

Code: Select all

if ( ReefAngel.WaterLevel.GetLevel(1) <= 63 ) ReefAngel.Relay.Off( Box1_Port1 );  //Turns off Carbon Doser if sump water level <= 63.
   if ( ReefAngel.WaterLevel.GetLevel(1) <= 63 ) ReefAngel.Relay.Off( Box1_Port6 );  //Turns off Ca Reactor Recirculation Pump if sump water level <= 63.
   if ( ReefAngel.WaterLevel.GetLevel(1) <= 63 ) ReefAngel.Relay.Off( Box2_Port8 );  //Turns off Ca Reactor Fill Pump if sump water level <= 63.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Simple if/then statements not working

Post by rimai »

The code you used looks fine.
Roberto.
jcjrogersstar
Posts: 43
Joined: Thu Jan 04, 2018 10:47 pm

Re: Simple if/then statements not working

Post by jcjrogersstar »

rimai wrote:The code you used looks fine.
Thanks!
Post Reply