0% found this document useful (0 votes)
196 views

AC PWM Dimmer For Arduino

This document provides instructions for building an AC PWM dimmer circuit for controlling incandescent lights with an Arduino. It summarizes an existing circuit design and identifies issues with it, then proposes improvements. The improved circuit uses an IGBT or MOSFET transistor controlled by an optocoupler to switch the AC power to the light on and off rapidly, allowing dimming through PWM. Component values are provided along with an explanation of how the circuit works and potential variations.

Uploaded by

Javier Peres
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
196 views

AC PWM Dimmer For Arduino

This document provides instructions for building an AC PWM dimmer circuit for controlling incandescent lights with an Arduino. It summarizes an existing circuit design and identifies issues with it, then proposes improvements. The improved circuit uses an IGBT or MOSFET transistor controlled by an optocoupler to switch the AC power to the light on and off rapidly, allowing dimming through PWM. Component values are provided along with an explanation of how the circuit works and potential variations.

Uploaded by

Javier Peres
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

instructables

AC PWM Dimmer for Arduino

by diy_bloke

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 nally 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 rst 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 recti er 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 o in a certain duty cycle will switch the lamp on and o and if done fast enough
the lamp won't be seen anymore as ickering, 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 recti ed AC voltage for that.

AC PWM Dimmer for Arduino: Page 1


And 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 recti er is completely shorted. Therefore there will be no voltage anymore
to put on the gate and the MOSFET will block again. This e ect 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 icker. 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 in nite 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 recti ed voltage is 230x1.4=330V The average recti ed voltage is 230x0.9=207V
If we forget about the smoothing e ect 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 in nite, the capacitor C1 would charge up to full
recti ed voltage if not for D1. On average 3mA will ow through R3,R4 and R5 (207-10)/66k which equals a power
consumption of 0.6 Watt in the resistors R3,R4, R5

Improvements

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

AC PWM Dimmer for Arduino: Page 2


AC PWM Dimmer for Arduino: Page 3
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)
AC PWM Dimmer for Arduino: Page 4
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:

The IRG4PC30 acts as a fast switch that either switches the lamp on or o . 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 uctuations 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, e ectively 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 recti ed sine wave, making the e ective 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.

AC PWM Dimmer for Arduino: Page 5


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 ne. If you use a MOSFET without clamping diodes a zener of 15 Volt is adviseable.

I couldnt embed a video, but you will nd it here. It is a 60 Watt lamp. The slight icker 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
BOM:
Bridge recti er. 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)
AC PWM Dimmer for Arduino: Page 6
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

AC PWM Dimmer for Arduino: Page 7


Step 2: AC PWM Dimmer for Arduino: Thoughts

Without any input signal the lamp will burn at max.


AC PWM Dimmer for Arduino: Page 8
If you notice that When writing a zero PWM value to the circuit the lamp burns a bit less than when you switch o 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

AC PWM Dimmer for Arduino: Page 9


Olá amigo, muito bom seu circuito! Fiz um dimmer com Triac para controlar a velocidade de um
motor AC de 1CV, mas notei que o Triac esquenta muito. Será que o seu circuito funcionaria
neste caso? Agradeço sua resposta (renearduino)
I am using this on 220v stringer LED lights. The led's tend to flicker on low duty cycles below
60%.
So I had to move the capacitor over the positive and negative of the rectifier. Now I can go as low
AC PWM Dimmer for Arduino: Page 10
as 1% without flicker.
The mosfet I am using has no heat to it at any duty cycle. I you have a heatsink on, DO NOT
touch the heatsink. It not hot, but has 330volt of DC kick.

Hi Bloke, thanks for this great circuit, if I changed the MOSFET and the bridge with higher power
ones and add a suitable heat sink, so can I use this circuit for higher power loads like 220 AC
heaters (about 5000 Watt)?
Looks good! I was thinking about using this circuit but uprating it to make an immersion heater
controller for use with solar panels. I figure that together with a house import/export sensor,
dimming a standard immersion heater down to 500 watts through a smoothing inductor should be
about right for that application. I'll try to do an instructable if I get it to work.
Looking forward to that instructable. Was just wondering though that if you use solarenergy you
do not need the AC part.
A FET with some PWM would suffice ( but ofcourse a large part of my circuit is just that)
1st off all I love this post, I made your old design once. but I think this is much better no more
interupt pins ;-)

So I try to make the circuit 2 channels to drive 220v Cooling fans for a reef tank.
I'm bit new so I was wandering if someone could have a look if This will work.
most of the parts I used double because I'm not sure if 1 Cap and the 15v zenner and diode
would work. Also I added 2 Relay switches just to take sure power is off when not needed.

Cheers

Sorry for my late reply. Thank you for your kind words
Your circuit is a bit small on my phone so i can't say much about it but i hope you have the
answer already
Thank you for your kind words. Your circuit is a bit hard to read, but it should be OK if you just
copy the circuit behind D1
How can i alter the design so that it may work with LIGHT bulb and FAN

Fans are inductive, so you'd need to add a flyback diode across the load to the power rail or
something like that otherwise you'll overvolt the semiconductor from the kickback during
switching transients.
Hi!
I had just a part of the circuit and already had a problem. I had the bridge, the light (placed in the
ac part just for test) and the control element (I tried TIP150 at first and then fqp19n20) and just by
turning on and off the AC source a cpuple time, the protection diode in the control element blows.
Does anyone know why?

Thanks

AC PWM Dimmer for Arduino: Page 11


Sorry to hear that. I am a bit confused though by your question. What 'part' was it that you built?
When you say 'protection diode' do you mean the zener?
Also a TIP150 is a darlington BJT a d is totally unsuitable for this project
Thanks for your reply! Yes I am in a 110volt country. What I had was the AC source, diode bridge,
the light and the mosfet. Nothing was pluggued to the gate pin. The protection diode I talked
about is in the mosfet, between Source pin and Drain pin.
Furthermore the fqp19n20 is a 200volt mosfet, so unless you are in a 110volt country that might
not be a suitable FET
After second try and soldering all together, it works! All electric parts were taken from old PC
power supply, then i go to parts store and buy 1W 100k resistor.
Related to topic question: any way to reduce PWM noise in heating element? Filter capacitor can
help, or i need LC?
Anyway, thank you! Works better than dimmer with zero detection, 10A mosfet stay cold.
Hello, I would like to ask why the light does not change when I use PIC to let it specify the PWM
output
Hi Bloke , your circuit is wonderfull ,please tell me , is it working on induction load like Ceiling Fan
? i want to control my fan through mp3 ir remote (+, - ) Buttons .
kindly ,confirm me is this circuit will work on induction load ?
Which is the sketch file of arduino ? please upload it
You cannot use this for a ceiling fan as it feeds DC to the load.
You keep asking me for a sketch. There is no sketch as I cannot foresee what each individual
wants to do with this circuit, but the only thing you need to do is to write a PWM value to the
circuit
Thanks for your reply.

Thank you for this awesome circuit


I have a problem as an trying to dim 500 watt light with irf740
I changed the bridge rectifier to 6amp 800v and diode to 10a10

But the irf740 burnt


Is there any more changes I need to do to make it works?

Thank you
Mohammed, the IRF740 should be fine as it is suitable for some 6 ampere.
Provided you work with 220 Volt, it draws about 2.3 ampere and disipates 3 Watts when in
saturation.
So the only thing I can think of is that somehow you are not fully opening the IRF740. Have you
used the same components as I advised? what processor do you use to trigger the optocoupler?
diy_bloke
Have you used the same components as I advised?
yes sir same components
what processor do you use to trigger the optocoupler?
I am using Arduino nano to trigger the optocoupler
If you are sure your circuit is correct, the only thing I can think of is that either you are not
opening the MOSFET completely, or the MOSFET is broken.
Please do the following (but be careful not to touch the circuit when it is plugged in).
Remove your Arduino: lamp should be ON
Measure the voltage over the lamp

AC PWM Dimmer for Arduino: Page 12


Measure the voltage over the gate
Rather than using an Arduino, try to put 5Volt on the input
Check the voltage over the optocoupler
Measure voltage over the lamp
measure voltage over the gate

Again, be careful when the circuit is plugged in and mind you that the 100uF capacitor may carry
a charge for a short while even after unplugged

BTW the circuit is working perfectly when i use 100W light but when i use 500w light the light
burn at full and the MOSFET become very hot, and when i disconnect the load and attach 100w
light again the circuit is become not responding (no dimming at all just the light in fully on) till i
change the MOSFET and its back to work again. I have tried it with 5X IRF740 and its all the
same thing
basically what you say is that the 500 Watt lamp kills your mosfet. That should not happen.
Earlier i asked you to do several measurements. What came out of those?
I make ac dimmer, input ac 220v but output only 0-110v. Whats wrong? Please help me

That is indeed odd. If it is indeed 110 Volt, I would think you may have made a wiring problem, or
may have a faulty FET. What FET are you using?
I will connect a DC motor instead of lamp, which needs to work above 230V DC and also above
20 A. Motor's RPM is between 15000-20000.
It' s called spindle motor.
I want to drive it and also control it with pwm.
I don't know how to control such a high level DC motor.
Can you help me?
I need someone to help me!
I have little experience with that kind of motor, so I am not the best source to ask

Awesome circuit

For those who interested in trying this circuit normally-open ( when you turn the arduino off the
lamp will turn off accordingly) this is the schematic (thanks to Spehro Pefhany of
electronics.stackexchange.com):

Hello
If anyone ... and i will guess most... have the need of a normally open circuit based upon this
schematic; that is capable of being driven by either a pir or a arduino pwm or simply by a low
current positive 3.3-5V coming from a door switch or something; then .. there ya go ... needless to
say capable of 10-350V input AC or DC , and load either led or noninductive load as kindly
indicated by the guest.

AC PWM Dimmer for Arduino: Page 13


Are you sure your circuit is correct? It seems like your BSS123 will never get anygate voltage

+1

Hello,

I see your point and is very valid.


The circuit is working in this configuration with no visible stability issues.
I had a 10k resistor to the positive rail upon designing , to achieve just that: keep the gate
suspended; but i guess foolishly removed since it made no visual difference in the stability of the
circuit.

To make things short a 10 K to the positive rail or bss's drain was my original approach.
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.

Ardian, somehow your question escaped my attention. Apologies.


Could you perhaos measure the voltage on the gate (please be careful) and let me know what it
is?
its 15v, on D1 around -130Vdc, on the load around 100Vdc.

-130V ?? How can you measure a minus voltage there??


Anyway 15 Volt should be enough to open the fet.
Can you check your connections. If those are OK, I start to doubt your FET
Yes, its -130Vdc, at capacitor the voltage is 330Vdc, so at the load just 200Vdc.

I am really lost at what and how you are measuring.


there cannot be a minus voltage of 130.
you say 330 volt at the capacitor and -130 volt at D1 that is just physically impossible.
The "So 200Vdc at load" I do not understand other than that you deduct 2 voltages of which I
have no idea where you measured one of
Anyway If there is 200 Volts over your load, then it is ON.
Where is the 110 VAC that you measured coming from?

I am more than willing to help but what you write makes no sense to me.
The connection is OK

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.

AC PWM Dimmer for Arduino: Page 14


Christian, apologies I overlooked your question. Normally I try to reply asap, but yors escaped my
notice.
An incandescent bulb is almost a pure ohm resistance so yes yoy can change it for a resistor
Hi!! Thanks for this project..
Can u send the sketch for me? i need that sketch because my sensor (dht22) can't read the data
when i combine it.
[email protected]
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)
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.
BOM:
Bridge rectifier: RS507
Diode 1n4001
Capacitor 330uF 350-400 Volt
resistor 100k
resistor 6k8
Zener 15
MOSFET IRF840
Optocoupler 4n35 0.25 euro
Resistor between 470ohm.

AC PWM Dimmer for Arduino: Page 15

You might also like