## 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:

(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.

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.

Sugar Device (author)2017-01-13

good job

But this is better and more safe way to control AC light dimmer

https://www.instructables.com/id/Control-AC-Dimmer-...

and more tutorials and applications

https://www.instructables.com/member/Sugar%20Device...

PauloC91 (author)2016-10-26

Hello,

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

tinek (author)2015-04-02

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

siddhant.singhal.503 (author)2014-12-10

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

dudes (author)2014-10-10

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

UdyRegan (author)2014-09-26

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!

buteman (author)2012-06-16

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.

gabriellalevine (author)2012-06-17

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?

-max- (author)2014-02-20

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*.

tristantech (author)2012-06-17

"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.

gabriellalevine (author)2012-06-17

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 ?

-max- (author)2014-02-20

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)

-max- (author)2014-02-20

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.

gabriellalevine (author)2012-06-17

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

ekpamaku (author)2013-12-17

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

gabriellalevine (author)2012-06-17

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

Wayne1234 (author)2013-03-14

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.)

gabriellalevine (author)2012-06-17

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

mgingerich (author)2012-06-30

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.

GordieGii (author)2012-06-18

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.

memmdo7 (author)2012-11-04

hello , What components should i use to control a 220 v Lamp using Arduino.. and also i would be grateful if you put your circuit schematic of the "AC Arduino dimming circuit" ..thanks in advance

atb_uk (author)2012-06-15

The idea iteself is good but I'm seriously concerned about this circuit design. There is no isolation between low and high voltage parts so the whole circuit including an arduino got potential of 110V. This is really dangerous!. I can see the small hole in the box to plug an arduino power jack, please don't do it as you may blow up your power supply or get electrocution if you touch any arduino part.

gabriellalevine (author)2012-06-15

If you use an transformer based power supply for the Arduino (or 9 V battery) it will keep the AC and DC isolated. I can put an addendum to the post making this EXTRA CLEAR

Also, I am not an engineer and if I am overlooking something, please don't hesitate to respond. I thought that by isolating the 5V (or transformer based) power supply from the 110 V power supply, it WOULD in fact be safe. Thank you for the concern

gabriellalevine (author)2012-06-15

Just to elaborate: if the arduino power
supply isolates its output from
input, then there shouldn't be in any
connection between AC and DC power. The 9V supply's grounded in the bridge rectifier.
So if using a DC power supply for Arduino or a transformer based supply, then input and output are isolated.

So yes, don't supply power from the PC via USB. ONLY use the USB to PROGRAM the Arduino board, when the AC voltage is NOT connected.

Thanks again

duncan_a (author)2012-06-17

Tristantech is perfectly correct in what he is saying - for the sake of safety, you MUST isolate the low voltage DC from the high voltage AC.

An opto-isolator is the obvious method (and probably the cheapest) because to are simply sending pulses to the MOSFET.

If I could draw you a diagram I would (can somebody else provide one?) but imagine all the high voltage AC components on the left and all the low voltage DC components on the right. There is no physical, electrical or mechanical connection between them except for light (within the Opto-Isolator) - that's safe...!!!

People's lives are at stake whenever you use AC mains power.

gabriellalevine (author)2012-06-17

Here is an optoisolator circuit I've used:

http://blog.eletronlivre.com.br/search/label/arduino%20brasileirino%20program-me%20dimmer%20dom%C3%B3tica

I'll respond to tristanTech, sounds like I should probably take down this post as the last thing I would want is to steer someone in an unsafe direction

duncan_a (author)2012-06-17

Even by cutting and pasting that link it just let to a page saying "No Links Found"

Your idea is good, your Instructable is good - it's just the method used that is worrying those of us with more experience of these things - experience often gained the hard way!!!

Rework the circuit with an opto-isolator (for your own safety), recreate the schematic showing the new method and replace the original with the new one, rewword the text and you have it - a good and safe Instructable...

Don't give up, don't be disheartened - OK?

diy_bloke (author)2012-10-19

try: http://blog.eletronlivre.com.br/search?q=dimmer

GordieGii (author)2012-06-18

If you used a bigger box and put the DC power supply inside then there wouldn't be any high voltage outside the box.

gabriellalevine (author)2012-06-17

Yep I see that this shouldn't be used for 120 V AC. super unsafe. Thanks again.

tristantech (author)2012-06-17

No, the AC and DC is not isolated because you connected them. Look at the schematic where the 0V line connects with the MOSFET Source pin and the rectifier. By DC, we mean the low-voltage circuitry that includes the IR receiver, PIC, and anything else connected (like a computer). The DC power source can come from anywhere (battery, transformer, solar, whatever) It's the way you control the transistor that creates the problem.

jfagan (author)2012-06-15

I have to agree with atb_uk, linking mains voltage rails to the low voltage is a recipe for disaster. There should at least be some opto-isolation between the uController and the mains side.

Sorry to be a party-pooper, but I would strongly suggest that no one really attempt this.

diy_bloke (author)2012-10-19

perhaps i completely misunderstand this project, but I do not see why the Arduino must be in the same box as the high voltage parts. It is a on optical driven dimmer am i right? The arduino sends an optical signal to a receiver in the high voltag epart. As long as that is properly wired and insulated there should not be any danger.
Also I see no difference with this project:
http://dmitry.co/index.php?p=./04.Thoughts/06.%20RC%20dimmer so i sthis just something that is copied?

mgingerich (author)2012-06-30

Really awesome project, even if it is potentially lethal.

Hi can we use Arduino Dueminalove (USB ) also for the above.. will it work for this Arduino...?

Ringmeister (author)2012-06-18

Gabriella,

I really enjoyed your Instructable, thanks for posting it.

I do not understand why people get so excited about the dangers of mains electricity. 120v AC is unpleasant to touch but really not dangerous in itself. I used to work for a company that did some work in Morocco and one of the electricians working on the installation would test for live (hot) cables by touching them (he didn't have a voltmeter!). Depending on the severity of the shock he would determine whether the voltage was 220v or 440v! I have had more shocks than I can count including some in the 300v DC range.

I think the real danger here is potential for fire due to overloads, semiconductor failure (mosfet or rectifier) or arcing (poor connections). Especially when controlling a high current device such as a heater.

Other risks for working with "high" voltages/currents include destroying the Arduino, secondary risks like jumping back when receiving a shock and then tripping, falling etc. and not forgetting sparks/arcing resulting in fire or injuries (especially to the eyes).

I am guessing that the Instructable is not intended to produce a consumer product by virtue of the fact it uses an Arduino as a controller making it a very expensive solution. Hopefully other readers will appreciate this.

One thing that I suspect should be avoided with this is attaching any kind of inductive load (fans, motors etc.) as these will result in large back-emf voltage spikes in the order of 1000's of volts (see LTSpice inductive load simulation attached).

To summarise, in my opinion:

1. This ible should be regarded as an experiment.
2. It should not be left unattended.
3. It should protected with fuses in event of a short-circuit due to semiconductor failure or overload.
4. The whole thing should be contained within a fire resistant enclosure.
5. It should not be used with inductive loads.
6. Be aware that your Arduino may get killed!

I have also attached the LTSpice screenshot, the application can be downloaded free from Linear Technologies at http://www.linear.com/designtools/software/

Ringmeister (author)2012-06-18

Oh dear, the images are almost unreadable, I will post some better ones. For some reason I could not get the post "preview" button to respond so had to take a chance the pictures would be ok :(

smokie44 (author)2012-06-15

Would it work with CFLs or other fluorescent fixtures?

gabriellalevine (author)2012-06-15

That's a good question - No, fluorescent's only dim about 5% and by reducing their amperage is NOT the way to dim them. Therefore it actually might shorten the life of a CFL not to give it the full V / Amperage.

Other lights it will work for (halogen, incandescent, etc)

JayGeeBSE (author)2012-06-18

Please note that correct operation of halogen lamps requires that they run near full power. Dimming may shorten their life. The hot quartz envelope causes a chemical reaction between the halogen gas that fills it, and any tungsten atoms that boil off the filament. The compound wafts around until it makes contact with the even hotter filament where it decomposes to deposit the tungsten back on the filament. If you lower the temperature of the envelope the reaction will not take place and the tungsten will simply plate onto the quartz, blocking the light and allowing the filament to get thinner and thinner until it fails.

ROBBIE777 (author)2012-06-17

I like and interests much your work, now I this looking for something like this, but to work with 12 volts DC. What I want is to check the power supply, or to vary the power of a Peltier, and clear with the convenience of remote control. What would the modification to your you would you do to make it work with 12v DC? Best regards

gabriellalevine (author)2012-06-17

for 12 V use something like http://itp.nyu.edu/physcomp/Tutorials/HighCurrentLoads

alextricity (author)2012-06-17

Important note to consider:

With AC, the average voltage will be 120V but the peak is over 170.

stuart_faust (author)2012-06-15

Hi , does anyone have a simular design to this one for the UK or is there just a change in a component to make this work in the UK .

gabriellalevine (author)2012-06-15

That component should work, http://uk.farnell.com/vishay-formerly-i-r/irf720/mosfet-n-to-220/dp/354533, as it is rated high enough for 220 volts

Callum Snowden (author)2012-06-16

Just a note on that part: its maximum rated voltage is 400V so it is OK for UK use I think... :)

uber