Introduction: Arduino 8 A.C. Outlet (plug) Timer / Vampire Killer

About: Just getting into the microcontroller craze. I used to do this sort of thing building circuits for 8 bit microprocessors back in the early 80s, so this is kind of like reliving a bit of my childhood. Back then…

A device that is constantly using power, even when not in use is commonly referred to as a "Vampire" device, because it's always sucking power.
Things like Cell Phone chargers, iPod/iPad/iPhone chargers, Laptop power supplies/chargers etc. are the most common examples, although things that use the most are things like printers, LCD monitors and TVs etc. when they go into standby mode.

In most cases, we know how long it takes to charge our phone or iPad, laptop, notebook etc. but it's inconvenient to unplug the charger/power adapter from the outlet or extension cord once it has completed it's task.

Enter the Vampire Killer.

It can eliminate vampire power usage from these devices by virtually unplugging them once they have completed their task.
This will increase the life of the chargers (and possibly your batteries if they are constantly being over-charged), lower your electricity bills, and decrease the worry of a bad laptop battery or charger melting the laptop or burning down the house.

This circuit can handle up to 8 devices, each with it's own timer varying from 1 to 9 hours in 1 hour increments using the supplied code, however you could easily modify this.
You can of course also use less outlets, but the code I wrote is for 8.
You can also set any of the outlets to ALWAYS ON if you wish, or turn them OFF at any time, or modify the remaining time.

It can also do things like turn off that old TV that doesn't have a built in sleep timer, or an old radio or night light, or anything else you only want on for a specific amount of time (as long as it's fairly low current - 2A or less per channel)
Other ideas that have been presented were larger vampires like your LCD monitor(s) or printer(s).

You could pre-code certain outlets to automatically be on when you turn on the power too. So in my case, the printer and monitor outlets would be programmed to come on the second it powers up.

More on that at the end of the instructable...

UPDATE: I thought hard about the concerns that the device consumes power itself.
While we can't do much about what it consumes while it's running (which is barely more than it's power supply draws while idle) - we can do something about it after all the devices are off.
Enter the Vampire Killer Killer!
We simply take output 13, which is pin 19 on the ATmega328p, and use it to turn off a relay that is in series with the AC to the internal 5V power supply.
Sounds great, right? but then how the heck do we turn it back on, because once the ATmega is off, there's no 5V to signal the relay to power back up...
Ok, no problem. We put a 125-250V pushbutton across the relay contacts as well.

When we push the button, it's just like the relay was on, giving power to the circuit.
In the code, the very first thing it does, is turn on it's own power relay.
Problem solved right? Oh ya, but all the outlets are off, and that's going to make the code shut off the relay - because that's what it's supposed to do - if all outlets are off, power down.
So what we do is put the "are all outlets off" check inside the "has a minute passed yet" check routine. This way, when the unit powers up, you have 1 minute to set at least 1 of the outlets on. If at least 1 outlet is on, it won't power down. 1 minute after all the outlets are off, it will shut itself off by cutting the 120V to the 5V charger that runs the circuit.

See step 8 to see the Vampire Killer Killer.

Step 1: The Concept (and Warnings)

I am going to state that this is a "HOW I DID IT" instructable, and not a "How TO do it" due to the nature of the danger of using high voltage circuitry.
Also please note that this device is not meant to power anything beyond a power adapter or charger, although it is capable of up to 2A per outlet at 100 - 240V (50/60 Hz).
Even though each and every output has it's own fuse, there's still high voltage all over the place, and should not be messed with.

Now that I have hopefully legally covered my proverbial butt, lets get on to the instructable.

CLICK EACH OF THE PHOTOS on every step so you can see the notes made on the pictures (if you can't already see them). Many questions may be answered when you can SEE what I am talking about.

I will first start out stating that the box I put this thing in was more out of lack of funds than actual design.
If I had access to a 3D printer, this project would look as awesome as it works! (I'll never be able to afford one though as my income is severely limited because I am caring for my aging mother).
Initially I wanted to have the low voltage circuit and LCD part of the circuit in one box with a 10 pin cable running to the outlet box which would be on the floor. Power for the controller would be sent up from the outlet box. The 10 pin total would be power, ground, and the 8 outlet signals. However, I could only afford one box ($15), so everything went in there.

So let's start with a few things needed to make the circuit.
ATmega328P microcontroller or Arduino
SainSmart 8 Channel 5V Solid State Relay Module Board.OMRON SSR AVR DSP Arduino
AC 125V 15A 2 Pin Terminals US AC Power Socket Outlet 10 Pcs
LCD Module Display LCM 1602 16X2 
Rotary Linear Taper Potentiometer with Shaft Knob (value not critical, almost anything should work, but try to keep it under 10K)
Trim Pot (for LCD Contrast) Again, value not critical.
Push Button Switch  SPST-NO (Normally Open)
Optionally you may wish to get a 10 pin header to program the finished board with an ICSP 
cheap iPod charger 
Resistors (I used a 100 ohm and a 4.7K, but these values are not critical )
Enclosures that fit your finished product.

A few of these are shown here.

Step 2: The Circuit

When designing the circuit, I concentrated on ease of connecting the parts to a bare microcontroller rather than an Arduino board. This will make for easier PCB design if we decide to make a PCB later for this.
The basic circuit is shown here. 

I must of course emphasize that you really should never put 120V circuits on a breadboard!

This is for prototyping purposes only to show what goes where.
I tried to create this circuit in 123D but it didn't have the LCD (that I could find) so since simulations would be impossible, I just created this in Fritzing.
In Fritzing there wasn't one of these 8 SSR modules in the parts, so I basically recreated it here using individual Solid State Relays to show how it's all connected, minus the 2A fuses on each output. You should always fuse circuits like this.

For the actual project, I used the Solid State Relay module from Sainsmart at all times, and never put the circuit (above) onto a breadboard. These modules are cheap on Ebay, costing much less than just the SSRs themselves if you bought them separately.

When dealing with AC (Alternating Current) we don't have a positive and negative like we do with DC circuits, because the positive and negative are constantly switching places.
Instead, we have Neutral, and Live. We will be using polarized outlets and plugs so that we can keep the Live and Neutral correctly connected throughout the construction.

In the mock circuit here,there are 2 screw terminals for the live, and 1 each for the outputs from the solid state relays.
The Live must be connected to one terminal of each of the 8 Solid State Relay connections.
I accomplished this by soldering a thick wire on the Sainsmart board itself (see photo). I also put standoffs on the board to keep the high voltage off the case. PC Motherboard brass standoffs are a nice tight fit in the holes in the board. I actually had to screw them in. 
The Neutral must go directly to the outlets, and the Live goes to the relays.This is because electrical code specifies that when switching an AC circuit, it is the Live line that must be switched, not the Neutral. We know none of this will pass code, but it's a safety thing. There's a reason electrical codes exist after all!

In this circuit, +V always refers to the +5V DC power.

NOTE: I always use a 10 pin ICSP header, not a 6 pin. Note the correlations here if you want to use a 6 pin ICSP
(You can of course program the chip in your Arduinol, and then move it to the completed circuit - or you may want to run it directly from your Arduino, eliminating the need for the ICSP altogether)

1 to 4 (MOSI)
2 to 2 (+V)
3, 4, 6, 8 and 10 to 6 (GND) <-This is why 10 pin is better for longer distances and crosstalk elimination
5 to 5 (RESET)
7 to 3 (SCK)
9 to 1 (MISO)

ATmega328P pins go as follows. see the excel chart to see which pins correspond to which connections on an Arduino board .

1 - 5 on ICSP (RESET)
2 - not connected. reserved for serial communication
3 - not connected. reserved for serial communication
4 - one side of 4.7K pulldown and one side of pushbutton. The other side of button goes to +V, and the other end of the pulldown resistor (as the name suggests) goes to ground. This keeps the pin at logic 0 unless the button is pressed, changing it to a logic 1.
5 - LCD pin 4  RS
6 - LCD pin 6 ENABLE
7 - +V
8 - GND
9 - Crystal and 22pF cap. Other side of 22pF cap to ground
10  - Crystal and 22pF cap. Other side of 22pF cap to ground
11 - LCD pin 11 D4
12 - LCD pin 12 D5
13 - LCD pin 13 D6
14 - LCD pin 14 D7
15 - 18 - outputs 1-4 to solid state relay inputs 1-4
17 also to ICSP pin 1 (MOSI)
18 also to ICSP pin 9 (MISO)
19 to ICSP pin 7 (SCK)
20 to +V
21 -
22 to GND
23 to wiper of linear pot
25-28 - outputs 5-8 to solid state relay inputs 5-8

LCD pinouts (not listed above)
1 - GND
2 - +V
3 - wiper of trim pot for contrast
15 - +V (backlight)
16 - 100 ohm resistor - other side of resistor to GND (current limiter for backlight)

potentiometer (pot.) outer contacts go one each to +V and GND

Solid State relay board +V and GND terminals go to +V and GND

ADDENDUM: This does not include the cutoff circuit since that was an after-thought.
I'll add that later as another step at the end.

Step 3: The Firmware (Source Code)

I wanted to make the device so easy to program that even my mother could do it.
Taking a cue from Steve Jobs' "I hate buttons" attitude, I came up with the following programming method.

Press the button. It asks you which outlet to program.
Dial the pot to the outlet you want to program from 1 to 8.
(all the way down is the "OOPS" position, and does not display an outlet number - if you didn't mean to program one, put the pot to this position, and press the button twice)
Press the button to confirm the outlet. It now asks for a duration. 
Durations range from 1 to 9 hours in 1 hour increments, or all the way down is OFF, and all the way up is (ALWAYS) ON
Press the button. That outlet is now programmed.

Since we're programming charging durations etc. I didn't feel the need for anything more accurate than just hours.
If you know your phone takes 1 hour and 20 minutes to charge - just set it for 2 hours. No biggie.
If you need something more precise, you can alter the code.

If the 2 second timer and 1 minute timer comparison / calculations look a little strange, it's because they take into account the 50 day rollover of the millis() function. If that's gobbledegook to you, don't worry about it. Since the timer that the millis() function is tied to can only count to a finite number before it "rolls over" back to 0, we have to account in our timer calculations for the eventuality of that rollover happening during run time. The timer rolls over once about every 50 days. This device was initially meant to always be on, so the calculations had to account for that. Now that the device shuts itself off after the completion of a timer run, it's much less of an issue (if it's an issue at all). The only way it could be an issue now would be if you keep setting new timers while others are still running, and do it so often, that there is never a time that all outlets are all off.

You'll notice a lot of commented out code. This is code that I had put in while debugging the code. I just never bothered to remove it in case someone else could benefit from it down the road if they wanted to modify the code.

Step 4: Prototype and Test Your Circuit

Assemble your circuit, upload the code, and give it a test.
It should cycle through the outlets from 1 to 8 stating their current state (OFF until programmed)
(if you added the Vampire Killer Killer, it should turn on the power relay first)

Programming the outlets is EXTREMELY  complex, so print out these instructions! (LOL!)

Press the button
dial the outlet number
press the button
dial the number of hours to set that outlet for (or OFF or (always) ON)
press the button

The outlet you programmed will now be on til the timer runs out (unless you chose OFF, in which case it will turn off if it was on, or it will remain off)

Repeat as necessary for remaining outlets.

I hope you didn't run out of paper or ink printing out the above instructions!

After programming an outlet, the unit will go back to cycling through the outlet numbers, stating their current time remaining or "Always on" or "off" state.

If you hit the button and didn't actually want to program an outlet, simply turn the dial down until there is no number beside the outlet number, and hit the button twice.

Step 5: Encase the Outlets

Figure out where you are going to put your outlets in the case.
I decided to put all 8 on the back of the box.
I don't have many of the boxy type adapters that need the plug to be horizontal, so I only arranged a couple that way.
I intend to make short cords for each of the outlets anyway.

My original idea was to put the SSRs in a box of it's own with the 5V supply as well, and have an octoplug cluster coming out of it, and it would (send power to and) get it's signals from the controller which would have a separate case.

I was also going to put an LED that would be visible for each outlet as well by just moving the ones off the SSR board.
This case is so darn thick though, I decided not to.

When inserting the outlets, make sure that the neutral is always on the same side.
All the neutral lines need to be soldered together.
Then put one wire on each of the outputs.
I used the same wire from the extension cord I cut up to make this, and left them in pairs for neatness.
Each pair is actually 2 outputs.

Neutral is the wider slot on the outlets by the way.

Once you have the SSR live output terminals connected to the 8 outlets (remember to connect only the outputs that aren't tied to each other on the SSR board) and the controller board, it's time to get power to everything.
Take the extension cord that you have cut the outlet end off of, and connect the neutral to the common neutral line on the 8 outlets. Remember to connect an additional thin wire anywhere on the common neutral line, which will go to the disembodied iPod charger circuit that provides the 5V for our circuit.
Connect the other wire (live) to any 1 of the common live screw terminals (there's one beside each of the 8 live outputs) of the SSR board - remember to also attach an additional thin wire (to any of the remaining common live terminals) to run power to the flattened out 5V iPod charger circuit.

Step 6: Powering the Standalone Circuit

If you give most of the cheap iPod chargers a good whack on the plug part, it'll open right up. 
You'll see 2 small boards folded over each other connected by a small cable.
Flatten out the circuit if you like. I liked, so I did.
Unsolder the wires from the plug to the board.
I soldered wires to the bottom of where the cable is just to keep the board flat.
Then I flipped it over, and hot glued it to my controller for lack of a better place to put it.
If you are going to use seperate controller and outlet boxes, you'll have to find a place in the outlet box for it.
Connect the 120V to the board using the small wires you attached to the live of the SSR module and neutral of the power outlets.

There will be a capacitor across the 5V and GND of the USB connector on the board.
This will help you identify which is GND and which is 5V by looking at the electrolytic capacitor markings. Negative is always clearly marked. The +5V by process of elimination is the other lead of the electrolytic capacitor.
I soldered my low voltage power lines directly to the solder pads of the capacitor itself, and ran it to the +V and GND lines of my circuit on the perfboard.

Step 7: The Finished Product

My finished Vampire Killer.
It's big.
It's ugly.
It works.
And even my octogenarian mom can program it!

I may later add some form of remote programming etc. but I wanted to keep this as simple as possible for now.

I can now have my iPod and my iPad and various laptops plugged in all the time, and just activate their chargers for as long as they are needed.
I haven't even calculated what this will save me in electricity charges in a year. I have a lot of vampires for various notebooks and iCrap of all sorts. I may put the printer and monitors on it too.

Those that REALLY want to save power could include a Power switch (Now taken care of when all timers are finished by the Vampite Killer Killer circuit) , so when everything is off, you just turn off the box too. It also makes for a quick "All Off" function. You could pre-code certain outlets to automatically be on when you turn on the power too. So in my case, the printer and monitor outlets would be programmed to come on the second it powers up. Doing so would look like this if lets say I wanted outlets 1, 5 and 7 to come on, and stay on when the device initializes...
int outletMins [9] = {0,600,0,0,0,600,0,600,0};
use that to replace the original int outletMins [9];
600 indicates 600 minutes or 10 hours. The code uses 10 hours as it's "always on" indicator, and it does not ever decrease any timer set to that.
NOTE: the first timer is a phantom outlet that doesn't exist (Outlet 0). This is the one we set if we accidentally hit the button, but didn't want to change anything. When choosing an outlet, if you decrease the knob from outlet 1, the display goes to "choose outlet" with no number.
So outlet 1 is the first one we set to 600 (always on) in the line above. You can also automatically set any outlet to an actual time. So lets say when you boot up your system , it automatically does a backup to an external hard disk, and it takes about 2 hours. You can have the external hard disk plugged into outlet 6, and initialize outlet 6 for 180 minutes (3 hours). So after the backup is complete, it shuts off the external hard disk.
And now that I have thought about all this, I think I will implement this into my box.

The photos were taken before I put in the Vampire Killer Killer circuit. It looks the same, except there is 1 more button in the box.

Let me know what you are going to do with yours - I am sure everyone would love to hear your ideas on how to make use of this device!

Step 8: ADDENDUM: the Vampire Killer Killer

Further power savings are now realized as the unit shuts itself off once all the outlets are off.
Don't worry, if you turn off the last live output while programming it, you still have 1 minute to turn at least one outlet on to keep the device alive.
It shuts off 1 minute after all the outlets are off.
This is so that when you first power the device up, you don't have to hold the power button til you program it (LOL- ya, I thought of that ahead of time, it wasn't learned by mistake).

This circuit by itself would make a great project on it's own as a self shutoff circuit that could be added to almost any circuit.

You can use another Solid State relay for this. The schematic app I used simply didn't have a symbol for an SSR.
They do the same thing anyways (basically), so it doesn't matter. Personally I hate clicky relays.

In fact, if you wanted to modify the code, you could just have one less outlet, and use one of the 8 existing SSRs to power and turn off the device. I decided I didn't want to over-complicate the instructable, and just added an SSR specifically for the Vampire Killer Killer.

So, as it's final act, being a vampire itself, the last Vampire it kills, is itself.

123D Circuits Contest

Participated in the
123D Circuits Contest

Full Spectrum Laser Contest

Participated in the
Full Spectrum Laser Contest