Page 1 of 1

Relay always turning off?

Posted: Wed Jul 04, 2012 8:51 am
by dmglakewood
I'm not sure if this is the right place to put this or not but I'm having some weird issues.

1. For some reason my relay port 2 always turns itself off. It doesn't do it right away it seems to be a random time but after a day or 2 I will look at my controls and port 2 will be manually turned off. Easy enough just turn it back on right? Well when I turn it back on it instantly turns it back off. Nothing in my code even touches port 2.

2. Randomly things just wont listen to me. I connect to my reef angel via my android and I will manually turn off the return and it appears to send the signal over but it doesn't actually turn the pump off. When it starts doing this I have to unplug the whole system for like 3 seconds and plug it back in. Then everything starts to listen to commands again.

Does anyone have any ideas on these two issues? They are driving me crazy :shock:

Here is my code. I've gone through it countless times and I can't find any issues with it. =/

Code: Select all

#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>

void setup(){
    ReefAngel.Init();

    ReefAngel.FeedingModePorts = Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port6Bit;
    ReefAngel.WaterChangePorts = Port3Bit | Port4Bit | Port8Bit;

    //Always on
    ReefAngel.Relay.On(Port2);
    ReefAngel.Relay.On(Port3);
    ReefAngel.Relay.On(Port7); //Sump Light
    ReefAngel.Relay.On(Port8); //Sump Powerhead
    
    //Set timer for powerhead 1
    ReefAngel.Timer[1].SetInterval(random(15,60));
    ReefAngel.Timer[1].Start();
    ReefAngel.Relay.On(Port5);
    
    //Set timer for powerhead 2
    ReefAngel.Timer[2].SetInterval(random(5,10));
    ReefAngel.Timer[2].Start();
} 

void loop(){
    ReefAngel.Portal("dmglakewood");
    ReefAngel.ShowInterface();
    
    //Random powerhead turn on
    if(ReefAngel.Timer[1].IsTriggered()){
      ReefAngel.Timer[1].SetInterval(random(15,60));
      ReefAngel.Timer[1].Start();
      ReefAngel.Relay.Toggle(Port5);
    }
    
    //Power head 2 random short time
    if(ReefAngel.Timer[2].IsTriggered()){
      ReefAngel.Timer[2].SetInterval(random(5,10));
      ReefAngel.Timer[2].Start();
      ReefAngel.Relay.Toggle(Port6);
    }
        
    //Heater on when temp lower then 80.0F
    if(ReefAngel.Params.Temp[T1_PROBE] < 790 && ReefAngel.Params.Temp[T1_PROBE] > 0){
      ReefAngel.Relay.On(Port1);
    } else if(ReefAngel.Params.Temp[T1_PROBE] >= 800){
      ReefAngel.Relay.Off(Port1);
    }
    
    //Turn sump light on at 9am and turn off at 9pm
    if(hour() >= 9 && hour() < 21){
      ReefAngel.Relay.On(Port7);
    } else {
      ReefAngel.Relay.Off(Port7);
    }
           
    //ATO Sump too low
    if(!ReefAngel.LowATO.IsActive() && ReefAngel.HighATO.IsActive()){
      //Water in sump too low, let's pump some in
      ReefAngel.Relay.On(Port4);  
    }
    
    //ATO Sump good level
    if(ReefAngel.LowATO.IsActive() || !ReefAngel.HighATO.IsActive()){
      //Water in sump too low, let's pump some in
      ReefAngel.Relay.Off(Port4);  
    }
}


Re: Relay always turning off?

Posted: Wed Jul 04, 2012 9:01 am
by rimai
I bet that when this happens, you have status red led turned on too, right?
I think it is the default overheat ports.
I thought of removing them and I have seen a couple cases where it just created more confusion than benefit, but left them alone. I may revisit this for the next libraries update.
Use this:

Code: Select all

  ReefAngel.OverheatShutoffPorts = 0;

Re: Relay always turning off?

Posted: Wed Jul 04, 2012 9:06 am
by binder
I've got a couple comments / suggestions:

1. You need to move the Portal() and ShowInterface functions to be the last lines inside your loop(). This will ensure all of your logic gets processed correctly.

Code: Select all

void loop()
{
   // other stuff
    ReefAngel.Portal("dmglakewood");
    ReefAngel.ShowInterface();
}
2. To simplify things, you should use StandardHeater instead of this:

Code: Select all

    //Heater on when temp lower then 80.0F
    if(ReefAngel.Params.Temp[T1_PROBE] < 790 && ReefAngel.Params.Temp[T1_PROBE] > 0){
      ReefAngel.Relay.On(Port1);
    } else if(ReefAngel.Params.Temp[T1_PROBE] >= 800){
      ReefAngel.Relay.Off(Port1);
    }
StandardHeater does exactly this code plus it has an additional check if the value is 0.
So you can use this:

Code: Select all

ReefAngel.StandardHeater(Port1, 790, 800);
3. The same goes with this. This function can be simplified:

Code: Select all

    //Turn sump light on at 9am and turn off at 9pm
    if(hour() >= 9 && hour() < 21){
      ReefAngel.Relay.On(Port7);
    } else {
      ReefAngel.Relay.Off(Port7);
    }
You can use the standard lights function and have it be like this:

Code: Select all

ReefAngel.StandardLights(Port7, 9, 0, 21, 0);
It will simplify the coding inside your loop() function and make use of already pre-defined functions. I know the name is confusing, but it's simply a timed port.

4. You may want to remove this line from setup. This will always turn your light / port on when the controller starts up and then the logic will override it. There's no reason to turn it on at the beginning. Just let the loop() logic control it:

Code: Select all

ReefAngel.Relay.On(Port7); //Sump Light
Give those changes a try and see if you notice a difference. I think you will and it's most likely coming from the placement of your ShowInterface and Portal functions.

Re: Relay always turning off?

Posted: Wed Jul 04, 2012 12:38 pm
by dmglakewood
Okay I went ahead and made both of your changes. I will post back in a couple of days and let you guys know the status.

Re: Relay always turning off?

Posted: Mon Jul 09, 2012 7:09 pm
by dmglakewood
Everything seems to be good with my initial issue now I seem to be having the opposite issue though.

When I turn off the relay using my phone it instantly turns it back on. Do you guys know why this would be happening?

Re: Relay always turning off?

Posted: Mon Jul 09, 2012 7:18 pm
by rimai
Humm, that shouldn't happen.
Can you try power cycling the controller and see it it still continues?

Re: Relay always turning off?

Posted: Tue Jul 10, 2012 4:31 pm
by dmglakewood
After powering it off and back on it's still doing the same thing.

Re: Relay always turning off?

Posted: Tue Jul 10, 2012 4:44 pm
by rimai
Can I see the latest code?

Re: Relay always turning off?

Posted: Tue Jul 10, 2012 5:00 pm
by dmglakewood
rimai wrote:Can I see the latest code?
Sure

Code: Select all

#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>

void setup(){
    ReefAngel.Init();

    ReefAngel.FeedingModePorts = Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port6Bit;
    ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port8Bit;
    ReefAngel.OverheatShutoffPorts = 0;
    
    /*Ports
    1 - Heater
    2 - Return
    3 - Skimmer
    4 - ATO
    5 - Powerhead
    6 - Powerhead
    7 - Sump light
    8 - Sump powerhead
    */
    
    //Always on
    ReefAngel.Relay.On(Port2); //Return
    ReefAngel.Relay.On(Port3); //Skimmer
    ReefAngel.Relay.On(Port5); //Powerhead
    ReefAngel.Relay.On(Port6); //Powerhead
    ReefAngel.Relay.On(Port8); //Sump Powerhead
    
    //Set timer for powerhead 1
    ReefAngel.Timer[1].SetInterval(5);
    ReefAngel.Timer[1].Start();
    
    //Set timer for powerhead 2
    ReefAngel.Timer[2].SetInterval(5);
    ReefAngel.Timer[2].Start();
} 

void loop(){
  
    //Turn off power head for 5 seconds
    if(ReefAngel.Timer[1].IsTriggered()){
      ReefAngel.Timer[1].SetInterval(5);
      ReefAngel.Timer[1].Start();
      ReefAngel.Relay.Toggle(Port5);
    }  
    
    //Power head 2 random short time
    if(ReefAngel.Timer[2].IsTriggered()){
      if(!ReefAngel.Relay.Status(Port6)){
        //If powerhead is off turn it on for 15 seconds
         ReefAngel.Timer[2].SetInterval(15);
      } else {
        //Turn off power head for 5 seconds
         ReefAngel.Timer[2].SetInterval(5); 
      }
      ReefAngel.Timer[2].Start();
      ReefAngel.Relay.Toggle(Port6);
    }
        
    //Heater on when temp lower then 80.0F
    ReefAngel.StandardHeater(Port1, 790, 800);
    
    //Turn off sump powerheads if temp over 80.5F
    if(ReefAngel.Params.Temp[T1_PROBE] > 805 && ReefAngel.Params.Temp[T1_PROBE] > 0){
      ReefAngel.Relay.Off(Port8);
    } else {
      ReefAngel.Relay.On(Port8);
    }
    
    //Turn sump light on at 9am and turn off at 9pm
    ReefAngel.StandardLights(Port7, 9, 0, 21, 0);
            
    //ATO Sump too low
    if(!ReefAngel.LowATO.IsActive() && ReefAngel.HighATO.IsActive()){
      //Water in sump too low, let's pump some in
      ReefAngel.Relay.On(Port4);
    }
    
    //ATO Sump good level
    if(ReefAngel.LowATO.IsActive() || !ReefAngel.HighATO.IsActive()){
      //Water in sump too low, let's pump some in
      ReefAngel.Relay.Off(Port4);  
    }
  
    //Send info to portal
    ReefAngel.Portal("dmglakewood");
    ReefAngel.ShowInterface();    

}

Re: Relay always turning off?

Posted: Wed Jul 11, 2012 10:20 am
by rimai
Everything looks good.
What port is that you are trying to turn off??

Re: Relay always turning off?

Posted: Thu Jul 12, 2012 6:58 pm
by dmglakewood
I was trying to turn off port 2 but I tried all of them and they all did the same thing. =/

Re: Relay always turning off?

Posted: Thu Jul 12, 2012 7:31 pm
by rimai
Does it do the same thing if you try it on the portal?
What version of libraries are you using?