Instructables
Picture of Microcontrolled AC switch.

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.
-Multimeter.
-Thermofusible glue gun + some glue (epoxy would work even better)
 
Remove these adsRemove these ads by Signing Up
demond101 made it!6 months ago

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.

Picture 019.jpg
Lucif3r9457 months ago

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.

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.

Victor8o5 (author)  Lucif3r9457 months ago

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.

Also the relay must be rated at 5V, with 6V ones you might have problems.

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.

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.

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.

Mahmoud.Samy7 months ago

What do you mean by "A steady power supply is recommended if the relay will be on during long periods of time."?

Victor8o5 (author)  Mahmoud.Samy7 months ago

I meant a power supply obtained from the grid with an adapter, just to avoid draining the battery.

Sorry if I expressed it in a confusing way.

thanks :)
bluesquare7 months ago
Please contact me regarding this device
rimshot7 months ago

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 "listening" devices. Imagine going to bed / leaving the house, flicking a switch by the door to kill all phantom loads, hot water heater, etc. A "whole home" off switch.

Victor8o5 (author)  rimshot7 months ago

I've been also thinking about using an ethernet shield (or a Raspberry Pi) to control it.

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.

About your idea, just make sure not to exceed the relay capabilities, also not to turn off the fridge :)

MeGravity7 months ago

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.

For a safe construction you would use 1,8 mm and more spacing between the mains side and everything else.

Further reading on:

http://www.smps.us/pcbtracespacing.html

(also image source)

pcbtracespacing.png
Victor8o5 (author)  MeGravity7 months ago

I sent you a message about this issue, please read it and tell me your opinion.

Thanks for your time.

This instructable will be immediately deleted if it implies any potential risk or threat to the security.

I wouldn't want you to delete your instructable, but please add the discussed safety spacing changes.

Everyone else might also consider the "pollution degree for electronic equipment":

http://www.ni.com/white-paper/2871/en/

Cheers!

85rocco7 months ago

I've used a solid state relay for this purpose, they're very cheap on
ebay and they contain an internal opto-isolator which draws very little
current so you drive it directly from the arduino, no transistor
necessary just a 220 ohm resistor.

MeGravity 85rocco7 months ago

pros: good and save industrial alternative

"cons": 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)

jbrimberg7 months ago

I'm not very comfortable with my soldering skills - How do you think this board(link below) would do as part of this project?

www.ebay.com/itm/310886731873

Victor8o5 (author)  jbrimberg7 months ago
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.
Victor8o5 (author) 7 months ago

Thanks to all of you!

Zironid7 months ago

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.