Hardware ideas for power outage notification?

I have problems with occasional power outages at my house. Usually it happens during a large storm, but on Sunday morning it went out for no discernable reason (my whoe block lost power). I live at the bottom of a hill, so I have a lot of moisture and rely on two sump pumps to keep the basement dry. While I have battery powered backup pumps, I need to know when the power goes oit so I can get a generator going to power the mains. If the power is out for less than a few hours, The backup sumps are fine though.

I would like to know when my power goes out while I'm away from home, and aso when it comes back on. That way if it comes back on, I won't have to rush home to ensure the pumps keep working.

I have a GPRS/GSM shield and am planning to send myself a text message to let me know when the power goes out, and when it comes back up. I need some help figuring out how to power the arduino though. Ideally, I'd like to have the arduino always running on AC power, but fall back to a battery when the power goes out, without interruption. My thought is to also split the line power before it goes into the Arduino and also send 5v into a pin, which will trigger a message when here is a change from HIGH to LOW, or vice-versa, meaning the power went out, or came back on.

What's a simple way of powering the Arduino in this situation?

Is there a way to have the Arduino always run off the battery, but have the battery simultaneously charging while power is connected?

Yes. I would run the Arduino from a lead-acid battery (they are practically bullet proof) and keep the battery topped up with a trickle charger. Use a 12v battery as 6v is too low for the power input to the Arduino and too high for the Vin pin (which needs 5v). A second-hand car battery might be cheap option.

...R

Love the idea of this project. I have a salt water fish tank at home that needs power all the time. When I have a power failure I have about an hour maybe two tops to get home and hook up the generator before things start going south.

Typically my PC and cable modem, switch etc. are all on a UPS and it'll sms me when power is out but if a tree falls over and takes out the power as well as the cable line I'd get no notifications.

How much does a GPRS/GPS unit cost to run? I imagine a sim card with a cell phone carrier?

Here's what I would do: (see attached schematic)

The AC PSU in this case would be some form of battery charger. Generally, its voltage output would be higher than the full charge voltage of the battery, so by diode-isolating the charger from the battery, you get a tap from the charger that won't be active (from the battery) when the PSU is offline.

To bring the voltage down to something that the microcontroller can cope with, I used a 3.3v Zener diode, along with a cap to ignore nuisance alarms if the power drops for very short times.

The 1k "load" resistor literally represents the load device -- your Arduino project. It's not a literal component.

Here's the Falstad circuit sim file in case you want to play with the sim. (In the sim, there's an additional diode from the 12v source to the load, since the simulator doesn't like voltage sources trying to "charge" other voltage sources. It's not something that should be in the real circuit if the battery is rechargeable.)

$ 1 5.0E-6 10.20027730826997 50 5.0 50
R 240 176 208 176 0 0 40.0 16.0 0.0 0.0 0.5
R 240 256 208 256 0 0 40.0 12.0 0.0 0.0 0.5
s 240 176 304 176 0 0 false
d 240 256 304 256 1 0.805904783
d 304 176 304 256 1 0.805904783
r 304 176 368 176 0 4700.0
z 368 256 368 176 1 0.805904783 3.3
g 368 256 368 272 0
r 304 256 304 336 0 1000.0
g 304 336 304 352 0
c 416 176 416 256 0 1.0E-6 3.259522655061203
w 368 256 416 256 0
w 368 176 416 176 0
O 416 176 464 176 0
O 240 176 240 144 0
O 240 256 240 224 0
O 304 256 336 256 0
x 142 182 186 185 0 12 AC PSU
x 144 261 181 264 0 12 Battery
x 241 302 283 305 0 12 Load ->
x 365 151 422 154 0 12 3.3v Zener
w 384 192 400 160 0
x 488 183 551 186 0 12 POK Signal
o 14 64 0 34 20.0 9.765625E-5 0 -1
o 15 64 0 34 20.0 9.765625E-5 1 -1
o 16 64 0 34 20.0 9.765625E-5 2 -1
o 13 64 0 34 5.0 9.765625E-5 3 -1

acloss.png

Robin2:
Yes. I would run the Arduino from a lead-acid battery (they are practically bullet proof) and keep the battery topped up with a trickle charger. Use a 12v battery as 6v is too low for the power input to the Arduino and too high for the Vin pin (which needs 5v). A second-hand car battery might be cheap option.

...R

Thanks. That's not a bad idea. I thought about using the cheapest UPS battery backup I can find, seeing that most are made for computers, and expect a far larger draw than an Arduino. I would then use a USB wall wart into a pin in the Arduino (from the wall, not the UPS) to detect whether the power is on or off.

I also did more searching after posting this thread and found this shield. It allows you to use a Lithium Polymer battery with the Arduino, and the Arduino will keep it charged while the battery isn't being used. I have my doubts that it would power the Arduino for more than a few hours from even the biggest battery they have (I think 2000mAh), but all I really need is for it to stay on long enough to send out an SMS message that says "The power has gone out". I can have the Arduino send out a "System is powering up" message in the setup so when it comes back on, I'll get my 'power restored' notification.

MalcolmV8:
How much does a GPRS/GPS unit cost to run? I imagine a sim card with a cell phone carrier?

The one I have is the Seeedstudio unit that costs $60. For service, the best deal I can find is a pre-paid SIM from T-Mobile that costs $10 and is good for 3 months. The actual SMS messages are $0.10 each, so you get 100 messages over a 3 month period. I really wish they had low-use, SMS-only options that could get the price down even more, but that's the best I can find. Even if they just made the period last a year, rather than 3 months, it would be more than I'd ever need.

SirNickity:
Here's what I would do: (see attached schematic)

Thanks for your suggestion, but that looks way beyond my abilities. I'm not a total beginner, but I haven't graduated much into more medium to complicated understanding of the programming or the electronics.

Robin2:
I would run the Arduino from a lead-acid battery...

As soon as I posted my reply above and re-read it, an idea hit me: I could tap off of the battery used for one of my backup sump pumps. It's already there, and it's already being kept charged by that system.

I'd still need a way to detect when the main power goes out, but the USB wall wart into an Arduino pin should do it.

You still have to verify the voltage from the USB wall wart is never higher than the Arduino's power supply. Which means you're back to the circuit I posted above, plus you'll need a diode to Vcc to protect the Arduino if its supply is missing or the battery is really low but AC is available (if/when that can happen.) :wink:

So help me understand SirNickity. Let's assume I power the Arduino off my backup sump pump's 12v deep cycle lead acid battery.

I assume a standard 5v power regulator between the battery and the Arduino (I've made a few breadboard Arduinos, I'd assume I wire them the same, but have the power coming from the battery rather than a wall wart). Then the USB wall wart could be regulated down to 3.3 volts.

If I go with the deep cycle battery, I'm unconcerned about the battery ever being low. The sump pump system warns me if the battery needs attention. It's usually something like I need to add water to the cells. As long as I respond to the alerts, the system works.

I am probably missing something. What are your thoughts?

If the wallmart spit out 5.8v for example ...

I know vcc can just about handle a 6v input, wether or not a digitital pin can handle 6v .. no idea.

But, place a diode or 2, to lower the voltage or a voltage divider, or a zener... if you're worried, if digitalRead(wallmartpin) is HIGH we have power, you might wish to use a capacitor to stop any unwanted noise which might give a false reading along with a bleed resistor or it will think power is on when it's not... a 1k resistor would give it 2 - 3 seconds or so to make sure power is really off not just flickred on and off . After the cap bleeds, arduino sees low and you do what you need.

I can draw a circuit....

Canyonero:
I assume a standard 5v power regulator between the battery and the Arduino (I've made a few breadboard Arduinos, I'd assume I wire them the same, but have the power coming from the battery rather than a wall wart). Then the USB wall wart could be regulated down to 3.3 volts.

Yes, you can build your monitor circuit the same way you would with a breadboard Arduino. In theory, since the wall-wart would always* be lower voltage than the 5v regulated from the battery, it would work fine that way.

But, you shouldn't assume that two independent power sources are going to be completely predictable. The most likely case is that you'll make a mistake some time -- maybe during your installation, or during testing, or maintenance -- or something could break and conditions won't be what you expect. It may sound overly cautious, but things like that tend to happen quite frequently, and with a couple additional diodes, you've protected your circuit from that inevitability.

Take a look at this sample schematic. (Sorry, the sim tool is the only thing I have on this computer, so use your imagination a bit.)

... continued ....

diag1.png

OK, now... The 12v source in the diagram is your battery. You're going to use an LM7805 to regulate that down to 5v. In addition, you'll have a wall wart with a 3.3v output (or you can use a 5v wall-wart and regulate down to 3.3v, but why not just use a 3.3v wart instead?) Good so far?

Now, the proper way of doing this would be to hook up the 12v side, let the Arduino come online, and then connect the 3.3v input to whatever input pin (I'm using D13 here.) As long as you do this, and the 12v battery never goes away, you're fine. But, if you ever end up with the battery not being connected -- either +12v or Gnd -- you will potentially destroy at least the input pin, but possibly also the Arduino itself and the LM7805.

The reason why is because the Arduino will attempt to power itself through the input pin if the main power supply is not there. The pin's current limits will likely be exceeded, and things will be damaged.

The diode from the 3.3v wart to the 5v power rail guarantees that if the 5v power supply ever goes away, power will flow through that diode to Vcc, and not backwards through the AVR itself.

Likewise, by placing the "backwards" diode around the LM7805, you ensure the regulator's input is always higher than its output also. That way, if the 3.3v supply is powering the circuit (because the 12v battery is absent), current flows through the left diode and both sides of the LM7805 are roughly equal, making damage to the regulator far less likely.

A couple parts, that costs less than a quarter, and the whole thing is considerably more bullet-proof. One problem we haven't covered yet is this: If the batteries are offline, and power is coming from the wall-wart, there's nothing stopping it from going past the input of the regulator, and upstream to anything that might be there -- like the charger or a critically depleted battery, or a short to ground. Well, the charger should be diode-isolated so no current should flow there. The flat battery would be essentially a short to ground, so make sure the wall-wart is protected against short-circuits or over-current and you're good to go.

Going way back to my previous post... Since you're using an existing battery/charging system: As I said, the charger will almost definitely have a diode in it to make sure power flows out of the charger and into the battery, and never the reverse. This would be helpful to you, because the charger's output terminals will have voltage when the charger is on, but also when it's off, because of the battery. You would need to tap from the charger before its output diode to sample the voltage without reading backflow from the battery.

However... there's a good chance you won't be able to tap the charger before the diode without tearing into its guts -- which is probably not something you want to do. So, using an external power source (like the wall-wart) is probably your next best option. But you should use those two extra diodes to protect the circuit against faults. :blush:

Thanks for that explanation, I think I understand much better.

I was also thinking I could isolate the USB wall wart by having it power a relay. The wart would hold the relay closed, and a loss of power would open the relay. Then it would work as a simple switch, and power would never leak into the Arduino itself. A change in state would cause the Arduino to send an appropriate SMS message.

A relay is more expensive than diodes, but still a cheap way to build this.

  1. Power for the Arduino comes via two diodes...

DC from mains --------->|--------+----------- Regulator-------- Arduino
|
DC from Battery--------->|--------

  1. Signal for Arduino comes via resistive divider to an analog input pin...

DC from mains----------R1------+-------- Arduino Analog input
|
R2
|
Ground

Then a loop.... if the analog input value drops to a low level, Mains supply has failed

You could also have a second analog input monitoring the Batteries.... so you know if the Power failure was long enough to drain them

Also, thinking outside the square.... Does your generator have an electric start ??
Could it be possible for the Arduino to start the generator as the backup batteries get low... ??

AndrewR:
Also, thinking outside the square.... Does your generator have an electric start ??
Could it be possible for the Arduino to start the generator as the backup batteries get low... ??

No, it's a fairly small generator, I think it runs at 5250 watts, peak is 6000. It's enough to run the sumps, two fridges, a freezer, the garage door opener, some lights, and a few other small things. It's normally stored in the tool shed, so I have to dig it out, hook it up, and start it. I'm considering getting one of these to be able to hook it into the house's electrical system, but even with that I'd have to manually flip the switch to change over from mains to generator.

I like the idea though!

I have a few relays laying around, but no diodes, so I've been playing around with it today using a relay, and simulating a power outage by unplugging the relay and letting it open. It works fantastically! I get the text messages I expect. I'll post my code in a while, I want to test a modification or two first.

My only remaining issue is related to the power. I just want to be sure that the UNO will be fine connected directly to a 12v battery via the barrel jack. The specs say it will take 7-12v (recommended) or 6-20v (limits). My battery is at 12.5v today on a voltage meter. Will it be fine?

Here is my code. Again, it uses the Seeedstudio GPRS shield. I have never used the official Arduino shield, and don't know if they are completely compatible, or if the code would need to be modified.

The way it's physically connected to the world is this: There is a relay that is between pin 2 and ground. The other side of the relay is simply connected to the power and ground of a USB cable plugged into the wall with an AC adapter. The relay is active-low, so the control pin is connected to ground. When the power is on, the relay is closed and pin 2 on the Arduino reads HIGH. If the power goes out, the relay trips and opens the circuit, causing pin 2 to read LOW.

/*This sketch will send a text message to 'myCellPhone' when the sketch starts,
when the power goes out, and when the power is restored. It uses a Seeedstudio GPRS shield.
The Arduino is powered off of a battery, and pin2 is connected to a relay that is Normally Open.
The relay is connected to the AC power via a USB adapter that feeds it 5v to power. 

This sketch was created Canyonero and is released to the public domain.
  */
 
 
#include <SoftwareSerial.h>
#include <String.h>
#include <Button.h>        //https://github.com/JChristensen/Button
 
SoftwareSerial mySerial(7, 8);

#define BUTTON_PIN 2       //Connect a relay from Arduino pin 2 to ground using the NC pin
#define PULLUP true        //To keep things simple, we use the Arduino's internal pullup resistor.
#define INVERT true        //Since the pullup resistor will keep the pin high unless the
                           //switch is closed, this is negative logic, i.e. a high state
                           //means the button is NOT pressed. (Assuming a normally open switch.)
#define DEBOUNCE_MS 20     //A debounce time of 20 milliseconds usually works well for tactile button switches.
#define LED_PIN 13         //The standard Arduino "Pin 13" LED

boolean powerOn;
boolean previousPowerState = true;

Button myBtn(BUTTON_PIN, PULLUP, INVERT, DEBOUNCE_MS);    //Declare the button
boolean ledState;          //A variable that keeps the current LED status

char myCellPhone[] = "+13215551234";
 
void setup()
{
  pinMode(LED_PIN, OUTPUT);            //Set the LED pin as an output
  mySerial.begin(19200);               // the GPRS baud rate   
  Serial.begin(19200);                 // the Serial baud rate 
  delay(500);
  powerUpOrDown();                     // Turn on the GPRS Sheild
  delay(6000);
  SendStartUpMessage();                // Send a Text message to indicate the sketch started
}
 
void loop()
{
  
  powerOn = myBtn.read();                    //Read the button
  
  if (powerOn == true) {       //If the button changed state, change the LED state
    digitalWrite(LED_PIN, HIGH);
    if (previousPowerState == false)  {
      previousPowerState = true;
      SendPowerRestoredMessage();
    }
        
        
  }
  else  {
    digitalWrite(LED_PIN, LOW);
    if (previousPowerState == true)  {
      previousPowerState = false;
      SendPowerFailureMessage();
    }
  }
  
  ShowSerialData();
}


void powerUpOrDown()
{
  pinMode(9, OUTPUT); 
  digitalWrite(9,LOW);
  delay(1000);
  digitalWrite(9,HIGH);
  delay(2000);
  digitalWrite(9,LOW);
  delay(3000);
}



void SendStartUpMessage()  {
  mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
  delay(100);
  mySerial.print("AT + CMGS = \"");  //send sms message, be careful need to add a country code before the cellphone number
  mySerial.print(myCellPhone);
  mySerial.println("\"");
  delay(100);
  mySerial.println("The Power Monitor has started up successfully");//the content of the message
  delay(100);
  mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
  mySerial.println();
}

void SendPowerRestoredMessage() {
  mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
  delay(100);
  mySerial.print("AT + CMGS = \"");  //send sms message, be careful need to add a country code before the cellphone number
  mySerial.print(myCellPhone);
  mySerial.println("\"");
  delay(100);
  mySerial.println("The power has been restored");//the content of the message
  delay(100);
  mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
  mySerial.println();
}

void SendPowerFailureMessage() {
  mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
  delay(100);
  mySerial.print("AT + CMGS = \"");  //send sms message, be careful need to add a country code before the cellphone number
  mySerial.print(myCellPhone);
  mySerial.println("\"");
  delay(100);
  mySerial.println("The power has gone out");//the content of the message
  delay(100);
  mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
  mySerial.println();
}

 
void ShowSerialData()
{
  while(mySerial.available()!=0)
    Serial.write(mySerial.read());
}

Now all I need to do is get the Arduino connected to my backup sump pump battery and it will send me a text message whenever the relay loses power (the circuit breaks or the power goes out). It will also send a message when the sketch starts, and when the power is restored. The purpose of the sketch-start message is in case the battery dies for some reason and shuts down the Arduino before the power is restored, it will come back on when power is restored and the startup message will serve essentially the same purpose.

A temporary (knowing me, more like permanent) alternative to using my backup sump battery to power the Arduino is that I have it powered from a UPS. There's a computer connected to it, and it usually doesn't last more than 10-20 minutes without power, but all I really need is for it to stay on long enough to get a text message out. When the power comes back on, I'll get notified because of the "successful startup" message that is also programmed in.

I mention this in case someone might be interested in a similar project, but doesn't have a battery-powered backup sump pump. A lot of people do have UPS Battery backups for their computers.