Introduction: Save Your Home With Arduino

About: Walking into my cluttered dorm room and putting my coat on the 50-year old oscilloscope next to the partly-functional remains of a piano, I push the piles of engineering notes off my desk to bring you the late…

Just recently, there was a cold front that messed with power all over. There was a tornado watch in Canada, even. There were some really cool clouds, then some thunder, then a whole lot of lightning, thunder, and rain. Lots of rain and constant rumbling as the sky opened its stored water and charge. Just after a brown-out knocked out the TV and internet (it tripped a GFCI that I didn't see until the day after) I saw a leak in my basement.

It was no small dribble. It was a veritable deluge. (Click the video below to see the deluge.) That may be a bit of an exaggeration, but there was water coming into the house and unsteady power. I tried patching the leak with hydraulic cement, but it couldn't stop the flow because as the water stopped, it pooled up outside and built up pressure. (Instructable for basement repair pending?)

With a partially blocked flow running into the sump, I needed to know if the power died in the middle of the night because if the sump pump stopped, I'd need to empty it with buckets. The pipe into the sump was dumping a lot of water in addition to the leak. No fun, but better than flooding. Carefully directing the little river through the basement to the sump and jamming a bit more hydraulic cement in the crack, I went upstairs.

With the flow slowly breaking the patch I made, I quickly programmed an Arduino to beep when the power went out. It took like 10 minutes because I had to call my friend for the analogRead values. It's 0 to 1023 for voltages 0 to 5V. I know, I know, I could have found it in the examples, but I was without internet and I was desperate and not thinking clearly. I should probably get outside sometimes …

The Arduino never actually woke me in the middle of the night. The power stayed, but it was a lot of peace of mind.

And then the next day I found that the internet box where the fiber-optic comes in was plugged into a tripped GFCI. Oh, the embarrassment. I promptly got on the internet and made an instructable after checking my webcomics.

I didn't end up running wires down two flights of stairs to trigger an alarm when hypothetical flood water shorts some wires. I wanted to, but I just let the sump pump deal with it because it was late.

(I'm entering this in the Arduino contest because, wow, this was the most useful thing I did with it. Vote for me or whomever you think is cool. So me?)
(Too bad the battery-powered contest just ended. This would be pretty good for that, too.)

Step 1: Materials

1 Arduino (Uno, Mega, Duemillanove, Due (I'm so jealous of you), whatever you have. Even an ATmega or ATtiny because it can save your house.)
1 breadboard
1 wall-brick for around 9V DC and a corresponding jack to connect it to a breadboard.
1 3.3V voltage regulator (Alternative below)
Battery holders for 6-20V. I used 4 AA. 9V works well, too.
1 speaker or buzzer
1 capacitor—pretty big capacitance, preferably. I had a 22µF and it was okay. More on this later.

If you don't have a 3.3V regulator, you can make a voltage divider with 2 resistors. Easy math and everyone has resistors, right? http://en.wikipedia.org/wiki/Voltage_divider

Step 2: The Circuit

Build this circuit with this code on the Arduino:

/*
Power Outage Detector
By Chris Chungbin
*/

int in=0;

void setup()  {
}

void loop()  {
  in = analogRead(A0);
  if (in<400)  {
    while (1)  {
      tone(8, 440);
      delay(500);
      noTone(8);
      delay(500);
    }
  }
}

Things to note:
1) The 3.3V regulator isn't actually connected to the power of the Arduino; the batteries power the Arduino alone.

2) The grounds of everything are connected. That includes the battery negative, the regulator ground, the Arduino ground, and a speaker lead.

3) The capacitor. I can never decide which side of the voltage regulator to put it, but it works here. Note polarity.

4) The batteries are on Vin. This is automatically regulated to 5V in the Arduino, though it may drop if the voltage is under 6 or 7 volts. I'm cutting it close, here.

5) I didn't comment on anything in the code. This is me coding fast to make something fast. It's nice and simple, though.

So here's the idea: The battery-powered Arduino sits there analogRead-ing pin A0. The Arduino is powered solely by the batteries so it can still do things after mains power dies. The wall-brick power gets regulated to 3.3V so it's less than the Arduino's power (to prevent frying pins (which is actually kind of hard to do)). If the regulated power drops below around 2V, it means mains power just died. Bad stuff. Once bad stuff happens, the code jumps into a while (1) loop (FOREVER!) and beeps on the speaker on pin 8, hopefully waking you and saving your house from flooding or whatever happens when the power dies.

Step 3: Implementation

Okay, you've built it and plugged the battery and wall power in (preferably in that order). I recommend using a surge protector to avoid frying things no matter how unlikely that is. It probably doesn't even matter.

If you plugged in the battery power first like you should, the Arduino will keep beeping (even if you plug in the wall power). Once the wall power is in, reset the Arduino and it will stop. Pull the plug and it should beep at you. If not, are your batteries good? The right pins?


An interesting note: while I had this running, there was a really short brown-out/black out. Just a slight flicker. I was in the basement when it happened, but when I got upstairs, one clock lost time. One. The Arduino didn't detect it, but I know why. The stove clock in the kitchen and alarm clock in my room must have rather large power supply capacitors and low current draw. The stove is gas with an electric oven, so the power consumption could be really high, but it wasn't on; just the clock part. The short outage didn't let the capacitor discharge enough to matter. The microwave must have a smaller capacitor on it's control circuit which dropped below the controller's required voltage long enough, maybe because it drew some more current for the capacitor size as well.

Why didn't the Arduino see it? Two things: the wall brick capacitor (probably crazy big), the capacitor on the breadboard (not all that big, actually). The 9V power supply probably wobbled a little bit, and the 3.3V regulated power probably didn't even notice it. It's cool when science works.


The power never died completely, fortunately. Keep this in mind next time you need to watch your power. Vote in the Arduino contest. And keep making.

Arduino Contest

Participated in the
Arduino Contest

Kit Contest

Participated in the
Kit Contest