AC dimming with PWM and Arduino

dim-lampAlmost 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.

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.

GiebertsAt first glance, it 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  teh 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 230×1.4=330V
The average rectified voltage is 230×0.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

giesberts3The 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

But as we are changing the design, we 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-mosfet1The IRBT 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.


igbt-mosfet2 (1)

However, if you add the zener, you dont really need the 6k8 resistor anymore:


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

Note: Peak and average voltages are calculated with the following formulas:
CodeCogsEqn (2)

CodeCogsEqn (3)

Thus for 230 Volt Vp=323.86 Volt and Vavg=206 Volt

Video here

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

71 thoughts on “AC dimming with PWM and Arduino

  1. Hi, thanks a lot for this. I made the elector design and had much problems with it. It only regulated a small range and the FET got really, really hot. I tried a lot of suggestion but nothing helps. I made the change you propose and that is really not more than putting the lamp somewhere else and now it works great. You are great

  2. Hi, thank you very much for this design, I am a little noob in hardware design so i got to ask, how much load can this circuit handle, I have 5 incandescent 100 W bulbs in series and I would like to know if this circuit is capable of handling it, its on 127V at 60 Hz, Thank you.

  3. Hi, thank you very much for this design, I am a little noob in hardware design so i got to ask, how much load can this circuit handle, I have 5 incandescent 100 W bulbs in series and I would like to know if this circuit is capable of handling it, its on 127V at 60 Hz, Thank you.

    1. if you have 5 bulbs in series and these bulbs are standard 127 Volt bulbs, they may not give much light.
      much depends on the IGBT that is being used and the heatsink you are using.
      If for instance you are using the IRG4PC30, that has a maximum current of 31 amps so ideally that could be used to switch 31×127 Watt if properly heatsinked.
      However, it can only dissipate 100 Watt. As the Vce on is 1.59 Volts at full power (31 Amps) that would be 42 Watt, so that would be OK.
      Keep in mind though that when the temperature rises to say 100 degrees, the max collector current is only 17 Amps, So I would definitely not go above that, but that is still 890 Watts
      Your 5 100 Watt lamps however will not put out 500 Watt as you have them in series. To get 500 Watt from it you need to put them parallel.
      If you put them in series they will put out much less
      At 127 Volt your lamps will draw 0.78 Amps. That means they have a resistance of 162 Ohm.
      If you put those in series that will be 814 Ohm. On 127 Volt that will only be 20 Watt for all of them together. Really no sense in putting them in series. Put them parallel

  4. I have problem with this circuit. I made it and tried to use for two 100 W incandescent bulb and I used very big heat sink for IGBT, but IRG4BC40UP was destroyed after half hour of working. I also used MOSFET IRF840 and it was destroyed too. I dont know what is the problem.

    1. I am not really sure how that happened. did you use the MOSFET in the same circuit as the IRG4BC40UP? (I did not test it with a MOSFET)
      did it happen af full blast or at a dimmed value? Did it regulate correct until you blew the components?

    2. I gave it some more thought and pulled up the datasheet. I am using a 4PC30, you are using a 4BC40 but that really should not be the source of the problem.
      Your IBGT can take 12 Ampere so no way could that have killed it, So the only thing I can think of is that Heath killed it (read power dissipation).
      I have pulled up my circuit again and ran that with a sinusoid PWM value for about an hour with a 100 Wat lamp. Yes gets fairly hot but was still going.

      Your IBGT should be able to dissipate 160 Watt at 25 degrees but that quickly diminishes once the IBGT gets hotter (only 65 Wats at 100 degrees).
      the dissipation as you probably know has nothing to do (or at least not much) with the Wattage of the lamp but everything with the speed of switching. Ideally the IBGT works as an ON/OFF switch so it is either fully open and should not dissipate that much power, or fully closed and then it should not dissipate much power either.
      Teh danger is in between if the switch doesnt go fast enough there is period in which the IBGT acts as a resistor and then it can dissipate power.
      The VCEon is 1.5 Volt so even at 200 Wat (lets say that takes 1 amp) the dissipation in the IBGT is only 1.5 Watt.
      If the gate voltage is too low, the max collector emitter current is limited and the dissipaition goes up, but even then I reckon it is about 20 Watt that gets dissipated.
      Can you get me the following measurements (without IGBT) if you do not put a signal on the entrance, then what is the voltage over R2? Then please put 5 Volt on the entrance and measure again over R2.
      Please let me know

  5. Hi. As I understand, simply applying PWM and switching AC loads on and off will not lead to predictable dimming so we need to detect zero crossings. You have explained this well in your blog 3 years ago. I wonder how this design works without having a zero crossing detector. Please help me understand.

    1. The difference is that in this case you feed the lamp with a DC voltage (albeit one with some peaks) So there actually is no zerocrossing. Also The IGBT unlike a triac will not switch off.
      With the triac dimmer, one would open the Triac somewhere within the sinusoid cycle. As soon as the zerocrossing occurred, the TRIAC would switch itself OFF.
      With a frequency of 50Hz the full cycle length is 20mS. In that period there are two zerocrossings: for the upgoing wave and for the downgoing wave.
      If you would set the ignition to wait till 5ms after each zerocrossing (so at the top of either the positive or negative cycle), The TRIAC would be ON two times during the full cycle and get half of the full power (AreaUndertheCurve).
      Because the IGBT doesnt switch off on a zerocrossing and ideally there is no zerocrossing in DC, it doesnt really matter when you ignite it.
      Now ofcourse if only using a bridge rectifier, what you get is a fluctuating DC voltage that in principle will be zero after each peak, but that doesnt matter because teh IGBT doesnt switch off so basically you will get a PWM modulated 50Hz fluctuating ‘DC’ in which at a set dutycycle of the PWM the Area Under the Curve will remain constant.

      1. Thank you for your explanation. However, there are a few things I still can’t figure out. If we use your new design, I can see that the lamp will indeed get a “DC” voltage. But if we use Giesberts’ original design, aren’t we still feeding AC to the lamp? So I’m thinking that both your and Giesberts’ design are working because both of you are not using a triac which as you explained is switching itself off at zero crossings. But if this is the case, then we could have chosen any switch that is not dependent on zero crossings such as a mechanical relay. However, nobody seems to be using it. Can you help me understand why?

    2. Sorry for my late reply. I must have missed yr comment

      For as far as my circuit goes, I feed the lamp with a DC voltage so PWM is not a problem.
      As far as the Giesberts circuit goes, that is because the 50Hz is modulated with a PWM signal so the area under the curve (brightness) diminishes.
      With the zerocross dimmer you get the dimming by delaying the ignition of the Triac, so if you want to have the lamp at say 1/2 strength, you ignite the triac at the top of the sinus (=halfway the cycle). To know that halfway point (or any other point on the sinus) you need to know when the sinus starts, hence the zerocross detection.

      With the PWM modulation if you want the lamp at 1/2 strength you dont wait till you reached the halfway point of the cycle, but you just start takingsmall pieces out of the entire sinus. With a 50% dutycycle that also gives 50% of the AUC. But in this case it isnt really important where on the curve you start as you take out small chunks all along the way. As long as the frequency is high enough it doesnt matter if you start at zerocrossing or a wee bit later
      This is only possible with a transistor and not with a triac as we cannot switch off a TRIAC, that is switched off when the voltage drops.
      As far as using a relay goes…:-) that just isnt fast enough but if you could switch a relay with a frequency of say 500Hz or more that would work

      Ofcourse this can only work if the PWM frequency is high enough and definitely way over 100Hz

  6. Thank you for the great explanation. Just some extra questions I have:

    – What type to use for D1, just a 1N4007 like in the original circuit?
    – what voltage rating should C1 have? 400V?
    – If I would use this circuit in a consumer product, would output filtering be required to meet emission standards?

    thanks in advance.

    1. a 1N4007 is ok
      400 volt for C1 would be fine
      if you use it in a commercial product (i.e. for sale) in EU or EEA you need CE marking to testify it meets health, safety and environmental standardsstandards, the exact requirements are in the as dimmers up to 1000Volt fall under the Low Voltage Directive (2006/95/EC) The electromagnetic aspects however are covered in Directive 2004/108/EC15, so you would have to check there. Wether it would qualify for self certificationor certification by a notified body i am not sure but the directives no doubt will give insight on that

      1. Thanks again for the clarification. I guess that reading the standards will give me more info.
        But just as a shortcut, I notice this circuit doesn’t have a big choke coil like the conventional triac-based phase-cut dimmer designs. Does it not need one because of the higher switching frequencies?

      2. I didnt find a need for a choke. I am no expert on switching but I guess it wouldnt hurt to add one. The PWM frequency of the Arduino is about 500Hz.
        keep in mind ythought that the TRIAC based dimmers work with another principle as they do phase cutting rather than PWM

  7. Nice design, really like it.
    I noticed PCB and schematic design are not the same.
    On PCB C1 is directly connected to Br1, but in schematic design it’s after D1.
    My guess is that PCB is wrong here😉

    I was wondering. Do I understand correctly that it is in fact an inverted PWM?
    If arduino would give high signal, this dimmer switches off right?

    If so, is it done for the sake of simplicity?

    1. Arvin, Thanks. You are very very right. I usually build the circuit on veroboard before I design a PCB and in this case the PCB has a mistake. Thanksso much, I will correct it asap.
      It is indeed an inverted pwm. The main reason is speed. The voltage on the gate willl be made to switch between High and low faster therefore minimizing the transition phase in which the transistors C-E acts like a resistor, this minimizing the power dissipation in the Transistor.
      Thanks for yr remarks

  8. Hi, thanks for taking your time to write such useful article. Too bad that I found it just a day after I received my components for 20 dimmers I was going to make for my home based on the original scheme. Changing to IGBT would cost me quite a bit extra, so I think I will use your advice to work around the problems on the original scheme this time. One question though – I read it a couple of times in different places that incandescent bulbs (that are designed to run on AC) will have somewhat shorter lifespan if run of DC due to uneven filament wear and some other reasons that I don’t remember now. And Osram says this is especially big issue with halogen lamps (that I plan to use), where lifespan may decrease to 15% of the nominal value. So how about if I leave the bulb where it is (on AC) and put an extra smaller bridge rectifier to power up that “MOSFET driver” part of the circuit? AC input of this new bridge would come directly from mains (not through the lamp), negative output would be shared with the old bridge and positive output would go to D6 (sorry, don’t have my Eagle with me at the moment). It’s OK for me to add an extra component, if only this would solve the problems you described. E.g.:

    1. whether or not incandescent lamps or halogeen lamps have a considerably lower lifespan on DC as compared to AC I do not know. But what I do know is that cars/automobiles have 12V DC AND use halogen lamps as well. So I am not sure it is an issue, but at the same time I am sure Osram knows more abt halogen lamps than I do.

      A separate feed (which the extra bridge factually will provide should circumvent many problems of the original circuit. The bridge you linked to is really more than capable to deliver the few mAmps that circuit would require.

      Good luck. Would like to hear how you fare

      1. Thanks for encouragement, I’ll follow up as soon as I have something to show. And meanwhile, about lamps, I remember somebody asked same question about how come low voltage DC lamps (e.g. automotive) are OK, and the answer was “because they are made with thicker and shorter filament.” One of the reasons I remember why DC is not good for AC-designed lamps is that tungsten filament evaporates at one end (probably negative) more that on the other. When running of AC, these sides alternate and the filament gets thinner at both ends equally. In case of DC, one end gets thinner almost twice as fast as it would on DC and thus breaks sooner. And here’s more about halogen lights: Now I’m not sure if it’s all really true or just a plausible theory, but if just an extra bridge will take the doubts away, that’s cool for me. Thanks again!

      2. thanks, i considered that one end theory as well, but i just am not sure if it is true. Maybe it is, maybe it isnt, I just dont know. Thanks for the info

  9. Unfortunately, it didn’t work as expected. It took me a while to realize, that connecting negative terminals of both bridges actually shorts out the smaller bridge when the MOSFET turns on, effectively exploding it and ruining some other components on the way. I disconnected these “grounds” and it kinda works, but now there is some slightly visible flickering @100% duty cycle and even more visible when doing PWM. When I increased Arduino’s PWM frequency to ~4kHz it help a bit, but it’s still flickering. When I plugged the lamps directly to mains (just to make sure my eyes are not the main problem here) I found out that they where not even running at full power through MOSFET. So I suspect that issue might still be related to not having common ground and the MOSFET or optocoupler not turning on at some half of the mains 50Hz cycle? My competence kinda ends here, I’m in a dead end…
    P.S I also thought, that maybe the caps are not able to keep up with the power demand to drive the MOSFET, so I replaced the C2 with 660nF and C1 with 100uF, but that didn’t help at all.

    1. Well there are several issues. Not having a common ground makes the MOSFET get a gate voltage that is kinda virtual. I am sure that maybe somewhere through the bidges and the mains there is some current flowing, but as it is it gets it gate tension of 10 Volts referenced to the the ground. But as the source MOSFET isnt connected to that ground it is a completely undefined voltage. Asthere probably is some pathway through the bridges, most likely you have a fluctuating undefined Gate Source voltage. from yr video it still looks reasonanly OK but there is definitely a 50Hz flicker.
      Increasing the capacity of the capacitor isnt going to help.
      What you could do, even if just as a proof of concept: do away with the seperate bridge and put the incandescent lamp in the DC line, acciording to the theoretical ‘inbetween’ modification I discussed and see what that does.

      Just to make sure that people just superficially scanning yr post dont understand wrong: This is about a DIFFERENT circuit than I proposed

      1. I did try your recommendation and it works perfectly through the whole duty cycle, just as expected. I think it’s a super-simple yet genius workaround. It’s just that I still hope to find a non-workaround solution that would allow me to keep the lamp on the AC side of bridge and up to 100% PWM. Especially that I am going to use it mostly on halogen lamps.

        I wasn’t able to get my hands on the dimmer for a while, so I downloaded this LTSpice simulator. It turned out to be much cheaper and safer way to verify new “ideas”. Unfortunately, none of them gave me constant 10V for PWM’ing MOSFET @ 100% duty cycle and in many cases (including the one that I tried in real circuit) even at max PWM before the “power deficit” loop begins the actual current through bulb was only ~50%, as it was obvious with naked eye as well. LTSpice showed me, that there is a variable potential difference between grounds of both bridges which probably is the reason of troubles. I tried different configurations, but had no luck yet.

        Now that I’m back to my circuit I also tried the original version (only now). It works OK up to the duty cycle of ~96% (very close to authors estimation, BTW) with the MOSFET reaching stable temperature in the range of 60-70 degrees Celsius. When going above 96% the “power deficit” game begins: lamp starts to flicker a bit, gets a little dimmer and transistor starts heating up, etc.

        Also, I found out that this circuit (in any configuration) can handle only low frequency PWM’s. ~500Hz was OK, 1kHZ was so so, and anything above 4kHz was not usable (lamp is either fully on or off). Intuitively, MOSFET should be able to handle such frequencies, so maybe the optoisolator is too slow? Will try to read the specs, maybe even understand something. Incandencent lamp @ 500Hz would probably be OK for the eye, but there’s an audible hum up to 75% PWM.

        Anyway, thanks for taking your time to bother!

      2. I am happy that workaround worked. and thanks for your feedback. The specs of circuits in this range make it a bit of a coin toss regarding a MOSFET or IGBT being better or not. Tou may find this article interesting. I would think that a MOSFET as well as an IGBT would be able to handle 4kHz. Oddly I couldnt find any info on cutt-off frequency in the 4n25-28 datasheet, nor that of the 4n32-33

        To avoid that other readers understand it wrong: This workaround is for a DIFFERENT circuit than i was proposing

    1. That is indeed correct albeit that abt half a Watt should theoretically ve sufficient. It is always good to have a bit of a larger dissipation capacity.

  10. It is also good idea not to leave optocoupler’s transistor base floating (it has some capacitance so it wont shut until it is discharged (not vital in slow operation mode) and also could be susceptible to EMI noise) and tie it to power ground with i.e. 100-200kOhm resistor.

    1. I haven’t really had that problem, but it definitely is a good precaution.
      Just a warning to those reading this: Put that resistor between Digital pin of your microcontroller and the Ground of your microcontroller DO NOT ATTACH TO THE HIGH VOLTAGE ‘GROUND’

      1. In this application its probably ok to leave it floating, if pwm frequency does not exceed couple of kHz. You definitely don’t want to connect high voltage side to signal side, so probably its best to leave base in the air (although i connected it through 100kOhm resistor to emitter w/o blowing anything up)

      2. I didnt think you would blow anything up.Just wanted to make sure that people with less experience dont connect the resistor to HV🙂

  11. Another thing I was thinking of – is it ok to switch on the transistor when there is no current flow (during zero cross)? I red somewhere something about quasi-saturation losses in this case. Can it be the source of the problem “dragan” had? Easy solution to this is to put another capacitor acros +/- leads of the rectifier bridge. (I have encountered same problem, will try my theory when I replace dead igbt)

    1. I am not sure if it will be. if yr pwm frequency is higher than 50Hz it will not help and if it is lower than 50 Hz it is close to strong flickering already

  12. One last thing (I promise), current configuration of the divider r1-r2 in ideal conditions (phase voltage ~310v) provides base of the igbt with ~19v, it is really near the absolute maximum V(Ge) rating of the igbt used in current schematics (20v), but power grid is not an ideal place, under/over-voltages is pretty common thing (not talking about sudden spikes). So it would be good to protect base of the igbt somehow, clamping 12v zener in parallel to the R2 against base over-voltage, and small inductor in series after r2 probably – against spikes (although it will be hard to chose its value to effectively filter out input spikes of the grid without to much of trouble provided by its own spikes during on/off transition)?

    1. indeed, configuration is always a bit difficult with a pulsating DC voltage. The 310 Volt is in fact peak voltage. A zener would perhaps be a solution. 12 Volt may be a tadd too low for some IGBT’ s so maybe a 15 Volt might do better.

      As said the 310 volt is peak, with the average voltage being 0.637 x Vmax

      1. yep, but C1 is pumped to the max phase voltage (input pwm freq and capacity of the c1 affects – will c1 be charged to the max or not, but as usual in electronics lets assume the worst case scenario). As for myself, I solved problem without modifying the schematic by replacing IGBT with a slight cheaper MOSFET STP10NK60Z with clamping zener inside (btw, even though i have this mosfet in an insulated to-220 package on a small ~10w heatsink, on a 200w load the heatsink to the touch is not even slightly warm).

      2. Pavel, in principle it can be done with a MOSFET as well as I discussed in the article. Reason for me to go to an IGBT is because in general they are seen as better switches, but the voltage range in which this circuit works makes it a bit of a draw. I wouldnt dare say the IGBT is better in this case. Please be carefull touching the heatsink, even though yr mosfet is insulated🙂

  13. Thank you so much for this, I didn’t really understand the technical part but it seems that old design will overheat and have flicker problems, if am getting things correctly

    Here I have a problem with new design, which is that non of lamb terminals is connected directly to AC source, while in normal home, 1 terminal is connected directly to Neutral line through wall and other terminal is accessible through switch. I mean I can only access 1 lamb terminal in home and thus can’t apply modification you suggest. Is there any other design that will work without flickering or overheating and still solve this problem? Thank you so much.

  14. Hi, thank you so much for this

    May I ask if there is any circuit that works with no problem and still uses only 1 terminal of lamb while other is connected to AC source directly? In normal home application, 1 lamb terminal is already connected to Neutral line through wall and it is not accessible easily (at least not in where I live), while we can only access the other terminal through lamb switch in wall, what is the solution for this? Thanks in advance.

    1. the traditional TRIAC dimmer is in fact in series with the lamp and uses two wires. In fact it can replace a switch

      1. The traditional TRIAC dimmer circuit doesn’t work well with me, I tried it on an arduino and it works great, then I tried it on ESP8266 module but lamb keeps flickering every few seconds, I chased software and found out that each time ESP detects zero cross and tries to fire an interrupt it takes some time, maybe because it tries to handle WIFI connection via interrupts also and this makes GPIO interrupt delayed to a number between 10 – 200 uS, I believe this (somehow random) delay makes lamb flicker!
        Using an arduino beside ESP module takes a lot of size that is not available inside wall in switches box, and WIFI connection is needed by default

        I tried something, which is buying a ready dimmer from market (it has a simple circuit of triac, diac and potentiometer for control) and tried replacing potentiometer with LED and LDR with shrink tube around them, then provide LED with PWM signal. This worked but the relation is highly nonlinear besides that if am on low PWM, lamb lights then within less than a minute it starts to dim more and shuts off, not sure why but maybe it is because of LDR non linearity? Like even with same lux value it still changes resistance since LED is feed with PWM?

        Any help in this project will be appreciated, and if I can contact you on Skype I will be thankful, I believe you are an expert in the area thus I will need your help in few things, will pay for that!

        Thank you

      2. so the traditional dimmer DOES work, it just doesnt work wel on your ESP8266 setup. So before we go any further , please let me know exactly what it is you are building. Is it based on Arduino or ESP8266

      3. Thanks for your reply, in fact am making a project that require further help than just posting comments, if I can know how to contact you we can work this out on Skype for example, am looking for paid help. How can I contact you please? My Email is

        As an answer to your question, am trying to build my project on ESP8266, programming that using Arduino IDE, I got everything working (Am a very good programmer, but not that much good in electronics, this is because I studied IT not engineering). What am trying to do is to surprise my boyfriend by making our home lights controllable from mobile phone via internet, I made user interface and android program beside PHP server pages and programming ESP8266 with static IP address beside port forwarding (so basically I made all IT stuff work just great), but am having little problem in electrical circuit, as explained before, traditional triac works well with Arduino but flickers light with ESP8266 module which I wish to use because ESP8266 should handle TCP/IP packets which delays hardware interrupt and causes unstable output, at same time I don’t have access to both lights wires (only one), and small size needed for control device.

        Let’s sum this up:
        I shall use ESP8266 to make size small
        I have access to 1 wire only for light
        I can’t use interrupt based techniques

        So I wish to have a PWM based dimmer that works with 1 wire and does not overheat or cause problems

        Thank you so much!

      4. No am not asking for the moon, just few stuff I need in electronics and will pay whatever it costs to make them! Simply I need AC DC converter that output 5V 1A continuous without heating, minimum ripple and very small in size, beside dimmer I discussed before and little consulting about some electronics

        Anyway am not sure why email does not appear fully, it writes xxx not sure why, here is my email: may dextar @ yahoo .com (without spaces)

        Thanks again

  15. Thank you for this tutorial. I wonder if I could control a 300w ceramic lamp with it. I tried with a similar diagram (the first or the seconds diagram of your tutorial I think) and a irf830. It started to burn and didn’t work.

    What you you think?

    1. yes you can if it is indeed a purely Ohmic resistive load.
      There is only one reason why an IRF830 (or any component for that matter) would burn: if it is pushed beyond its limits.
      I presume you are on 230 Volts, so your lamp draws about 1.3 amps and that should be no problem for the IRF830 as that can take 4 amps (at 25 degrees). Now when the temperature rises to say 100 degrees, it still can take almost 3 amps.
      However, the maximum power dissipation is 74 Watts and the RDSon is 1.5 Ohm. So when fully on the FET will dissiptae I² * R=2.5 Watt when fully OFF The Powerd dissipation should be close to zero so that is all OK
      However, when the temperature rises so does the RDSon to about 2.5 Ohms leading to a dissipation of 4.2 Watt.
      So that all is still OK,
      But if you have used the first or 2nd circuit, then you have used circuits that I warned about and that I just used as illustration of possibly problematic circuits:
      FETS make good switches but they make bad resistors. As I explained in the article, when switching a MOSFET on and OFF, if that doesnt happen fast there is a distinct moment in which the resistance of the FET goes from RDSon till endless. If this doesnt go fast enough the dissipation in the FET increases significantly.
      At the moment it is around 43 ohm the dissipation is approaching 74 Watt (for sake of ease I leave out that ofcourse the current goes down too, but you catch my drift I presume).
      Eventhough that is above the max rating, maybe for a brief moment that is not so bad, but if you use PWM (I think 500Hz for an Arduino), those small moments add up and the chip gets warmer (thermal resistance is around 60 degrees per Watt)
      The warmer a mosfet becomes, the lower its max ratings.
      Now the speed of switching doesnt depend on the frequency of the PWM, that just determines the number of times a MOSFET is switched.
      The speed is a combination of the MOSFET itself and the hardware it is in.
      The 830 is not a particularly fast MOSFET, but the circuit isnt really fast too. I will explain:
      The first circuit has two problems with regard to speed: the fact that the MOSFET actually shorts the voltage that is used to feed the gate and the larce RC constant feeding the gate.
      The second circuit only has the latter problem.

      So if one looks at that second circuit (the one without the great big red cross through it), one can see that there is a capacitor that is kept at 10 Volts with a zener. The moment however that there is a pulse on the optocoupler, that capacitor will provide the Vgs but is also discharged through the 22k resistor. So after 48mS the Voltage will have dropped to 37% of 10 Volts which means that in that 48 mS the Vgs dropped, increasing the resistance of the FET and thus increasing the Power dissipation and thus the temperature.
      Sure, the capacitor is being charged again via the two 33k resistors, but they form a larger RC time and it takes 145mS to charge up till 63% of 6 Volts.
      This means that during switching the Vgs is below the nominal 10Volts for a considerable period of time, leading to increased dissipation and junction temperature.

      Now someone will say, yes but when switching at a 500 Hz cycle the period is 2mS so there just is no time for the capacitor to drain till 37%. True, but even at a 5% drop (Vc=Vs*e⁻⁽t/RC⁾=10*e⁻0.04 =9.6) the resistance increases and thus the dissipation and thus the temperature.
      Once that goes up to 150 degrees, the max current is 0 and your MOSFET pops

      I didnt specifically mention the power derating (but defacto used it in my narrative), but it is about 0.6 Watt/degreeCelcius.
      That means that for each degree of temperature rise above 25degrees you need to decrease the dissipation with 0.6 Watt.
      So suppose your junction temperature is at 100 degrees that is an increase of 75 degrees and thus a need for 45 Watt less dissipation.
      So at that temperature your FET can only dissipate 74-45=29 Watt at a current of 1.3 Amp a mere Rds of 17 Ohm already would push the 830 out of its limits.

      1. Thank you for your answer. I haven’t had time yet to test the latest diagram, but I think I will have it this weekend. I am in Europe, so 220v and, in fact, I am using an arduino. I am sorry, I am not very fluent at english and I don’t completely understand your last couple of lines. Do you mean I won’t be able to make it working? Those electronic knowledge scape to my understanding although I think I more or less understand all of it.

      2. Paul. happy to be of service. Nothing wrong with your english. You asked about the Osram parathom right? back in december? I meant that i do not think it will work with this pwm dimmer but i think it will ork with my other circuit that is triac based

      3. I can’t answer to your comment, I don’t know why. Actually I am the other Paul, I asked some months ago about controlling a ceramic lamp about 300 watts with this dimmer design and the pwm output of an arduino. You gave a long and well detalied explanation. I tried to post my previous comment as an answer of yours, don’t know if you see well or I did it wrong😦 I can’t answer to your current comment , maybe the coincidence of the names is mixing somethings here…

      4. ah yes. sorry, my bad.
        Yes I indeed gave kind of an extensive answer. What I tried to do is to explain/calculate what could have caused your FET to burn in using the circuits I used as example of how not to do it.
        The Most important thing in handling FET’s is speed of switching. every moment the gate of a FET is between 0 Volt and optimal gate voltage, the drainsource connection acts as a resistor rather than a switch.
        Now that doesnt mean you have to increase the PWM frequency, preferably not even, it all has to do with how fast the Vgate can be at its optimum. That is mainly determined by the powersource and the various RC constants that power source meets on its way to the gate.
        In my circuit the main RC constant is formed by the gate capacitance of the MOSFET and the 100k resistor. For the 730, the gate capacitance is 700pF. So to be on the safe side lets take 5RC for the capacitor to fully charge so that is 5×100.000×700*10⁻⁹ = 350uS. So your pwm could go to approx 2800Hz without entering in the saturation zone of the MOSFET.
        The Arduino PWM frequency is some 5-600 Hz I think so you wont have any problems there.
        Instead of a 100k, probably a 50 k would be OK too. That would cut your rise time in half to 175uS.
        It also means that the 100uF capacitor is likely grossly overdimensioned. A 10uF is probably more than enough
        No need for you to answer the earlier comment.. as you are the other Paul my earlier reply was totally irrelevant

      5. I just tested the last diagram. My capacitor just blew up. Well, it exactly created a fog in my room. I have one 100 mu F 100v. Is it not enough? White part is “+” in the diagram, isn’t it? I have to check if I have anything else wrong but it seems to be fine. Rest of components seem ok too.

  16. I was just thinking of building this, but was wondering how long C1 would take to discharge once the power is removed, so making it safe to handle ? Also perhaps having an LED as an indicator that it’s still charged?

    1. Well you could actually calculate that. Generally, a capacitor is discharged after 5T, in which T stands for the time constant of the RC network which is R*C. Say R=105k then RC=(105*1000*100)1000000=(105*100)/1000=10500/1000=10.5 sec. Thus coming to 50-52 secs
      You could add an led with a proper seriesresistor, that would not only indicate it was still charged or not but also help in the discharge.

      As my circuit worked right off the drawing table I didnt really feel the need to handle it, but it is always a good idea to be careful.

      1. Indeed. Yet it is always good to be careful. I have gotten shocks from old TV’s, hours after being switched off that definitely had smaller capacitors… but maybe bigger resistors🙂

      2. I built the dimmer. The 100K resistor gets a little warm (on 220v AC) but is fine, and i discovered that the light flickered a bit – so i increased the clock speed on the arduino to 980Hz (was 490Hz default) – problems solved. Again many thanks ….

      3. great. thanks for letting me know. Interesting that you increased the speed, as a matter of fact the clockspeed came up in a discussion I had with a fellow DIY enthusiast about the size of the capacitor, that we think can be drastically reduced if the clockspeed (of the pwm) does not get too high. 980Hz is no problem, certainly not with the 100uF. I plan to try some smaller capacitors. maybe even a 10uF is enough

  17. Hi, great work with your design. I have previously used the Tom Giesberts design on a 100w lamp and it worked quite well but unfortunately not so well on an inductive load. I read here somewhere that your design can’t be used on an inductive load either. What about if a snubber circuit is added? Or is there some other reason it can’t be used? I’m wanting to speed control a 240v 50hz 850w universal motor via PWM.

    1. Well the problem with an inductive load is that it often expects AC. My design uses DC on the load so unless it is a DC motor it would probably not work or get damaged.
      I also have a design that uses AC and zerocrossing. Also not perfect for inductive load but it does work and probably could work even better with pulse skip modulation

  18. Hi! Thank you very much for this post!

    I have a doubt… As I could control a series of three 9W LED lights already installed in a house with phase, neutral and return with this circuit?

    Thank you in advance!

    1. Well, it depends what you mean. A Phase and a Neutral is what you need, but what exactly you mean with ‘the return’?. Do you mean you have two wires going to the LED (The Neutral and the switch) but you have both neutral and phase available in yr wall socket?
      The reply is actually simpel: if you have a phase and a neutral in yr socket and you have two wires going to your Lamp you can use this, as long as you just follow the circuit if you have any uninterruped wires (either phase or neutral) you have to cut those.

      The circuit has 4 connections: Neutral and Live and 2 for the Lamp.
      As long as you have that, without any of those 4 wires being shared, you can use this.

      Having said that, this circuit is not suitable for all LEDs.
      LEDs that are directly connected to the mains usually have some electronics built in that doesnt respond to PWM

    1. yes, I know the board and at 15 usd it is not specifically expensive. Unlike the PWM dimmer I presented here it uses zcd and a TRIAC and in that aspect it is more like the dimmer board I published earlier on this site.
      The difference is that the mpdmv4 board is processing the zcd signal itself, while on my board the zcd signal is sent to the arduino for processing.
      I therefore suspect that the board has an onboard processor like an attiny or a pic. As i can see the board originates -coincidentally?- from the same country as you:-)

  19. Hey! Thanks for this really helpful, however i want to dim a 60watt bulb from 220V source instead, will this circuit work perfectly with it too?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s