AC Arduino Dimming Circuit





Introduction: AC Arduino Dimming Circuit


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. 


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. 



    • Pocket-Sized Contest

      Pocket-Sized Contest
    • Pro Tips Challenge

      Pro Tips Challenge
    • Science of Cooking

      Science of Cooking

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





    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.

    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.