Introduction: Arduino Controlled Relay Box
This project is designed to help you construct some relay boxes for controlling power from your wall socket using an arduino or microcontroller. The inspiration for writing an instructable came when I decided to build some relay boxes for my personal Garduino project. For safety concerns I started designing my own relay circuit and outlet until I came across SparkFun's article "Controlling Big, Mean Devices".
I decided to abandon my own plans mainly due to time and cost and ordered the parts from SparkFun. What follows is essentially the same information you'll find on their guide but with a few of my own notes. I hope that you find my insights helpful and it will get your project off the ground without a hitch.
Step 1: Parts and Safety
The great thing about this project is that there aren't a lot of parts that you need to get started. You probably have most of the parts lying around your junk box and the rest you can order directly from SparkFun or your favorite supplier. I've made a list of parts available on my wiki. SparkFun can supply the relay and PCB and your local hardware store will have your GFCI Outlet and electrical housing.
Now a brief note about safety. Every time you work with electrical lines you may be risking your life if you don't use the right precautions. In general you should always employ a certified electrician but you can do this project on your own if you're careful. Absolutely ensure the plug is not connected to a live electrical socket when working on the relay, the outlet, or the extension cord at any point. Also, it's probably good practice to enclose any wires before testing. With that you should probably do just fine.
Step 2: Assemble the Circuit
- Attach the resistors
- Attach the diode
- Attach the transistor
- Attach the three pin screw terminal
- Attach the two pin screw terminal
- Attach the LED
- Attach the Relay
Put the relay on last because it gets in the way if you don't. You will find it to be a little tight against the two pin screw terminal, but that is ok because it still fits. You don't have to use the two pin screw terminal either and can opt to solder the extension cord directly to the board, but I decided against that for useability.
Step 3: Splicing the Wires
When you splice the extension cord wires you are likely to see one of two things. Either your cord has three different color wires or it doesnt, but there ought to be three or this project won't work. The three cords are as follows:
- Green - Ground Return
- Black - Hot Wire
- White - Neutral Wire
Your going to cut the extension cord about a foot from the end of the female plug. Then split the three wires about 6 inches down. Cut the black wire five inches from the end. This should give you about one inch attached to the cord and a 5 inch extension that will go from your relay board to the outlet.
Next strip and tin the end of all the wires. It's likely your wires are a collection of smaller wires, twisting them before tinning is a big help. Then lay out everything and check it before moving on.
Step 4: Assemble the Relay and Outlet
You're almost there! You need to attach the relay and the outlet to the extension cord you just prepared. Something to remember here is to thread the extension cord through the nail mount housing before you attach it to the relay and the plug. This is expecially important if you intend to solder the hot wire to the relay board. Remember, I decided against this in case I wanted to re-use the relays at a later time and instead used the screw terminals.
The GFCI outlet is the most important part of this entire apparatus. The reason you're using this instead of a different outlet is that it may protect your life in the case of an over-voltage event. For this reason I recommend that you actually take the time to read the manual that came with your outlet before connecting the wires.
I was fortunate that my outlet had color coded screw terminals on it. On mine the ground plug screw was green (for ground), the hot wire attached to the brass screw, and the neutral wire to the silver screw. Also, my wires connected through holes in the back of my outlet plug, not the exterior. I can't help you with your outlet, so again read the instructions.
Finally, cut three six inch pieces of 22-guage wire. I chose three different colors so I could distinguish them when hooking them up to my microcontroller. I suggest you do the same thing. Also, don't get them backward. I made two of these and accidentally hooked up the ground and +5V lines in the opposite position. It didn't hurt anything but I had to take the whole thing apart just to reconect the lines properly.
Step 5: Complete the Outlet Box
Now you've got everything connected all you have to do is close up the box. Since you already threaded the extension cord you should be able to simply pull everything into the housing. Pull the control wires out the other side of the box and push the relay board to the bottom. Put the outlet on the top and screw it in, finishing with the top plate. If you have stickers that say "GFCI Outlet" you can put them on the sides of the box at now and move on to testing.
Step 6: Test With an Arduino
You are now done with your project. If you've wired everything up then you're ready to test out the box. I tested mine with my arduino. Below is some code you can use to test yours out too. In this case I connected up the red wire to +5V, the black to ground, and the green to digital pin 12.
Here's the code I used:
https://github.com/chrisgilmerproj/relay-box
I hope this project worked for you. You'll find this useful in a number of great projects, so go out and make something fun!
18 Comments
9 years ago on Introduction
Thank you mate, this was my first real life scenario with Arduino
9 years ago on Introduction
Hi. Im trying doing my project but i was confused about the connection between arduino uno, CT sensor, Relay , AC- AC adapter and socket outlet. The project that I was doing is monitoring power appliances.
10 years ago
Hi. I'm trying to use this with a Refloleo ( on Kickstarter) He has 2 inputs to control the relay, this has 3 wires. I guess I need to get some power to this relay for it to operate.
10 years ago on Introduction
Does this control both outlets? or just one?
Reply 10 years ago on Introduction
Yes, it controls both outlets at the same time.
10 years ago on Introduction
Hey, I'm going to build one of these as soon as I receive the parts. I was wondering if there was a way to place a relay for each plug, or would you have to use a non-GFCI plug? If so, is it really unsafe to do so?
I have a broader idea in mind and this is the first step in pulling it together. Thanks
Reply 10 years ago on Introduction
You'll definitely need a different circuit for each plug you wish to automate. It's probably unsafe to use non-GFCI for projects, but you can do it. Play around with it and see how you like it with the setup I describe and decide what you want to do from there. Good luck with your project!
11 years ago on Introduction
This is cool! If you want to switch high power faster, use a solid state relay. The advantages of a solid state relay are that it can switch faster because it is not electro-mechanical. Great ible!
13 years ago on Introduction
Hi there,
I really appreciate you posting this instructable, and enjoyed the SparkFun tutorial as well. I have been in the planning/prototyping stages of putting together a homebrew home automation system for the past year, and this tutorial will certainly come in handy. You see, because I will have some relatively important things being controlled by the system I'm planning, I do not want to use pre-constructed systems like X10, for fear of mixed signals from my neighbors.
One thing I have been trying to find is a solution to a switch-controlled device (eg. front porch light), but I have not been able to find anything. Have you seen a product or homemade solution to this issue? Your instructable has given me the idea of maybe setting up a "2-way" switch layout, but with the 2nd switch being a relay, and housing it within the existing light switch box. That way, you could switch the load manually, or by automatic control. Adding a sensing element to the load pair would enable you to make the switch smart enough for the system to actually turn the load on/off, rather than just send a switching signal.
I would love to hear what you think, and if you have heard of a device (homemade or not) that could make this work!
Thanks,
Mike
Reply 11 years ago on Introduction
Hi Mike...
I don't work for only program but you might want to look in to a Crestron control system... It will run your house and more.
Good luck.
Leo
11 years ago on Step 4
Also, any outlet you buy nowdays has the Black/Hot/Brass screw and the White/Neutral/Silver screw, and it's been that way for a long time. A regular outlet costs ~$0.50, and a GFCI is maybe $15, so there's almost no reason not to buy new.
12 years ago on Introduction
i was wondering if you could replace the relay from a 120v AC and use a 12V DC. I want to use an old computer fan and have a tempature control for it.
Reply 12 years ago on Introduction
you dont need a relay for that, simply a transistor would do
check the specs of ur fan and find a transistor that can handle the current, add a nice heatsink and ur practically done!
12 years ago on Introduction
Hi, Lots of information about power control with Arduino here:
http://arduino-info.wikispaces.com/ArduinoPower
Several kinds of relays here:
http://➡.ws/relays
Regards, Terry King
terry@yourduino.com
Reply 12 years ago on Introduction
Sorry. Bad link. Try this:
http://arduino-direct.com/sunshop/index.php?l=search_list&s[search]=relay&s[title]=Y&s[short_desc]=Y&s[full_desc]=Y&s[sku]=Y&s[match]=all&s[cid]=0
13 years ago on Step 4
QUOTE:..."The GFCI outlet is the most important part of this entire apparatus. The reason you're using this instead of a different outlet is that it may protect your life in the case of an over-voltage event."
ACTUALLY, the reason for using a G round F ault C ircuit I nterrupter is because it will trip (and possibly save your life) during GROUND FAULT conditions.
More info at "How Stuff Works" http://home.howstuffworks.com/question117.htm
13 years ago on Introduction
Hello,
Your instructable is really nice and easy to follow. I stumbled upon this from the name Arduino and well...
What is a relay box? How will it help me with my Arduino projects?
I just got my Arduino today and been looking for guides and tutorials on how to program the arduino.
Reply 13 years ago on Introduction
Glad you liked the instructable! Wish I could take credit for most of the work here, but I followed directions from the people at SparkFun.
A relay is a kind of switch. It allows you to turn on and off this switch without being directly connected to the thing you're turning on or off. In this case I wanted to turn on and off power to a light and a pump in one of my projects. I used the relay to turn on and off the 120V power using the 5V signal from my arduino.
If you've got projects where you need to control power to something that normally plugs into the wall this is a good way to do it. I think these things are dead useful when combined with the arduino so I've actually built a few.
Hope this helps and good luck building!