AC PWM Dimmer for Arduino





Introduction: AC PWM Dimmer for Arduino

About: I am a physician by trade. After a career in the pharmeceutical world I decided to take it a bit slower and do things I like. Other than my hobbies that involves grassroots medicine in S.E.&P Asia. I have bu...

Before you decide to build this, you may want to have a look at acolomichi's design as well

Warning: this project uses deadly voltages, as well as a sizeable capacitor to store these deadly voltages. Even after you disconnect the circuit from the grid, the capacitor still can give you a jolt to remember!!

Over 3 years ago, I published a simpel TRIAC AC dimmer for the arduino. That proved to be a very popular design. Yet in spite of the simplicity of the circuit the software needed was a bit complicated as it needed to keep track of the zero crossing of the AC signal, then keep track of the time and then finally open the TRIAC. So to avoid letting the arduino just wait for most of the time, an interrupt and a timer were necessary.

So why can't we just use PWM, like with LED's? Well, I explained that in that instructable, but there are possibilities to do that. Someone looking for that would no doubt end up at design by Ton Giesberts/Elektor Magazine that can do PWM of an AC source. This design is on Instructables as well.

That will work, but in spite of my admiration for Giesberts and Elektor, there is something fundamentally wrong with that circuit. I think it is necessary that I explain what is wrong before I come up with improvements. If you are not interested in the technical details, just skip to the next step.


At first glance, the Giesberts circuit seems like a complicated circuit, but we can bring it back to 2 or 3 components: A lamp, and a switch, but as in fact the switching is done in DC rather than AC, it becomes a lamp, a bridge rectifier and a switch. That switch, which is in fact the MOSFET and the components around it is controlled by the Arduino (or PIC or whatever). So, switching that on and off in a certain duty cycle will switch the lamp on and off and if done fast enough the lamp won't be seen anymore as flickering, but as being dimmed, similar as we do with LED's and PWM.

So far so good. The theory behind the circuit is sound. However, the MOSFET needs a voltage on its gate to be switched on and as we cannot get that from an arduino for obvious reasons (it is only 5 Volt, which isnt enough AND you don't want your arduino to be connected to the mains grid), Giesberts uses an optocoupler. That optocoupler still needs a DC voltage and Giesberts is using the to DC rectified AC voltage for that.

giesberts2And that is where the problems start, because he is feeding the gate from the MOSFET, with a voltage that is shorted by that same MOSFET. In other words, if the MOSFET is fully opened the DC voltage coming from the rectifier is completely shorted. Therefore there will be no voltage anymore to put on the gate and the MOSFET will block again. This effect might not be so outspoken by a low dutycycle (= lamp on a low intensity), because of the presence of C1, that will retain its charge for a while and will be receiving new charge thanks to the low dutycycle, but at 25-80% dutycycle the voltage on C1 just cannot be sustained anymore and the lamp may start to flicker. What's worse is that at moments that the voltage on the gate drops, for a while the MOSFET will be still conducting, but not be fully saturized: it will slowly go from its nominal 0.04 Ohm resistance to infinite resistance and the slower this goes, the higher the power that needs to be dissipated in the MOSFET. That means a lot of heat. MOSFETS are good switches but bad resistors. They need to be switched ON and OFF fast. Currently the circuit heavily relies on D1 to keep the voltage on the gate of T1 at acceptable limits while the voltage is swinging between 0 Volt and Full peak At peak the rectified voltage is 230x1.4=330V The average rectified voltage is 230x0.9=207V

If we forget about the smoothing effect of the capacitor for a while and presume the optocoupler to be fully open the average voltage on the capacitor would be 22/88 * 207 =52 Volts and in peak 22/88 * 330= 83 Volts. That it is not is because of D1 and the fact that the MOSFET will short the Voltage.

If the optocoupler is not in saturation and its impedance therefore infinite, the capacitor C1 would charge up to full rectified voltage if not for D1. On average 3mA will flow through R3,R4 and R5 (207-10)/66k which equals a power consumption of 0.6 Watt in the resistors R3,R4, R5

Improvements giesberts3

The problems mentioned with the Giesberts circuit can be remedied by putting the lamp somewhere else: remove it from the AC line and put it in the Drain of the MOSFET. For the lamp it doesnt really matter if it is receiving DC or AC. You could make more improvements, as now there is no need to cater for a a voltage swinging between 0 and 330 Volt

Step 1: AC PWM Dimmer: IGBT or MOSFET

But as I was changing the design, I might as well take it a step further and use an IGBT (Insulated Gate Bipolar Transistor) Simply put, an IGBT is a device that is a MOSFET at its gate and a bipolar transistor at its Collector and Emitter, making it an ideal switch. Thus we can come to the following circuit: igbt-11

The IRG4PC30 acts as a fast switch that either switches the lamp on or off. It needs about 12 Volt on its gate to do that. The voltage divider R1/R2 should put about 13-15 volts* max on the Gate of the IGBT, switching the lamp fully ON. As there might be some fluctuations on the grid 4k7 is a safe value. If you want to be safe, make sure you have an IGBT with a Base Emmitter breakdown voltage of >= 20 Volt and put a zenerdiode of 15 V parrallel to R2. Possible IGBT's are IRGPC40W or IRG4PC30, but basically any will do provided they have a Base emmitter voltage rating of at least 20 Volts When the optocoupler receives a signal, it opens and pulls the voltage on R1/R2 to zero, effectively closing the IGBT. The PWM signal of an Arduino is faster than the 50Hz Frequency so you will basically see the PWM signal modulated on the 50Hz rectified sine wave, making the effective voltage lower. This circuit is ONLY for incandescant bulbs. It is NOT for any inductive load as it is DC biased. With regard to the capacitor C1, I have tested it with 100uF but will probably work with lower capacity as well.


  • Although the average voltage will be 230*0.9, C1 may eventually charge to 310-330 hence 4k7 is a safe value.


Reader acolimitchi pointed out to me that if you add the zener, the 6k8 resistor isnt really necessary anymore, which is true, so the circuit becomes like this:


With regard to MOSFETs vs IGBTs both have their pro's and con's and the voltage and switching rate this circuit is operating under may just be in an overlap of both spectra. Using a MOSFET rather than an IGBT is therefore possible. MOSFETS are generally also cheaper than IGBT's. A tried and tested MOSFET is the STP10NK60Z (Thanks Pavel). This MOSFET has a gate-source breakdown voltage of 30 Volt and has clamping diodes protecting the the gate. Another one that worked quite well is the relatively cheap IRF 730. MOSFETs usually need a bit of a higher voltage than IGBTs to switch so a 6k8 resistor should be fine. If you use a MOSFET without clamping diodes a zener of 15 Volt is adviseable.

I couldnt embed a video, but you will find it here. It is a 60 Watt lamp. The slight flicker you may see when the lamp is turned up, is an artefact. It is caused by my cellphone camera trying to adapt to the changing light intensity

Conclusion: stick to the MOSFET, they are on average 4 times cheaper than IGBT's

Bridge rectifier. I used a 1 amp 400 Volt DIL pack 0.25 euro
Diode 1n4001 or 1N4007 0.10 euro
Capacitor 100uF 350-400 Volt 1.36 euro
resistor 100k 0.5-0.6 Watt (actually it dissipates abt 480mW max) 0.12 euro (play it safe with a 1 Watt resistor)
resistor 6k8 1/4 Watt 0.10 euro
Zener 15 Volt 0.5 Watt 0.08 euro
MOSFET IRF730 or STP10NK60 0.58 euro
Optocoupler 4n35 0.25 euro
Resistor between 330ohm-470ohm (possibly even 1k dpending on the Optocoupler) 0.10 euro

So, alltogether at single piece retail prices the cost is 2.94 euro

Step 2: AC PWM Dimmer for Arduino: Thoughts

Without any input signal the lamp will burn at max.

If you notice that When writing a zero PWM value to the circuit the lamp burns a bit less than when you switch off the Arduino, that means that the 4n35 is still opened a bit. Play around with t470 Ohm serial resistor, maybe you need a higher value.
The 100uF 400 Volt can be quite big. A 50 uF may work as well and maybe even a smaller value. However, you do not want the value to be too small thus as not to be able to deliver enough voltage for the Gate of the MosFet in fast switching.

Should you wonder if perhaps you can use a capacitor of a lower voltage -say 25 Volt- and connect that over the zener/6k8 resistor in order to replace the 400 Volt one... maybe that will work, but the 4N35 will make it lose its charge almost instantaneously and due to the large RC time (remember, there is 100k resistor) it might not have time to fully recharge again. At least it will make keep the MOSFET in its resistive phase longer, leading to extra heat development.

The Arduino has a PWM frequency of about 500 Hz. That is ample enough. My guess is that around 100 would be more than enough. The Attiny85 delivers I think 280 Hz on its PWM pins. Software ofcourse can always elevate that if necessary.

This dimmer is not suitable for inductive loads

This dimmer does NOT need zero cross detection.

Heat development:
I tested this with a 60 Watt lamp at full brightness, without any heatsink: the temperature rose with 9 degrees above ambient after half an hour and an hour.
Then I tried with continous dimming from zero to full and back again.: The temperature rose with 10 degrees above ambient after about 10-15 minutes and stayed like that for the hour I tried.

With a 150 Watt halogen spot the temperature went up 15 degrees. It reached max temperature after about 10 minutes and then stayed the same for the hour tested.

This was measured with a DHT11 sensor directly clamped to the MOSFET

9 People Made This Project!


  • Planter Challenge

    Planter Challenge
  • Woodworking Contest

    Woodworking Contest
  • Oil Contest

    Oil Contest

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


6 Questions


great project, helped a lot.

can you please tell me what modification I can do to avoid turning on the lamps when no input signal

Hello again, your design Is working perfect on incandescent bulbs. recently I changed bulbs to Dimmable Led Filament 6Watt, and it started flickering... any way to work it out to be able to use the Dimmable Led filament ?

3 more answers

Though I am sure I replied, I cant see my reply anywhere anymore,
Anyway, you need to put the optocoupler in series with the 100k resistor

please what is the best way to make it dim when I increase PWM, as now it is full brightness at value 0, and off at value 255?

Well, basically that is a different circuit and I have described it earlier in the comments: what you need to do is to put the optocoupler in series with the 100k resistor; so one end to the 100k resistor and the other end to the gate

Hello, I have a question for your project. I would like to make a 6-channel dimmer if it is possible to use one rectifier bridge for 2 channels in my case, it is DB107 1A / 400V. What would the connection look like?

Oddly I cannot see my reply anymore, though I am fairly sure I did reply.
Yes you can use one bridge rectifier

3 more answers

what about the zener diode? we should repeat also 1 zener diode to every channel ?

Thank you for your answer. I understand now what it would look like. Do I have to choose a bridge rectifier for a larger current or just 1A for 6 channels.

I am a bit puzzled now whether you want 6 or 2 channels, but in fact it is rather simpleas the only thing you need to repeat is the FET, the voltage divider and the optocoupler with series resistor

your circuit is too dark, I cannot see it


hey, this is what have been i looking for. Now, if i would like to add more than 1 lamp, am i need more than 1 mosfet? or is it enough with just one mosfet?

Hi !

A great project and perfectly explained ... something I've been waiting for a long time ago and found.I have a small question - will the STP10NK60 transistor with a heat sink be proper for a 600W bulb ?... of course, the rectifier bridge will be suitable for the current consumed.

Maybe someone tested this transistor with loads above 150W and is able to write how it works, which would help me very much before possible failures :-)

I am asking for loads above 500W because I have some old bulbs from the 60's (about 500-600W one) which look great dim and I would like to control them with Arduino.

1 more answer

Thank you for your kind words.
the STP10NK60 can deliver 10 amp so with 220Volt, the <3 amp for a 600 Watt lamp is OK.
As far as the heat goes, yes I would advise a heatsink.
The heat developed in the STP10NK in optimal conditions at 10 amp is 7.5 Watt which would be OK, but the STP ofcourse is not always under perfect conditions, for instance when it is switching on or off, the dissipation briefly can go up. To minimize that, I designed the circuit to switch as fast as possible as it is during the switching the Rds(on) can increase and thus the dissipation will increase.
That means also that at low settings (frequent Switching) the dissipation at the one hand will go up (coz of the switching), but on the other hand will go down (coz it is OFF most of the time)
Not sure why you specifically ask about loads above 150 Watt.

Hi, thanks for sharing your knowledge,
if we want to use ac motor, what if connect anode of D3 to one of main power lines?
just a little offset on ground?

My circuit does not have a D6. I admit due to automatic numbering the components did get a different number sometimes, but there is no D6.
Are you sure you mean my circuit? Or are you talking about the Giesberts circuit that I described the drawbacks of?

1 more answer

Sorry i meant anode of D6 not D3

hey, its very good tutorial, my question is, is it possible to control speed of induction motor using this circuit by just replacing the lamp with motor?


Hi, i made it but my lamp is not at brightess while there is no PWM input. As i measured its just received 100 VAC. I just replace the 100uF with 120uF and use IRF730 as MOSFET. I have no idea whats wrong with my circuit. I hope u will reply this, thanks.


Hi and thank you so much for the tutorial!

So i have a question, i want to dim the voltage on a heater resistor, if i change the incandescent bulb for the resistor, will this circuit dim the voltage on the resistor?
Thanks a lot.

Ah, I see what you are driving at, you want the outcome of a DHT22 reading to be translated in a setting for the PWM dimmer.That' s simple, just read the DHT22 and map the pitcome to an analogWrite value between 0 and 255

There is no sketch, you need to send a PWM signal to the FET. Not sure what a DHT22 has to do with it

Hi diy_bloke

As I mentioned before, I had "high temperature" problem for 100k resistor. So I put 3 100k resistors in series then the matter got a little better. It seems as long as you put 15V zener in the circuit, gate voltage will be near 15V and the 100k resistor (in my case resistors!) just regulates the current with no (maybe little) effect on gate voltage. Am I correct? (my background in electronics is near zero and it is my first try in this field, so forgive me if I neglected some basic facts)

1 reply

The main issue is to be able to provide enough voltage to the gate of the FET. as long as you reach 15 Volt and still have a somewhat reasonable current left it will be fine.
The thing with FET' s is that you need to use them as a switch, not as a variable resistor. That means you want to switch them fast. The 100k resistor(and in your case 300k) will form an RC time with the input capacitance of the FET that could be around 9-20pF. It is best to keep that RC time as low as possible, so with a 300k resistor, the FET will switch a bit slower, but I think it is still all reasonable

Hi diy_bloke!

Thank you for your sharing this circuit. I tried this circuit with bulb light 60Watt, it worked so smooth. My circuit have to work month by month and year by year. When I tested with bulb light 60Watt for a while Resistor 100k turned hot. And I tried it with two bulbs light 60Watt,Resistor 100k burned.

Can you help me this problem? where am I wrong?

I use this circuit for my incubators. One incubator has 5 bulbs light.


Bridge rectifier: RS507

Diode 1n4001
Capacitor 330uF 350-400 Volt
resistor 100k
resistor 6k8
Zener 15
Optocoupler 4n35 0.25 euro
Resistor between 470ohm.

4 replies

Sorry about that. Nevertheless I am a bit surprised if this would be dependent on the load of the lamp becayse that does not influence the current through the 110k resistor at all.
At most the current through the 100k is some 2.3 mA (roughly, probably a bit less), the heat dissipated in the resistor thus is a little over 0.5 Watt. So indeed the resistor will get hot. At best you use a 1 Watt resistor there. Apologies if I did not make that clear in the text

"Although the average voltage will be 230*0.9, C1 may eventually charge to 310-330 etc."

So the peak current should be 3.3 mA. Why 2.3 mA?

be aware though of using it as an incubator. The construction is such that if the input is lost, the lamp will be full on and you will cook yr eggs. Ofcourse if it was the other way around, your eggs would be too cold, but geberally eggs are better suited to expereince a period of 'too cold' than a period of 'too hot'

hi diy_bloke

how did you calculate the max power of 100k resistor to be 480 mW? it seems if you use the max voltage (suppose 300v) it should be 0.9 W. Maybe this is the problem with my 0.5 W resistor getting too hot.

thank you again

2 replies


As I understand, the effective voltage is some 207 Volts UxU/R then gives 429mW. But I could be wrong.
It won' t harm to use a 1 Watt resistor. Always better to have some space in the specs

Thanks alot diy_bloke

I thought to determine wattage of a resistor, one should consider the most critical situation, i.e. take the peak voltage 330 V not 207 V. As you mentioned, It seems I am wrong because you (and some others also) made the circuit with 0.5 W resistor and it works flawless.

@John123456, I received your question in my mail, but I do not see it appear anywhere here.
Anyway, the max current of the bridge depends on how big a load you want to use it for. So if you have a 1 amp bridge, a 220 Watt lamp is the max

Hi diy_bloke!

To view all your comments in one place please visit your Comment Tracker:

From: jon123456
Date: May 17, 2018. 5:01 AM
Subject: have an even question about the components of the system whether you used a capacitor for 400V or 0.5W zener diode is enough, I used the db107 rectifier bridge has it max 1A or is it a bit not too little?

Nice circuit @diy_bloke! I would build it with a TRIAC based circuit but my input signal is PWM and I cannot change that, so I ended up on this page. I need to build 4 of them, each controlling a 40W incandescent bulb.

I have 2 questions: Since my bulbs have a rather low power requirement, is there anything you would change to make it more safe?

Also for safety reasons, I modified it to be a normally open circuit (no Arduino signal => lamp off) since the circuit will be powered 24/7.

Would you add some fuses or thermal cutoffs to make the circuit safer and if so, where?

3 replies

what modification have you exactly made to make it NO circuit ?

Sorry for not noticing your request sooner. Ofcourse I do not know what changes Alexander made but I presume he put the optocoupler between the 100k resistor and the gate

Alexander, the power of th lamps isnt really anything that determines safety, so i cant think of any changes on that aspext.

A fuse can be put anywhere in the supply line, either in the AC line or t the DC line.

I have not tried myself but supposedly people have put the optocoupler in series with the 100k resistor to reverse the action