120v Switching

[Kenneth] built a 5v controlled power outlet inside of a junction box. We’ve seen plenty of projects that can switch 120v outlets using 5v logic for refrigerator controllers, lighting controllers, or grow systems, but they almost always use solid state relays to facilitate the switching. This iteration uses mechanical relays along with the necessary protection circuitry. The project is housed in an extra deep single-gang box and allows for individual switching of the two outlets. You can see this connected to an Arduino switching two lamps after the break.

[Thanks Mightysinetheta]

52 thoughts on “120v Switching

      1. So, what is the required separation? When I want to put a 120v receptacle and ethernet in a 2-gang box, I have to put a physical partition separating the two sides. You can’t do that with relays connecting the two sides, so what is the compliant means of separation? Just runt the wires to opposite sides of the box and tie them down so they can’t wander to the other side? Is there a code section that describes the required separation.

        I’d like to do some DIY home automation using a Raspberry Pi and some relays controlled by that device, but I’d like to maintain safety by only using relays in a code compliant way.

  1. I was looking into doing this as well. Problem I had is I wanted a low power application, solid state relays couldn’t handle the maximum load of the outlet (15A in north america I believe), but physical relays took a fair chunk of power themselves, 400mA for the ones I was looking at.

    I know it’s probably a safety issue, but there needs to be a relay that only draws current for the actual switching, then stays there unless it’s switched back.

  2. If you were going to put this in a wall, it would be better done in a junction box, separately from the plug itself, then run 14/3 to the plug. For one, it’s not fully accessible to the room. For two, no one expects to see extra electronics behind an outlet. From the electronics side, it’s a good solution. There are commercial alternatives (X10/etc) but this is definitely cheaper.

  3. @Peter there is it is called a latching relay. some have two coils so a pulse on one will turn it on and a pulse on the other will turn it off. other only have one coil and one pulse will turn it on a second off.

  4. “By the way, I certainly hope that this ‘hack’ is not ‘news’ for anyone reading this website.”

    Because we certainly wouldn’t want any beginners on here getting in the way of all the constructive commentary. Goddamn beginners reminding us that we once knew as little as they did …

  5. “By the way, I certainly hope that this ‘hack’ is not ‘news’ for anyone reading this website.”

    Actually, I was thinking just yesterday of how to do something very similar, but with DC. I’ve just ordered the parts, and this will be my first Arduino project. So, yes, this is ‘news’ to me, and I’m glad the editors don’t take the same elitist attitude!

  6. oh,I see we have some NEC experts here.

    So tell me when it is acceptable to have high and low voltage mixed together?

    first one to get it right gets an arduino shoved up their a##

  7. @pillbox: at a step down transformer inside of an approved enclosure.

    This is a horrible build from a safety stand point. Cardboard, no fuses, no optical isolation, and if it burns your house down you’re out a house for violating your local electrical code. Your insurance company will laugh at you.

  8. polossatik,

    >Maybe start a Hack101 website for stuff like this and blinking leds?

    The LED must at least have an Arduino causing it to blink in order to be featured on Hackaday. Everyone knows this.

  9. @Peter: The relay I’m using draws about 65mA at 5V, so the power consumption isn’t killer. A latching relay would be ideal.

    @Hackius: I separated the two outlets so one is NO and one is NC, so both. The coil is de-energized with a low input on the control line.

    About the NEC comments: I don’t show it, but the wire running out of the box is a 3 prong plug, so this is temporary wiring, and doesn’t violate the electrical codes as I understand them. I agree, I would NEVER NEVER NEVER put this in my wall. I just hacked this together to prototype stuff with my Arduino.

    Other lacking safety measures aside, I don’t understand why people are complaining about the lack of opto-isolation. The relay is rated for 1.5kVAC separation between the coil and contacts, so I’d think my lack of care in routing is more at fault.

  10. @polossatik
    Wow, this is a new low for hack a day.
    driving a relay with an arduino, you almost make it sound that a regular relay is more exciting than a ssr.
    Anyways awesome “hack”
    Digikey has multiple ssr’s that source/sink 16 Amps of AC at 120/240V, you could even use those as dimmers.

  11. Nice job Kenneth,
    Sorry if it offends some of the 733T hackers here. I have a different approach if anyone is interested. It uses opto isolation and Triacs that can handle 8 A RMS and 70 A peak with a 400V rating. The boards I am using even have a header that will plug into a arduino as a Shield. I have had about 500-800 of these laying around for serveral years and I just finally got around to messing with them. You see them at my blog mendingthings.com.
    Oh and to your point of not needing opto isolation, I have many stories I could share about relay breakdown leading to control voltage side melt down, so don’t rule out the need for isolation for a serious build.

  12. I would love to read an article that is about what is “the state of the art” for electronic control of mains power – (Inside a wallbox. As in something that meets regulatory standards and doesn’t look shitty.) I know that wouldn’t be a hack – it would be DIYinAProfessionalWayADay.

    Everytime someone says “there is a better way to do this”, they need to man up and post their solution to the web.

  13. Hi,

    because refrigerators were mentioned in the text:

    These types of relays which are shown on the photos are absolutely not suitable for direct switching of these types of load!

    1. A standard Linde-type refrigerator motor has an enormoulsy high inrush current when switched on. This is caused by the popular choice of a low-impedance resistive phase shifting motor starter auxiliary winding.

    2. The relay’s rated current applies to non-inductive loads only, and motor loads or similar are highly inductive.

    There really is a reason why contactors were invented…

  14. @mosheen,
    I will not argue theory with you. I will only state that Experience tells me magnetic isolation in the form of a relay is not sufficient to prevent damage to the primary circuit. This goes to Urich’s point about contactors. The spacing and design is such that the isolation is sufficient for protection as well as high inrush current. I don’t think that Kenneth’s intent is to install these in a wall for daily appliances or mass market them so he has an acceptable design. My comment was around a more serious build.

  15. “…no optical isolation…” You do realize that he has magnetic isolation by using the relay. Optical isolation would be redundant and useless.

    Posted at 6:24 pm on Jan 31st, 2010 by Odin

    @Odin: Not redundant, and not useless. It would provide an additional layer of protection, is easily sourced from old modems, and is no more than a passing thought to integrate into the design.

    Here’s my hour and a half build circa 2006:


  16. If it was built with SSRs you could do PWM dimming. I tried PWM (low frequency) with a relay, and I quickly fried a relay.

    Why would you want to switch a refrigerator on and off? The built-in thermostat is good enough for me, and I don’t want my food going bad if something goes wrong with a 5V supply, arduino, or relay.

    I am working on something similar for controlling lights (specifically, syncing to music), and I gave up on relays. I’m either going to do it with SSRs or make my own SSR. I plan on optically isolating it if I don’t use SSRs, (and maybe even if I do). I would never put it in the wall, even though it is build in a 4-outlet junction box (8 individual channels).

  17. @Matt – If you’re brewing at home, the built-in thermostats in most refrigerators suck, particularly if you’re using a chest freezer for conditioning. In that case, you can’t get the freezer ‘warm’ enough for the proper conditioning temp.

  18. @odin:
    I’m an industrial electrician and a control specialist. I’ve seen contactors and relays, and just about every other type of device charred to a crisp. A relay does jack for isolation when it burns up. Yeah it can handle 25kva blah, blah, but when the casing turns into carbon, a conductor, all bets are off. The opti is to protect the control side and the user. PLC’s have optical isolators on every card just for that reason. No sense killing the whole rack when a trace burns clean off of a relay board.


    I think you mean someone else. I use opti’s.

  19. Sorry I was talking to @odin not you and we are making the exact same point. I suspect those in our background have seen many toasted control circuits because of relays turning into carbon, copper and silver blobs. Not much isolation when that happens.

  20. This project seems to pay a little more attention to safety concerns than some of the other line-voltage “hacks” I’ve seen here, but I’d like to share a few comments.

    I agree that a solid state relay might be a better choice than a mechanical relay. I would mount it in an aluminum outlet box, so that the relay can dissipate heat into the housing. Ground the housing for safety.

    Solid state relays switch on zero crossings, so they are much quieter, electrically speaking. This is very important if you intend to do any kind of bang-bang control.

    One possible downside to solid state relays is that they will *not* switch properly if they are not loaded sufficiently.

    Whether you use a mechanical or solid state relay, one thing is clearly missing from this design– a fuse in the 110 “Hot” lead. A fuse goes a long way to protecting your switch gear, maintaining isolation, and protecting your home from fire.

  21. Good job. I would replace the cardboard and use a proto board so you can solder the parts to the board. They only cost about $3 for one that will do what is needed here.

    I would also place it in a metal wall box instead of plastic so if something like a fire were to occur you have better protection as well as the casing being grounded for shock prevention.

    People saying, ‘use a solid state relay’ need to realize that people have been using this circuit for decades and it is in use in millions of places for a reason, it works and it is safe. The relay is just as good isolation as a optoisolator and often more reliable than solid state relays because it produces no heat and has a very low parts count. Television sets have used this for over 30 years when turning on and off and I don’t see homes going up in flames because of it.

    One nice hack you can do with this circuit is to buy a cheap clock or clock/radio. Use an extension cord and cut one of the wires , leave the other wire intact. Inside the radio attach the circuit used here to the alarm function(speaker or piezo) and run the cut wire of the extension cord through the relay. You now have a device that can turn anything on at preset times and depending on the clocks functions turn it off after 15 minutes or 1 hour. I used it for years to wake up to my tv . This was back in the 80’s way before tv had alarm functions.

  22. That hot-melt glue construction could be a recipie for disaster – while the circuit design itself is fine (the relay providing adequate isolation), it wouldn’t take much for one of those components to pop loose and potentially short the high voltage side to the control logic side, leading to destruction or harm.

    Having used a decent duplex box and such, it seems odd to skimp on a simple protoboard or other suitable construction method.

  23. I would use a solid state relay. Just do a search on ebay. The last one I bought was $6.99 and that was with shipping. It can handle 25 amps and can be switched with 3-32VDC and provides optical isolation. You can drive it directly from a port on the Arduino. It will take a couple of weeks to arrive.

  24. Why do this when there are tons of pre-compiled solutions, that are much safer?

    (I know the “Why do this” question is the anti-thesis to hacking but I really think the ready-made option is better.)

    X10 products have been selling switch 110v outlets based on a form of analog powerline networking that can interface with a pc (or arduino) via serial or usb connections, since 1976.

    UPB is similar to X10 but uses digital signals, and is slightly pricier.

  25. For all you anti-multi-voltage in the same box yahoos check this out-
    This is a UL listed product.
    This handy little cube has a total of six wires sticking out of it.
    A 120V Hot
    A 120V Neutral
    A 120V Switch Leg
    3 LOW VOLTAGE switch wires
    It’s about 1 Inch Cubed
    Slam it into a box, or a fixture connect your low voltage t-stat wire that is rated for 300V in the same enclosure and….
    You have a great little switch system that turns on a light when you open the door or whatever you want it to do really.
    You get… If memory serves me correctly 6 Amps of rated contacts. There is no saftey there is no fuse, you only get breaker protection from burning this bad boy out.
    Go take your opto-isolators to your pretty PLCs.
    Yes opto-isolators have their purpose. You NEED them in certain situations. Usually High Voltage and/or High Current Situations.
    And please, don’t even try to argue that 120V 15A is High Voltage and/or High Current.
    If I could not mix voltages in the same box as a resi electrician I could not do my job. Yes there are restrictions but opto-isolators are not a necessary requirement of those restrictions.

  26. Your device is UL listed. His was not. It’s not in the wall, so it’s not a big deal. I know you can mix voltages. I replace more burnt out 120v equipment than I do 480v. 120 gear likes to catch fire. 480 usually goes quick and pulls the breaker with it. I merely suggested the opti as a good practice. Do what you want.

  27. Another thing. If it’s rated for 6amps where is your fuse? You do know it needs a fuse right? You gung-ho breaker-protected attitude is illegal, and I pray that’s not how you wire peoples homes.

  28. It’s rated for less then full circuit current just like a lot of equipment you wire in a house.
    Look at most dimmers- they are not rated for a full circuit load, most are rated for only 600W – if you don’t gang them and break their tabs. There is no fuse on them, they just burn out.
    I wire them that way because that is the way the code and their instructions tell me to wire them.

  29. @ jon (first poster.)

    Couldn’t you build it into the box in such a way that an optocoupler is the only passthrough?

    In fact, use a discrete led and the fiber-optic jacks from some old busted DVD players to make your own opto-isolated box.

    I am sure the NEC wouldn’t have a problem with it being optically coupled.

  30. Hi,

    from a security standpoint, opto-isolators certainly are a benefit, but they are only required by law (i.e.: “prior art”, “state of the art” clauses), if the relay used is /not itself/ rated for use in such a “class II isolative” protected application.

    There are some industry standards (e.g. EN 60335-1, (IEC 60990: 1999) Deutsche Fassung EN 60990: 1999 or DIN VDE 0106), but basically what you want is an isolation that is as effective as an 8 mm creepway on any surface, or 6 kV voltage.

    Another good indicator is: can a single, flattened drop of water cause dangeraus loss of insulation?

    Other issues are contact current, electromagnetic interference and switching/breaking capacity.

    The EMI is adressed with opto-isolating and snubber circuits, for higher currents you need bigger relays, and for higher switching power and breaking capacity you choose a contactor.

    If the contact current is rated smaller than the wall outlet rating and a short-circuit or overload can not completely be ruled out, you need an extra fuse.

    1. I just stumbled upon this old thread and realised, “protective isolation” is a rather unfortunate term for what I meant here.

      The correct term for electrical insulation as a means of providing safety even in case of single faults would be “reinforced insulation” instead of “protective isolation”, which seems to denote putting some person in an isolation room for medical reasons..

      That at least is in accordance with most international safety regulations like IEC 60664.

  31. If you forgot about building it into the outlet and just made a box that plugs in over the outlet then you do not have to worry about building codes.

    If you do this hack and your house burns down, even if it was not the hack that started it, the insurance company will have a good excuse to back out of covering the loss. I would advise that you NEVER do something like this unless it is 100% in line with your building codes.


  32. @SeanL: You see that cord coming out the left side of the box in the first picture? That’s the cord that plugs into the outlet, which means that this already does exactly what you say it doesn’t, except it’s in one of the CHEAPEST project enclosures I’ve ever seen (70 cents)

  33. I’m trying to sense 110v bath fan turning on and subsequently closing a 24v circuit for a heat recovery ventilator controller. I’m stumped by what I see as NEC limitations. Any ideas? I think a 120v coil relay n/o with spdt output side would work, but mixing 600v insulation romex and thermostsat cable in the same box seems to be a no no. Thanks/Don

  34. @Don – if you are not trying to do anything too sophisticated, an improvised pressure switch detecting the air flow and directly switching the 24V line might be an approach to consider.

    Could also try and detect magnetic field of current flowing to fan…

  35. Totally cold device! I was wondering if there’s something like this readily available on the market. I want to connect a water sensor to a shop vac to collect winter vehical drippings up off my heated garage floor. Any insight would be awesome!

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.