Instructables
Picture of Web Controlled 8-Channel Powerstrip
Greetings, fellow Raspberry Pi enthusiasts.  We are about to create a multi-purpose gadget that is sure to impress!  My primary reason for building this to to control my Christmas lights, but that is only one of many possible uses.  Basically you can plug in up to 8 appliance and turn them on and off independantly from your smart phone!  If you want to setup port-forwarding on your wireless router, you can control your appliances from anywhere in the world.  (Although why you would want to turn on your blender from over-seas is a bit of a mystery.) Please leave me a comment letting me know how you use your Web Controlled Powerstrip!

Before we get started, I want to give credit where credit is due: TheFreeElectron wrote an excellent instructable on controlling the Raspberry Pi GPIO pins from a web-browser. In fact, in-order to complete this instructable, you will need to follow almost all of the steps from his instructable including using his awesome web application for controlling your power-strip.

Secondly a reminder that working with mains power can be extremely dangerous. Please be very careful. Those of us that have had the experience of touching a live 120 volt wire do not EVER want to repeat the experience.

Assuming you already have your raspberry pi with the adapter and SD card, you should be able to round up the rest of the ingredients with $40-$50 dollars.

Here's what you're gonna need for this project:
  • Raspberry Pi with SD Card
  • Micro USB Power supply (Make sure your power supply can supply a full 1 amp)
  • Project Box - Available at you local Target ($14.99) - Hurry these are seasonal!
  • 8-Channel 5V Relay board - EBay (About $10 shipped, I found mine here.)
  • 4 (qty) 15-Amp Power Receptacles (Lowe's or Home-Depot, get the cheap ones about 80 cents each)
  • 18AWG Solid Hookup Wire (3 colors) - Radio Shack (About $8.50)
  • Short length of 14-Gauge wire. (Only need about 15 inches of white, I found some scrap)
  • Large wire-nuts (Red or bigger)
  • Colored jumper wires - Female to Female buy them on EBay here.
  • Power cord (I used an old computer power cord)
  • Scrap wood pieces
  • Double Stik tape
  • 1/4" wood screws
  • Optional (but handy):  A female end of an extension cord or broken holiday-light set.

Tools
 

  • Trim or plunge-type router with 1/8" straight cutting bit.
  • Wire strippers
  • Drill & drill bits (various sizes)
  • Screwdrivers (various sizes)
  • Multi-meter (for testing circuitry)
  • Utility knife


 
Remove these adsRemove these ads by Signing Up

Step 1: A Faceplate to be Proud of

Picture of A Faceplate to be Proud of
135.JPG
137.JPG
148.JPG
We'll start by modifying our project box to expose the face of our power receptacles. Take your time on this step, you want it to look nice since you're going to be impressing all of your friends with it.

We will use a spare wall plate as your template to draw the shapes you will be cutting out with the router.

Start by using a ruler and straight edge to draw a straight line centered across the long side.
Next locate the exact center of that line and make a center-mark.
Now lay your ruler along the line with the center-mark at the 10 cm point on your ruler. Carefully create a mark on the center line at positions 4, 8, 12, and 16 cm. We should end up with four center-points spaced 4 cm apart and centered along the line. These center-points will line up with the screw-hole of the wall plate and allow you to trace each of the large face-plate openings as shown. I also recommend drawing another reference line across the top or bottom to help make sure the wall-plate is parallel with the box edges when you trace the face holes.

Next use your router to carefully rout-out each of the 8 shapes to allow the receptacles to slide into place from the back. It may take a few tries to get them to fit nicely through the holes, but you'll get it.

Tips: Routing MDF is messy with lots of fine dust. You may want to have someone blowing compressed air on the lid while you're routing to keep the dust from obscuring the lines. Keep one of your receptacles near by so you can continue to check the fit and shave off the edges that are preventing the fit. Once all of the holes are cut and fit, clean up the whole mess with a damp cloth.


Step 2: Preparing the receptacles

Picture of Preparing the receptacles
140.JPG
Remove the long mounting screws from the ends of each of the receptacles.

Take a careful look at the receptacles. You'll notice that on one side you have two silver screws for the common (white) wire and on the other side you have two gold screws for the hot (black) wires. We will be removing ONLY the tab on the gold (hot) side. Do NOT remove the tabs on the silver side.

Using a pair of needle-nose pliers carefully remove the tabs on the gold side of each of the 4 receptacles. You'll need to grasp them securely and bend them back and forth until they break off. This step allows the top and bottom to operate independently. (you will be able to turn on one without turning on the other, thus we get 8 total channels rather than 4.)

Step 3: Wiring the receptacles

Picture of Wiring the receptacles
143.JPG
144.JPG
145.JPG
Now we will do a little wiring.

  1. Cut off 8 pieces of the black 18AWG wire about 15 to 20 cm long.
  2. Strip about 2 cm of the insulation from one end and bend into a hook as shown. Repeat for all 8 pieces.
  3. Hook one around each of the gold screws on the sides (clockwise) and firmly tighten down the screws to make the electrical connection and to secure them in place.
  4. Place each of the receptacles into place from the back of the box lid. Make sure they are all facing the same direction. (Notice in the 4th picture, all of the green grounding screws are on the same side.)
  5. Now carefully remove a section of white 14 gauge wire from the outer casing and cut three pieces about 8 cm each. Be sure to only score the outer casing with your utility or exacto knife so that you don't cut into the bare wire. Any exposed bare wire presents a very dangerous hazard so we want to prevent it at all costs.
  6. Using the strip-guide on the back of the receptacles, strip off exactly the right amount of insulation from both ends so that you can press the wires into the holes as shown leaving none of the exposed wire still visible. (I bet some of you didn't even know there was a strip guide on the back of those things. Kinda handy huh?) Remember the 14-gauge wire is quite stiff so you will want to get the lengths right. I put a little bend in the center so that I could make the the exact length I needed to go from one receptacle to the next.
  7. IMPORTANT! No white wires go into the holes marked for hot (black). (Duh right?) Basically we are chaining together the commons by putting a wire from 1-2, from 2-3, and from 3-4.
  8. Finally cut and strip one more piece of white 14-gauge wire about 10 cm and push it into the extra hole on the right hand receptacle closest to the green grounding screw. (This step is not shown in this picture but you'll see it later on.) Just leave the other end hanging out for now.

Step 4: Securing the receptacles and mounting the relay board

Picture of Securing the receptacles and mounting the relay board
For this step, we will need to measure and cut two pieces of wood which will serve to secure the receptacles in place and will also be used to mount the relay board. These will be 2.5 x 2.5 x 18 cm.

Before mounting the blocks into the lid, we will use one of them to create a wire-bending jig. (I should have taken a picture of this, sorry) I found it really helped keep the wires nice and neat which is important in this project because there are so many wires in a small space. Here's how I did it. Make 8 marks along the block of wood to coincide exactly with the slots between the relays on the relay board. Then drill holes exactly 2 cm deep using a small bit about the same diameter as the 18 gauge wire. Now push the red wire into each hole and bend it square to make the shapes required for the wiring harness shown in the picture and cut them all off at the same location with the longest one roughly 16-18 cm from the bend. Before removing the wires from the jig, tie them together using wire ties (or tape or hot glue) That way when you remove the wiring harness each wire will line up with the relays.

Now strip off just the tip of each of the red wires about 5 mm. This will allow you to push them into the terminals on the relay boards without leaving exposed wire. Now secure them into the CENTER terminals on the relay board with the terminal set-screw as shown.

Next hold or clamp the blocks of wood in place in the box lid and then mark and drill (4) 1/8" holes into the top of the lid (and into the blocks of wood) about 2 to 2.5 cm from each edge (in the corners) to receive a screw. (I used 4 of the screws I removed from the receptacle tabs. I realize these are not technically wood screws, but since I pre-drilled the holes they did the trick.) These screws and wood blocks effectively clamp the receptacles into places so they can't move around.

Finally, using two small screws, mount the relay board to the top block using the two holes on the side opposite the terminals as shown. (The terminal side of the board will hang out suspended above the backs of the receptacles. Again please refer to the picture.)

Step 5: More wiring...

Picture of More wiring...
157.JPG
158.JPG
Next we will wire in each of the 8 black wires to the left-hand terminal for each relay. Carefully bend, cut and strip each of the black wires to fit exactly into the corresponding terminal on the relay board. You will want to connect them to the left hand hole of each terminal. (The right hand holes will not be used in this project) Remember to only strip about 5 mm of insulation so that all of the exposed wire will neatly fit into the terminal.

Safety note here! Make sure the power cord is not plugged in while you're working on it!

Now we'll wire in the power cord.  I used an old computer cord for mine, mainly because I had a few laying around with nothing to do and because the cord was round which makes it easier to fit into a drilled hole (1/4" drill bit was a perfect fit). As an added bonus, the computer cord has color-coded wires inside so it is easy to tell which is the hot (black), the common (white) and the ground(green.) If the cord you're using does not have the nice color coding, don't worry, it's easy to tell with a multimeter.

(Refer to second picture for this step) Drill a hole in the bottom of the box and insert your power cord 20 cm or so.  Very carefully remove the outside casing to expose the three insulated wires inside.  Make sure that you knife did not remove any insulation on the individual wires.  You may also want to wrap electrical tape several times around the cable just as it enters the box to prevent it from being pulled back out through the hole.

Now we'll connect the power cord to our relays.

The only hard part here is getting all of the red wires connected together. Since the red wiring nuts are too small to fit all of the wires, we will split the red wires up into two groups with a short section of 18AWG wire connecting the two together.

The goal here is to get the black wire from the power cord connected to all of the red wires. The trick to using a wire nut is to have all of the wires stripped the same amount and have them terminate together. (Except stranded wires such as those coming from the power cord can extend a little longer than the solid ones, that way the strands wrap around the solid wires binding them together inside of the nut.) Make sure to twist the wire-nuts good and tight, you don't want them popping out on you.

The white wire is straight forward, just wire it up to the extra white wire that you left hanging out the the last receptacle. (Use a smaller wire nut for this step if you have one.)

Also notice (in the 3rd picture) that I used 3 short pieces of green wire to chain together the ground screws and connect them to the green wire from the power cord. The ground connection is important for safety.







Step 6: Adding your raspberry pi

A quick note of explanation: Up until this point of the build, I was planning on having a second cord coming out of the box to power the raspberry pi. Then it occurred to me that I might be able to add a female plug inside the box to plug the raspberry pi's USB power cord into. That way I would only need one cord coming out of the box. I happened to have an old Christmas light set that was missing most of the lights so I just cut off the female end with enough wire to reach the wire nuts. It worked out nicely. Just wire one side into the wire-nut with the white wires and the other side into one of the wire-nut with the red and black wires.

For this step you will mount a small piece of plywood to the bottom of the box using double-stick tape for the raspberry pi to rest on (and mount to) Using 1/4" screws mount the raspberry pi to the piece of plywood. (Then realizing you forgot to put in the USB WiFi Adapter... you'll take it back off, put in the wifi adapter, and then mount it again.) Ah hem.

Actually, before mounting the raspberry pi, you will want to make sure it is configured to use the wireless USB adapter to automatically connect to your wireless router when powered up. There are plenty of tutorials on the web to show you how to do this. Try this one for example.

Almost there... let's hookup our rainbow wire.


Step 7: Adding the magical rainbow (wire)...

Obviously in this step the colors don't matter.  It only matters that you create a connection between the correct pins.  If you happen to have exactly the same rainbow-wire set that I have, start by peeling off a 10-wire harness that has the following colors (in-order) Black, White, Grey, Purple, Blue, Green, Yellow, Orange, Red, and Brown.

I recommend pushing all the wires onto the raspberry pi first using the chart from top to bottom. (i.e. pin 1, then 6, then 7 then 11). You'll notice that there are several pins that have no connection, so pay close attention to the pin numbers.  If you hold the raspberry pi such that the SD card is on top and the header pins are on your right facing you, pin 1 will be on the top left, 2 is next to it on the top of the right-hand row, 3 is below 1 on the left row and so forth.  All odd numbered pins are on the left and all even numbered pins are on the right.  Hopefully that is enough info to identify the pins correctly. 

Anyway, wire up the 10-wire ribbon as indicated in the pictures.  If you have any questions, feel free to leave a comment and I'll do my best to answer.

Finally, you will need to remove the 2-pin shunt (jumper) that is on the relay board connecting the VCC to the JD-VCC pin.  (Just pinch it with your fingers and slide it off) Then peel off one additional wire to connect pin-2 (5V) on the raspberry pi to the JD-VCC pin on the 3-pin header of the relay board. (I used brown in the picture.)  This provides 5 volts to the coils to power the relay.  (If you fail to do this, you only get 3.3 volts to the coils which isn't quite enough.)


Step 8: Safety Testing - (Before you plug it in!)

Picture of Safety Testing - (Before you plug it in!)
Call me paranoid, but I really like to check and double check all of my connections before plugging something like this into the wall.  You really want to be sure you didn't accidentally wire hot directly to common or ground... bad things happen.

Don't worry, it's easy, just grab your multi-meter and dial it to continuity test. (If your multi-meter doen't have a continuity test, just put it on one of the resistance settings.)

Close up the box.

Connect one of the test probes to the ground post of your power cord using an alligator clip.  

Using the other test probe, touch inside of each of the receptacles' ground holes (the round ones) making sure that you have a connection on each one.  (Multi-meter should beep or, if you're using a resistance setting, the resistance should  go to near zero.)  Then check that you do NOT have a connection on either of the other two slots on each receptacle.)

Next check the common which is the longer of the two slots on the left (assuming the ground post-hold  is oriented down) Again make sure that all of the common slots have connectivity to the appropriate blade on your power chord AND that you DO NOT have connectivity to either the ground or the hot side.)

With me so far?

Before continuing, make sure you have setup the web-interface for the GPIO pins by following TheFreeElectron's instructable.

The hot-slot (the shorter slot on the right) of the receptacles should not have connectivity (yet) to any of the three posts on your power chord.  This doesn't happen until you activate the corresponding relay. 

If you want to be really safe, you can continue the test by plugging in only the raspberry pi. (Unplug the adapter from the female socket and plug it into the wall.)  Using the web-interface on a computer, tablet, or smart-phone, turn on each channel one at a time and listen for a distinctive click of the relay making the contact.)  One thing you'll probably notice right away is that web-interface buttons are reversed.  In other words, when it indicates ON, it will actually be OFF and vice-versa. This is because the relay board is "active-low" meaning that the relay is turned on by pulling the corresponding pin to ground and not to VCC.  For now this is just a minor annoyance, there are several ways to fix that. 

To test this, connect the alligator clip to the hot blade on your power cord and insert the other test probe of your multi-meter into the hot-slot of one of the receptacles.  Use your handy web-interface to cycle the channel on and off and verify that the connectivity on your meter responds accordingly.

If all that works CONGRATULATIONS, you're ready to plug it in and give it the full test!





1-40 of 89Next »
natebman10 days ago

I was just wondering if you had had any problems with the raspberry pi controlling and powering the relay board? I found a schematic that says the relay board is active low and the raspberry pi is active high so you have to short the relay board to ground to active the relay.

rleddington (author)  natebman10 days ago
It worked fine except that the web-site displays green when its off and red when it's on. I tweaked the code a little bit so that I could reverse that and show green for on and red for off.
KHOR15 days ago

hi, i'm newbie, may i know that if my receptacles are 15amp 250v, how many volt of relay board i need to use?

HenryA127 days ago

hi. i'm newbie , so how can i control /monitor the lamps from my smartphone,Are there any sripts or coding ?? i would like to learn that, thanks

hello sir I want to control our electrical home applinces through my mobile using raspbery and monitor that how much power is consumption at hat time....

the data must show graph bw power consumption over time..

help me.....

joesewer1 month ago

Hi, for some strange reason my setup shows for Red button (which normally would be off) the on state. Can you guess what might be wrong?

Can you do this with a 50 amp (normal australian mains socket) instead? what modifications would i need to make?

SandeepS22 months ago

How I know that my device is ON / OFF when I am at long distance ... Any acknowledgement ?

rleddington (author)  SandeepS22 months ago
Yes, when you visit the web-page served by your raspberry pi, you get to see if the devices are on or off just. (Red for OFF, green for ON)
And if any one device is not starting then how we get the feedback that it is not starting ?
bandicoot_4 months ago
EW!!! Who wants your phone???
rleddington (author)  bandicoot_4 months ago
No kidding. The Motorola Triumph is a LEMON! Can't wait to get a new phone. This thing crashes so often my standard procedure has become - remove battery - put it back in - use phone - repeat. :-(
dragons.n.s5 months ago

hi there,

i have some doubt, since your wiring system is differ from ours in India, and i identify that green wire is ground, yet i can't find that black wire you used is positive or negative charge. can you plz answer for that. thank you

rleddington (author)  dragons.n.s5 months ago

I'm not sure I understand you question but I will try to answer just the same. The power cord has white, black, and green. Since this is A/C there is no such concept as positive/negative wires. Instead you have a ground (green), hot (black) and neutral (white). All of the energy (both positive and negative) come from the black wire. Does that help?

hi there
sorry about that, thats not my question, actually its my friend's question. i know how it works but he insist; so i wrote that. yet thank you for your reply

the ground wire (green) is sometimes BARE copper. it depends on the manufacture of the wire. the standard is what was listed above, so if your friend sees no green but does see a bare copper then that is ground. The only other possibility would be the wire is a 2 conductor line that has no ground. Hope that helps

jaredr096 months ago
Scratch that last comment I fixed it and found out why one is not working. Notice in the picture how the Q6 has wires not completely in the relay board. That's the problem had to order another relay
14, 8:59 AM.jpg
rleddington (author)  jaredr096 months ago
Glad you figured it out. Yea the relay boards are kinda cheap. Good job with the build!
jaredr096 months ago

Having fun working on the project. we are having a problem with one coil not clicking it was 2 coils but i tied in the other 5 volt pin from the pi to the relay board which gave me more power but for some reason one still will not click on the light turns on but still no click. the power supply i am using is 5V 700mA for the output.

hhs997 months ago

What software did you use on the PI?

rleddington (author)  hhs997 months ago
I used wiringpi and the apache web server. Just follow thefreeelectrons instructable to get it all installed and working.
kumaran5128 months ago

excellent article.....i need to control 16 channel relay.....please help me what all to be included

Jonnphillip9 months ago

Hey so I have a really quick/simple question. If you did not want to use this project to control your devices wirelessly but instead have there power controlled by a timer is that possible?

For instance say you had 3 or 4 devices that you wanted to run power to on separate timers so they all turned on and off independently.

Thanks!

rleddington (author)  Jonnphillip9 months ago

Hi Jonnphillip,

Great question. Yes, absolutely it is pretty easy to have any devices setup to go on/off at any time automatically. There are several ways to do it, I simply edited the crontab and used the gpio programs to turn on/off different channels at different times of the day.

mlweiss10 months ago
Great instructable. Thanks for posting. My suggestions would be to add fuse or circuit breaker on the "mains" to relay and 2) label box for inside use only. As a mod for outside use, suggest adding weatherproof enclosure and adding unswitched GFI plug and run "mains" downstream from GFI to protect circuits from ground fault.
AJMansfield11 months ago
120V is hardly 'mains power'. Mains power is usually at least 1kV, and can get to hundreds of kV.
rleddington (author)  AJMansfield10 months ago
You may want to lookup "mains electricity" in google. It looks like I'm not the only one that uses the term to refer to 120V alternating current household power. If I'm wrong, at least I'm not alone. :-)
Dialectal language strikes again. For me, 'mains power' refers to high-voltage transmission lines, (which are normally around 100kV), but it seems that usage is non-standard.
I agree that this comment from AJ was pointless and being an electrician, I'm sure I can safely say that this use of the term will suffice. i guess some people just have to say anything to feel included. - "usually at least"??? -
FuzzeeDee11 months ago
Nice project, think I'm gonna try it. I do have one suggestion though, rather than using the murets (twist on caps for wires) I would use a bus board. Much less chance of overheating or sparking. Bus boards are found at any big DIY store that carries electricians supplies. It will also make for a neater layout but will cost you some space and you can get ones that have a snap on plastic cover to prevent accidents.
rleddington (author)  FuzzeeDee10 months ago
Awsome, let us know how the build goes.
trippedout11 months ago
this is an excellent write up - been meaning to try something like this for a long time but the idea of shocking myself with 120v kept me out of it. one question tho - for a setup like this to be outdoors/weatherproof, id need something like this http://www.dyersonline.com/diamond-15-amp-weatherproof-receptacle.html instead right? and make some kind of roof that can protect stuff when its plugged in? would that be all?
alfista260011 months ago
This is awesome. I started doing this some time ago, but didn't have time to figure it all out.

I've got my pi able to turn on all the relays (the LED on each of the 8 relays lights up) but it only seems to be able to turn on the first (far side from JD-VCC) relay on. It is the only one that I can hear a click for and the outlet powers on. Any thoughts on what might be wrong? Relay 7 also will not keep a solid LED (alternates off and on every 5 seconds).

Thanks!
rleddington (author)  alfista260011 months ago
I would check the voltage on the JD- VCC pin. I had the same problem with a weak powersupply. Remember that the Pi only has 3.3 volts on the GPIO pins, but thats not enough for the relay coils. So VCC should have 3.3 V and JD-VCC should have 5 V.
Sembazuru11 months ago
Good attention to detail while checking continuity. At my work we call this checking the beeps and anti-beeps (because most continuity testers beep with continuity).

Out of curiosity, with this setup are you able to log into the Pi via SSH to facilitate updating the onboard software or have the Pi do other things (fileserver while waiting for relay commands)?

Also, I don't know if you have enough space in your enclosure, but it might be a good idea to put a 10A breaker on each of the outlets to protect against overloading any one of the relays. In a project for work I used these: http://octopart.com/1658-g41-02-p10-10a-e-t-a+circuit+protection+and+control-81875, but they might be a bit bulky for your design (and unfortunately would lead to mains being connected to both the lid and the box...) There may be other models out there that would fit this project better...

Sorry, too many ideas... Another idea to keep the AC cord from pulling out of the box too much would be to either use an actual strain-relief bushing, or simply a zip-tie clamped onto the wire on the inside of the enclosure. For safety in case of a catastrophic pull on the cord which partially or fully pulls it out, the hot should be the first to disconnect, and the green ground should be the last to disconnect. Yes, you would still have a dangerous hot flailing about on the AC cord, but none of the attached devices would be floating hot. Maybe have a small diameter cardboard tube (like from an inexpensive wire hanger that has the cardboard tube for hanging slacks) inside the enclosure that the hot wire runs through so it doesn't flail against the Pi while it is loose. (Hmmm... am I starting to over engineer this for you?)

Stop me now before I suggest using GFCI, especially when planning on deploying this near water (like what is at the bottom of live Yule trees)... ;-)
rleddington (author)  Sembazuru11 months ago
Great ideas. I like the idea of adding more over-current protection, especially if you wanted to sell these. I think a breaker may be too big but perhaps an in-line fuse would do the trick. Also a warning sticker letting you know what the per-channel and overall currunt limitations are.

Concerning SSH connections, absolutely yes. Even though the box is in my cold garage, I can remote log into the pi from my warm bed and write all sorts of programs for it. Set up cron jobs to run various scripts, etc. That's my favorite part of this design.
npimpfellow11 months ago
Is there a way to replace the 8-Channel 5V Relay board to turn this into a dimmer?

I'd love to build a remote controlled dimmer-pack this way! Please send me info if you know a board that would work!
rleddington (author)  npimpfellow11 months ago
I'm sure that's possible. A Triac dimmer with zero-cross detection is the type of circuit you would need. I don't know of any commercially available modules with exactly 8 channels, but there may be one out there if you look hard enough. Or you could go the DIY route and design your own. Google "Random Phase triac driver" module and see where it takes you.
Thanks for the info! If you come across a module that might work please link me!
FlintSyrup11 months ago
This will be great for pranks.... Meh hehe >:)
1-40 of 89Next »