AC Arduino Dimming Circuit

89,135

103

46

Published

Introduction: AC Arduino Dimming Circuit

THANKS TO CONCERNED VIEWERS, I HAVE LEARNED THAT THIS IS NOT SAFE AND SHOULD NOT BE REPLICATED.
SO PLEASE DONT TRY THIS :)

THANKS TO EVERYONE WHO COMMENTED, I LEARNED A LOT 
I am not an engineer, just an experimenter and hacker and prototyper etc, so, thanks to people who know a lot more than I do, I learned that this is not safe to use 
------------------------------------

Have you ever wondered how you can use a remote control to dim your own lights, to control a window fan, or to regulate the heater?

Here's a simple circuit using Arduino that makes this possible!
It uses ONLY two electrical components.

This is recommended for someone who has some experience with Arduino and electronics.

As with anything that uses AC wall power, this could be dangerous if done hastily.

Done carefully, it could also be really simple and fun.

NOTE:  This can only be used to dim a unit that runs off of a transformer-based power supply, ie something that doesn't run off of 120 V, but 12, 24, or 48 Volts. 







Step 1: MATERIALS

WHAT YOU WILL NEED: 
Solder iron, wire strippers, breadboard or perf board, wires, 9V battery, IRF730 transistor, bridge rectifier,  Arduino, infrared detector (like this one), SONY universal remote control (like this one)

Step 2: Get an IRF730 From Mouser

I adapted this method from info from Dmitri Grinberg’s post on Hackaday, “Lamp Fading and Remote Control for the Lazy”.
But I had been trying for a number of weeks to perfect this, as in, find the correct transistor that would not overheat or burn out (one that is rated for a high enough voltage since it’s using AC 120 V). I followed this circuit from Dmitri’s blog, except instead of the IRF 250 I used an IRF730.

You can purchase those particular transistors at the above link from Mouser for under $2. 

At first, I was using the IRF 520, with a 100 V drain source voltage and a 9 amp continuous drain current. It worked fine at first, and then it burnt out (there was connectivity between the gate-source and gate-drain). So I got an IRF540, with a 100 V drain source voltage and a 33 continuous drain current. This similarly worked at first, then burnt out.

Finally, I used the IRF730 which works pretty well so far! And doesn’t burn out – it is rated upto 400 V (which far surpasses the 120 V wall voltage in the US).

Step 3: Prepare the AC Power Cord

First: you will clip an AC power cord (OF COURSE, WHILE IT IS NOT PLUGGED IN!!)

I like to use this type of cord (see the main image here), that is ungrounded (it has only two strands and two prongs), it has some places to plug in an AC device, namely your lamp or fan, or whatever you will be dimming.  

There are two strands, a ground and a live. Feel the strand that has some striated texture:
This is the cord you will cut.

Once you cut it, strip away some of the rubber insulation around the wire, leaving about 1/8" copper wire hanging out, enough to plug into a perf board or a screw terminal (which I highly recommend using, as AC current should be very secure). 

Step 4: Here's the Circuit:

Follow this circuit. Instead of the PIC I use the Arduino. 

(better schematic coming...)

See the photograph of the circuit as well for reference. 


Step 5: Upload the Code

I adapted the IR remote control part of the code from Ken Shirff's IR Remote Control library, found here.

Download the library at the above link. Once downloaded, Drag the library folder into your Documents/Arduino/Libraries folder. Restart Arduino. 

Here is the link to the simple dimming code used with the infrared detection sensor. I used a universal sony remote as the transmitter.

Step 6: Put It in a Box.

Put everything into a box, and make some holes for the AC wires to poke through. Screw them into the screw terminals. 

Put a 9 V battery into Arduino to turn it on. 

Step 7: Try It Out!

This will work with an inductive load (like a fan), as well as a resistive load (like a light or a heater). So it will work with your ceiling fan, window fan, heater, lamps, etc.  It is especially good for a light that you want to dim but has no dimming-capabilities. 

Share

    Recommendations

    • Clocks Contest

      Clocks Contest
    • Oil Contest

      Oil Contest
    • Casting Contest

      Casting Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    46 Comments

    Hello,

    You could post the mounting scheme breadboard. From the pictures this very difficult

    omg that pictures are so unclear can you please make another picture and update it or replay here I'm bit confuzed about that diode part ANYWAY you are fricking AWESOME I need this so bad woo :D

    hey. can you please post the schematic using the arduino. thanks

    So does this convert AC to DC and actually output DC? Or did I miss something and it outputs AC?

    I was just about to create something similar for my glass storage cabinet but after pondering about it, I would rather not because I am not expert in this electronics field. I agree that it is indeed very fun to try out new things and produce something new by yourself. However, safety needs to always come first before achieving anything else. Thus, I have decided to leave it to the professionals. Nevertheless, you have a really creative mind!

    Good to see your efforts and what I say below is in no way meant to discourage you but rather to help you and others.
    We all make mistakes and it can be a way to learn. Better not to kill ourself in the process though. :-(
    Just so you know for anything else you might build here is why you had problems with the IRF520 and IRF540. You are using the bridge rectifier to turn the 110volt A.C to D.C. When it is 110volt A.C that is what is called the R.M.S voltage which means the average value of the voltage. For 110volt A.C you will have a peak voltage of 1.414 x 110 volts = 154 volts. Rectifying it does not reduce that voltage by more than 1.2 volts ( approx - due to the diodes in the rectifier ) so you are subjecting the transistors to way more than their specification so it is no wonder they failed.
    So they could have easily handled the current which for your 150 watt bulb ( less than 1 amp ) they could not handle the voltage.
    I agree with other comments about the danger of plugging in the low voltage supply while it is connected to the mains.

    2 replies

    Yep I see now that this is unsafe . I am wondering if it is safe to use to modify a 12 or 24V AC power supply?

    What type? Linear or switch mode? And of the switch modes, which class? Flyback, buck, boost? If you know the design of the PSW well enough, yes*.

    "This is recommended for someone who has some experience with Arduino and electronics."

    "At first, I was using the IRF 520, with a 100 V drain source voltage and a 9 amp continuous drain current. It worked fine at first, and then it burnt out (there was connectivity between the gate-source and gate-drain). So I got an IRF540, with a 100 V drain source voltage and a 33 continuous drain current. This similarly worked at first, then burnt out."

    A 100V max transistor to control a 120Vrms or 169.2Vpp signal? Come on!

    I'm sorry that I have to say this, but whenever I see a poorly designed circuit on Instructables that threatens the safety of anybody thinking of attempting this project and is a bad example of basic electronics guidelines, I feel that I have no choice but to call it out. And frankly, I don't think that you have the faintest clue as to what you are doing.

    1) Isolation. You should never have low voltage electronics at the same ground potential as AC mains. The 5v powering the electronics must stay isolated and cannot be electrically attached to the AC. The proper course of action to take is to use an optoisolator to control the switching element (in your case the IRF730) without needing a common ground. Why? Because it creates a grounding hazard. The Arduino and all connected devices (PC) are at mains ground potential.

    2) Wire gauge. In the last picture of step four you show the IRF730 attached to the AC cord with small hook-up wire (maybe 22 or 24 AWG). Then, you show a massive space heater being attached to your circuit. Wire has current limitations (maybe an amp or so); you can't run a 1,000W+ space heater (or any large load) through that dinky wiring. And yes, the full mains current comes through those wires. Follow the electron's path through the diodes and you'll see.

    3) Switching. The proper way to dim an AC load is to use a TRIAC device. A zero-crossing detector is employed to sync the microcontroller to the AC waveform. The TRIAC clips off certain portions of the waveform to dim the load. In your case, you're sending some random pulse width modulation signal to the transistor, causing it to clip off random bits of the waveform. I bet that the lights often flicker when you adjust the brightness.

    4) Heatsinks. Your transistor is switching a major electrical load. You need to affix a large heatsink to the metal tab of the transistor (that's why it's there). The heat sink will dissipate the heat that the heavy current is giving off.

    5) Enclosure. Your clear box is what we call a "Rat's Nest". This jumble of wiring is bad for low voltage electronics because you can't find anything, but it is deadly when using AC mains voltages. Because you don't have any strain reliefs and a breadboard, it is too easy for wires to come loose and short out or come in contact with another wire. High voltage projects need to be in a neat case with soldered connections.

    6) Fuses and safety precautions. Since you have a device with a current limit (Transistor) in series with a potentially heavy load, you need to insert a fuse to protect the transistor from burning out.

    I know that I'm being picky, but when you publish a project for the world to see, it has to be done right. There are simply too many people out there who don't know any better than to learn from or try this.

    10 replies

    And thank you for that, I see what I was overlooking. Is this therefore safe if you use it to modify a device, like a lamp, running off a 12, 24 or 48 AC power supply ?

    One thing I just thought of that will make this unit 1000's of times better is the implementation of a proper solid state relay. These are *specifically* designed for this exact purpose: to control mains power with low-voltage electronics. They are rare to find in household electronics due to the per-unit price compared to triacs, but with it, that alone will be enough to make this safe (and of course a nice, clean PCB etching of everything onto a PCB. It is actually not that hard to do, although I never had too much luck, I did not try hard either)

    If you implemented the use of an isolation transformer, this will be somewhat safer. Also, for a permanent unit, wired must be soldered or have solid screw terminals. To add additional safety, add either a fuse in-line, a current limiting ballast, or a control loop to regulate (and restrict) current flow (All 3 to really help limit current!). Also, as he said, use a generously rated 200Vds 15A MOSFET or BJT. As long as the electronics are enclosed properly, having them operate at mains potential is fine, as long as there is no electrical connections running from the inside to the outside, like a USB or the like.

    Also, the wires running to the MOSFET should be the same gauge as the extention cord, and if not, they should always be kept as short as possible.


    Do you recommend that I take this post down? The last thing I would want to do is steer someone in an unsafe direction.

    "And frankly, I don't think that you have the faintest clue as to what you are doing."

    I'm not sure what you mean by this. I have already explained that I am not from an electrical engineering background. I am a hacker and a programmer and I do a lot with electronics, and I use Arduino. For me, this has worked, and I have built this circuit a number of times. I used to use an optoisolator : http://blog.eletronlivre.com.br/search/label/arduino%20brasileirino%20program-me%20dimmer%20dom%C3%B3tica
    like that circuit but thought from http://dmitry.co/index.php?p=./04.Thoughts/06.%20RC%20dimmer this site where I found this circuit that this would be a fine way, and it worked.

    "A 100V max transistor to control a 120Vrms or 169.2Vpp signal? Come on! " I was following the circuit on http://dmitry.co/index.php?p=./04.Thoughts/06.%20RC%20dimmer website, from his post and video it seemed to work . So I got the right component and the circuit has worked for me, and as opposed to a triac / optoisolator circuit I've built, as linked to above, this one does not seem to flicker at low light level.

    Anyway, I thank you for your concern, and I am happy to take down this post. Please let me know your thoughts

    Hi gabriellavine,
    Is it posible to see your schematic and part list? Thanks in advance

    I see that what http://dmitry.co/index.php?p=./04.Thoughts/06.%20RC%20dimmer he is using it for is also not 120 Volts. So ... yes, I had built something quite unsafe. Thank you

    I beg to differ with Item 3.... With large loads a TRIAC is fine... BUT... at low loads, the TRIAC will not reliably trigger, and, if the load is less than 8 to 10 watts, can become downright unstable. With low power loads, the above approach is the ONLY approach (short of a Variac) that will work reliably.

    The circuit needs a little more refinement, though...
    A "zero-crossing circuit needs to be added to synchronize the micro-controller with the AC mains and the PWM overall period should be a few micro-seconds short of 8.33 mSec (in the us - 10 mSec in Europe)

    The PWM will "fire" twice each cycle of the AC mains (once for the positive half of the cycle and once for the negative half (hence the need for the zero crossing detector.)

    I have made an addendum, to the TOP of the post, that this should NOT BE REPLICATED as it is unsafe. thanks again for the concern

    You could probably redo this in a perfectly safe way. An optocoupler, some fuses, a heat sink, and thicker wire sound like they're the only real things you need.

    Item #3 is wrong.

    High frequency PWM (as is used in this project) is the norm in industrial AC control. TRIACs are used in household dimmers because they work with an extremely simple (and therefore cheap) control circuit. As long as the switching frequency is at least 300 Hz there shouldn't be any flickering. The MTSpice screenshots seem to show this is the case.

    The rest I pretty much agree with.