Always wanted to take total control of your electric appliances even without being at home? Well, thanks to this instructable you will be able to do that and much more.

Some friendly suggestions before starting:

  • Electricity is very dangerous, read and follow the "DANGER:" advices written in this instructable.
  • If you don't have any experience in the field of electrics/electronics seek for supervision from a knowledgeable person, although the circuit it's very simple If you don't know why you are doing what it's being explained the odds are if you make a mistake you won't be able to notice it, leading to unpleasant consequences.
  • NEVER EVER work on the circuit while it's connected to the grid, also don't do it with it connected to the arduino, some tin solders transmit small amounts of current that can damage it.
  • A steady power supply is recommended if the relay will be on during long periods of time.

To build a plug to plug arduino based-controlled switch you will need the following materials:

-1x plug to plug with manual switch (we want our circuit to fit inside).
-1x 5V relay (that holds 240V and 10A, check the datasheet of the one I used here).
-1x 2N2222 (also called PN2222) transistor.
-1x IN4002 diode (I used a 4007, small variations are acceptable).
-1x 1000 to 500 Ohms resistor. (I used one of ~750Ω)
-1x Prototype board (1,5x2 inches should be enough).
-1Strip x Female pin header (just for convenience).

Total cost: ~$6.

And the following tools:

-Microcontroller (preferably an original Arduino® board, notice I'm using a cheap imitation).
-Tin solder.
-Thermofusible glue gun + some glue (epoxy would work even better)

Step 1: First Build and Test.

First we want to mount and test all the components just to make sure we don't do a lot of work to end with a defective circuit, you can find some pieces of code at the step 6.

We can do this easily following the diagram shown above connecting the 5V to the 5V supply pin of the microcontroller and GND to the ground pin, i/o pin will be connected to the pin we want to use to send the signal, 10 in this case, and will have a resistance attached to it, the value might vary depending on the voltage used, mine works best with a 750Ω resistance, too high and it wont switch, too low and energy will be wasted.
To place the diode notice that they usually have a white band around the anode (the side of the "bar" if we talk about the symbol).

The reason for the diode and the transistor to be there is to protect your board, the diode redirects the voltage peak the coil induces to itself when the power supply is cut and the transistor acts as a protective shield for the board, so it can operate behind it without being affected by any harmful current variation, the resistor just limits the amount of current the base of the transistor can draw, making the circuit more efficient.
Connecting your microcontroller directly to the relay would end permanently damaging your chip.

IMPORTANT: If you want to make a "value=digitalread(button)" and then an "if(value==HIGH) {}" statement (just what I did) you'll need to place a resistor in the order of some hundreds of thousands of Ohms from the pin the switch is placed to ground, that will avoid getting wrong results, and getting frustrated.

Once it's all tested we can move on to the next step.

<p>it took some time but i made one to. thanks for making the instructable i had fun reading your instructable and making this for my arduino.</p>
<p>Thanks for posting this instructable. I built one myself last night. Very easy to follow, while still highlightning the dangers involved. I especially liked the picture of the PCB with the traces pointed out :), it made it easy for a beginner, such as myself, to build something new while feeling relatively safe not to mess up the routing.</p><p>Only issue I had was that my leonardo kept turning on/off the relay all the time... Apparently it was unable to power both the transistor and coil while powered through USB :/ Applying external power to the transistor solved that problem though.</p>
<p>Make sure you have a resistor of at least 500 Ohms between the Arduino and the base of the transistor, if you haven't done this the base will draw too much current, even surpassing the limits of the Arduino, this would explain why you need an external power supply for the transistor.</p><p>Also the relay must be rated at 5V, with 6V ones you might have problems.</p><p>My circuit works just fine with the 5V output of the Arduino, even powered with a 9V battery it still works not showing any signal of excessive draw (e.g: power LED dimming), but this is only when using the resistor, without it the circuit clearly draws too much energy.</p>
<p>I put an 800ohm resistor between the arduino and base, so that should be fine. And the relay is of course 5V, I can even trigger it with 3xAA(slightly used) batteries.</p><p>I think its something either with the leonardo board or my USB port(my guess is the leonardo board), because when only powering from USB the output voltage fluxuate quite a lot. Powering the board externally gives a nice rock-solid 5V output.</p>
<p>What do you mean by &quot;<em>A steady power supply is recommended if the relay will be on during long periods of time.</em>&quot;?</p>
<p>I meant a power supply obtained from the grid with an adapter, just to avoid draining the battery.</p><p>Sorry if I expressed it in a confusing way.</p>
thanks :)
Please contact me regarding this device
<p>Cool project. I've been wanting to find a way to remotely turn off appliances from one main switch which would send a signal (over a home network perhaps) to turn off all &quot;listening&quot; devices. Imagine going to bed / leaving the house, flicking a switch by the door to kill all phantom loads, hot water heater, etc. A &quot;whole home&quot; off switch.</p>
<p>I've been also thinking about using an ethernet shield (or a Raspberry Pi) to control it.</p><p>Sadly I just know to program with the windows console variant of C and I still have some problems to program my arduino, I will spend this summer learning java, c++ and maybe even something about python or android app developing.</p><p>About your idea, just make sure not to exceed the relay capabilities, also not to turn off the fridge :)</p>
<p>Please reconsider spacing between mains and low power side of the arduino! Since you are not using any optocoupler, you could accidently get 230V on your arduino - not even knowing, if you are using a floating power supply. On touch, the current would flow through you to earth.</p><p>For a safe construction you would use 1,8 mm and more spacing between the mains side and everything else.</p><p>Further reading on:</p><p><a href="http://www.smps.us/pcbtracespacing.html" rel="nofollow">http://www.smps.us/pcbtracespacing.html</a></p><p>(also image source)<br></p>
<p>I sent you a message about this issue, please read it and tell me your opinion.</p><p>Thanks for your time.</p><p>This instructable will be immediately deleted if it implies any potential risk or threat to the security.</p>
<p>I wouldn't want you to delete your instructable, but please add the discussed safety spacing changes.</p><p>Everyone else might also consider the &quot;pollution degree for electronic equipment&quot;:</p><p><a href="http://www.ni.com/white-paper/2871/en/" rel="nofollow">http://www.ni.com/white-paper/2871/en/</a></p><p>Cheers!</p>
<p>I've used a solid state relay for this purpose, they're very cheap on <br>ebay and they contain an internal opto-isolator which draws very little <br>current so you drive it directly from the arduino, no transistor <br>necessary just a 220 ohm resistor.</p>
<p>pros: good and save industrial alternative</p><p>&quot;cons&quot;: not so mutch diy, takes a lot more space, sould be more expensive if it's done right (china parts might have some cheap, unsafe solution inside)</p>
<p>I'm not very comfortable with my soldering skills - How do you think this board(link below) would do as part of this project?<br></p><p><a href="http://www.ebay.com/itm/310886731873" rel="nofollow">www.ebay.com/itm/310886731873</a></p>
I've taken a look at the circuit diagram and it's basically the same except for some LED's. I don't think it would make a difference to use it instead of the circuit I've made.
<p>Thanks to all of you!</p>
<p>Pretty cool, and very useful. It will work good with an attiny45/85, but I don't really know how useful it will be, considering the attiny limitations... Anyway, good instructable.</p>

About This Instructable




Bio: I'm an electronic engineering student. I don't usually have much spare time but I like to work on random projects to keep myself ... More »
More by Victor805:The Joule Blinker Cheap caliper battery life hack Wood LED Desk Lamp 
Add instructable to: