Power outage alert

User avatar
jsclownfish
Posts: 378
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Power outage alert

Post by jsclownfish »

Sorry I haven't had a chance to follow-up on this for awhile, but I have time this week to try it all out. :)

For review, I'm trying to hook the lowATO port to a 5V wall wart to detect a power failure. The main lines are connected to a battery back-up. The plan is to shut-off everything but a powerhead while the power is out and to return back to normal when main power returns.

When I tried a couple versions of this code, I always get an intermittent response to the power from the 5V wall wart being unplugged and or it cycles on and off. Also, something is not right on the masking as the port will cycle with the status change, but the others that are on stay on.

Any ideas? Do I need a resistor to pull up/down the signal? :?

Here is my abbreviated code....

Code: Select all

/* Main ReefAngelPlus controller with communication for sound,
 auxillary monitor, I/O expansion, and extra relaybox, send master time,
 flow, buzzer, overflow and reservoir alarms on the I/O
 
 The following features are enabled for this File: 
 #define DisplayImages
 #define SetupExtras 
 #define DateTimeSetup
 #define VersionMenu
 #define DisplayLEDPWM
 #define wifi
 #define RelayExp
 #define WDT
 #define CUSTOM_MENU
 #define CUSTOM_MENU_ENTRIES 9
 #define CUSTOM_MAIN
 #define COLORS_PDE
 #define FONT_8x8
 #define NUMBERS_8x8
 #define CUSTOM_VARIABLES
 */


#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>
#include <IO.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <avr/pgmspace.h>

//Power outage settings
byte BatteryPower1;  //first outlet box
byte BatteryPower2;  //second outlet box
static boolean fSave = true;   //status of highATOPin

//Custom Main Display
void DrawCustomGraph()
{
}
void DrawCustomMain()
{
  if ( ! digitalRead(lowATOPin) )
    {
    ReefAngel.LCD.Clear(255,1,92,102,102);
    ReefAngel.LCD.DrawText(COLOR_GREEN, DefaultBGColor,1,92,"Main Power ON");
    }
    else
    {
    ReefAngel.LCD.Clear(255,1,92,102,102);
    ReefAngel.LCD.DrawText(COLOR_RED, DefaultBGColor,1,92,"BACKUP Power ON");
    }
  if (ReefAngel.LowATO.IsActive())
  {
    lowATOPin == 0;
    FillCircle(100,96,5,COLOR_RED);
    ReefAngel.LCD.DrawText(COLOR_WHITE,COLOR_RED,98,92,"P");
  }
  else
  {
    lowATOPin == 1;
    FillCircle(100,96,5,COLOR_GREEN);
    ReefAngel.LCD.DrawText(COLOR_WHITE,COLOR_GREEN,98,92,"P");
  }
  pingSerial();
  byte TempRelay = ReefAngel.Relay.RelayData;
  TempRelay &= ReefAngel.Relay.RelayMaskOff;
  TempRelay |= ReefAngel.Relay.RelayMaskOn;
  ReefAngel.LCD.DrawOutletBox(12, 110, TempRelay);
  // draw 1st expansion relay
  TempRelay = ReefAngel.Relay.RelayDataE[0];
  TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
  TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
  ReefAngel.LCD.DrawOutletBox(12, 120, TempRelay);
}
//************************************************************************************
void setup()
{
  //...(other stuff)
  //Status of the outlets if power is triggered (only 1 powerhead stays on, all other outlets off)
  BatteryPower1 = Port3Bit;
  BatteryPower2 = 0;
  digitalWrite(lowATOPin,LOW);
}
//************************************************************************************
void loop()
{
  // Specific functions
  //1st Heater at 78.8, 2nd Heater at 77.0, MH on at 10AM off at 8PM, Actinics on at 9AM off at 9PM, Fan kicks on at 82.0
  ReefAngel.StandardHeater(Port1,788,792);
  ReefAngel.StandardHeater(Port2,770,792);
  ReefAngel.MHLights(Port3,10,0,20,0,5);
  ReefAngel.StandardLights(Port4,9,0,21,0);
  ReefAngel.StandardFan(Port8,792,820);
  ReefAngel.DosingPumpRepeat(Box1_Port7,0,60,4); // Dose for 4 seconds every 60 minutes with 0 minutes offset
  ReefAngel.DosingPumpRepeat(Box1_Port8,5,60,4); // Dose for 4 seconds every 60 minutes with 5 minutes offset
  //Logic for a poweroutage and return to normal
  if (digitalRead(lowATOPin))
  {
    // only execute once during power outage
    if ( fSave )
    {
      // Force on the ports you want, turn them on if they are
      // not already on
      ReefAngel.Relay.RelayMaskOn = BatteryPower1;
      ReefAngel.Relay.RelayMaskOnE[0] = BatteryPower2;
      ReefAngel.Relay.RelayMaskOff = ~BatteryPower1;
      ReefAngel.Relay.RelayMaskOffE[0] = ~BatteryPower2;
//      ReefAngel.Relay.Write();
      fSave = false;
    }
  } 
  else 
  {
    // only execute once after power returns
    if ( ! fSave )
    {
      // return everything back to where it should be in normal operation
      ReefAngel.Relay.RelayMaskOn = 0;
      ReefAngel.Relay.RelayMaskOnE[0] = 0;
      ReefAngel.Relay.RelayMaskOff = 0xff;
      ReefAngel.Relay.RelayMaskOffE[0] = 0xff;
//      ReefAngel.Relay.Write();
      fSave = true;
    }
  }
//...other stuff
  ReefAngel.Portal("jsclownfish");
  ReefAngel.ShowInterface();
}
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Power outage alert

Post by rimai »

Since you have a relay expansion box, you could use this solution:
http://forum.reefangel.com/viewtopic.php?f=2&t=1239
Roberto.
User avatar
mvwise
Posts: 48
Joined: Sat Apr 21, 2012 7:44 pm
Location: Burlington, Ontario, Canada

Re: Power outage alert

Post by mvwise »

Would a similar situation exist for the PWM expansion module? The module is powered by a 12v power supply - is there any way to determine if power is being supplies to this module or not?
Image
User avatar
jsclownfish
Posts: 378
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Power outage alert

Post by jsclownfish »

Thanks, I'll take a look. That would free up my low ATO port again as well. :)

I'm still a bit confused as to the signalling from the wall wart however. Even if I disconnect the wall wart and simply touch the two wires from the port lead wires, I can get the signal to change a bit, there must be something else going on. Maybe I should try the highATO port?

-Jon
User avatar
jsclownfish
Posts: 378
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Power outage alert

Post by jsclownfish »

mvwise,
I originally planned to use this on the IO module (similar to the PWM module) but it would have the same downside that any interuption of the signal through connections and the I2C would look like a power outage, so I tried to move it to the main lowATO pin.
-Jon
User avatar
jsclownfish
Posts: 378
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Power outage alert

Post by jsclownfish »

The extension relay and the I2C scanner seems to work great. Thanks Don and Roberto for the idea and code. I did have one issue however with the Back-UPS. I tripped the circuit breaker on the box and when that happened everything went out so I didn't get any back-up or notice change. It says the outlet box has an 8A capacity. Maybe I need to move some things like the MH lamps or Chiller to another circuit? I could move the MH lamps to the extension relay and power that from another circuit. Your thoughts?

-Jon
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Power outage alert

Post by rimai »

Well, if you kill power to the controller, there is nothing that can be done.
Was it intentional trip or too much power for the breaker?
I think you should do what you said. Move the heavy lifting equipment out of the main box.
Roberto.
User avatar
jsclownfish
Posts: 378
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Power outage alert

Post by jsclownfish »

yep, I didn't realize the amps that the system pulls now. I had a outlet strip with a 12A breaker on it and it was fine, but the BackUPS is only an 8A breaker. I looked up the chiller and it pulls 6A on it's own, so I moved it to another outlet on a separate panel breaker. Hopefully that will fix the issue.

Thanks,
Jon
Post Reply