loading

HOLD OFF ON BUILDING THIS for now (March 30 2017) for the simple reason that I know someone just made a slight variation on this design that might be interesting to build instead. It has 2 extra active components (transistors) but still a very simple design. The large capacitor I am using can then be replaced by a smaller one of lower voltage)

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.

Gieberts

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.

ac-pwm

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

igbt-mosfet2

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:

mosfet-pwm

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

BOM:
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-06 Watt (actually it dissipates abt 480mW max) 0.12 euro
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

<p>do you think that this should be work ?</p>
<p>no, if any you should switch the collector and emitter :-)</p>
<p>Ok.</p><p>Any idea to solve my issue?</p><p>Is there any (easy) way to modify the circuit so that when the PWM's Duty Cycle is 0% the lamp will be OFF and when the Duty Cycle is 100% the lamp will be fully ON?</p><p>In other words: is there any way so that the circuit will work in &quot;reverse&quot; mode?</p><p>Thanks in advance</p>
<p>you could put the optocoupler in the upper part of the voltage divider, but you would need to make a few recalculations</p>
<p>This could be work?</p>
<p>probably not so good. Place the optocoupler below where the capacitor is charged. You may have to adapt the resistor va;ue</p>
<p>Hello;</p><p>You need a Normal Open circuit(bassically a reversed logic): I've built and described below and also added the schematic using exactly the components in this article's build. </p><p>Regards,</p><p>C.</p>
<p>Hi Oc, thanks for your reply.</p><p>It seems to me that you has added two - different - Normally Open Circuit.</p><p>Is it rigth?</p><p>And if yes wich is the right (and easiest) circuit for my needs?</p><p>Thanks in advance</p>
<p>Hello; <br>This one creates a default opened circuit (lamp starts switched off) as in a normal electrical circuit or as some of us need bringing the needed behavior with no need of calculations inheriting them from the original design.</p><p>The previous implies modifications and extra parts ; and its logic is not sound as seen in comments.</p>
<p>What should I modify if I want to add 2 output channels? thanks</p>
<p>everything after the 100uF capacitor<br>Thus: voltage divider, mosfet, optocoupler, zener... if you use that</p>
<p>this is correct?</p>
<p>this would be what you need</p>
<p>your circuit is a bit unclear on where the 100uf is connected to. Your circuit makes no difference between crossing lines and connected lines. It seems needlesly complicated. if you want two channels, just duplicate the fet, the lamp, the optocoupler and the voltage divider</p>
<p>Hi.</p><p>A simple question.</p><p>Is there any (easy) way to modify the circuit so that when the PWM's Duty Cycle is 0% the lamp will be OFF and when the Duty Cycle is 100% the lamp will be fully ON?</p><p>In other words: is there any way so that the circuit will work in &quot;reverse&quot; mode?</p><p>Thanks in advance</p>
<p>Following the informed comment earlier, and without adding any parts; ; simply inverting the logic would give us a Normally open circuit easy to use in any application. from 10 to 350V AC or DC (for lower voltages ; the 100K resistor must be adjusted to allow the IRF's gate to open).<br><br>Thanks again for this article and with added flexibility will be easier to enjoy the use this circuit to control lighting via pwm or as a gpio from any embedded or PIR or anything you need to make use of it as a NO electronic cheap switch.</p>
<p>Thank you for your input :-)<br>have you already built this?</p>
Hello;<br><br>Yes of course, the i built one button is pressed for that reason; if anyone needs a layout i can share mine; but being so many connector choices ; dimensions and wide usage; this schematic is more valuable as a concept based on what one the needs : a normally open(this one) or inverted: normally closed circuit(the initial one).<br><br>Thanks again ; and happy DiY-ing to all.
<p>great, thanks for sharing the circuit. Just was interested to know if it was a theoretical addition or an implemented one as the latter always gives people more confidence o build it.<br>Ah yes, i know that 'problem' my circuits usually look simpler than my eventual PCB as i tend to add jumpers/connectors etcetera. :-)</p>
<p>Looking for help, I need to create something that will automatically fade in 1000w of incandescent lights over about 10-15 seconds once the circuit is energized. After fade in, lights will remain at 100%. Would appreciate any assistance on how to build something.</p>
<p>you can do that with this circuit or with the one in my other dimmer instructable that works with a triac.<br>What you want you can do in hardware, but that is very complicated, or you can do it in software with say a promini that will cost you 1.60 USD</p>
<p>Hi.</p><p>I've successfully realized the AC PWM Dimmer.</p><p>It work like a charm with Simulink (Matlab).</p><p>Many thanks</p>
<p>Thank you for adding the pictures </p>
<p>My pleasure. Thanks for sharing. Looks great</p>
<p>Hello</p><p>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.</p>
<p>Are you sure your circuit is correct? It seems like your BSS123 will never get anygate voltage</p>
Hello,<br><br>I see your point and is very valid.<br>The circuit is working in this configuration with no visible stability issues.<br>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. <br><br>To make things short a 10 K to the positive rail or bss's drain was my original approach.
<p>What is the model of bridge rectifier that you used?</p>
<p><a href="http://www.alldatasheet.com/datasheet-pdf/pdf/445195/TSC/DBL104G.html">http://www.alldatasheet.com/datasheet-pdf/pdf/4451...</a></p>
<p>thank you sir</p>
<p>HI. I'm an Italian High School Teacher. </p><p>I'm attempting to use arduino to teach ON/Off and PID controllers.</p><p>I've no issue on ON/Off controller : a simple relay and a bulb lamp 60W are enough to explain this systems to my students in a very efficient way (I've succesfully followed this: <a href="http://ctms.engin.umich.edu/CTMS/index.php?aux=Activities_Lightbulb" rel="nofollow">http://ctms.engin.umich.edu/CTMS/index.php?aux=Act...</a></p><p>The big issue is when I try to prepare a lesson on PID controllers.</p><p>My idea is that I can dim the brightenss of the same AC bulb lamp (in Italy there are 230V/50 Hz) so that - consequently - will vary it superficial temperature .</p><p>At this point, by means the same temperature sensor - I'll can adjust the superficial bulb temperature by varying its brightenss - and minimize the error by means PID controller.</p><p>And - to do this - I thing that I should use a PWM control ,</p><p>The question are:</p><p>1) in your opinion is this the right way to better teach PID Controller? </p><p>2) is your circuit suitable and good for my needs</p><p>3) because strictly times requirements, may I find anything of already ready on the web? or , in alternative, may you build it for me?</p><p>I hope I was clear in my needs ad request.</p><p>Thanks in advance.</p>
<p>Hi, <br>PWM indeed seems the most suitable for PID. You are aware of the Arduino PIDlibrary I presume? (if an arduino is what you plan to use)</p><p><a href="http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/">http://brettbeauregard.com/blog/2011/04/improving-...</a></p><p>Whether my circuit is suitable ofcourse I cannot garantee but if you want to keep things simple, yes I think it is useable. Ofcourse you do still need a temperature sensor.</p><p>Thereare various pid controllers on the market, such as e.g. a sous vide, but I am not aware of any commercial product for the arduino or other microcontroller.</p><p>Technically I could build it for you but I am afraid that would become too expensive for what is in fact a fairly simple system that you could easily put together yourself.<br><br>Yes, you were very clear. Thank you for your interest and goodluck :-)</p>
<p>Hi <a href="https://www.instructables.com/member/diy_bloke" rel="nofollow">diy_bloke</a>, thanks for your reply.</p><p>Reeding your post, it seems to me that the PCB you have posted, is not congruent with circuits showed.</p><p>Is it correct? </p>
<p>I checked but couldnt find any mistake. Where did you think it went wrong?</p>
<p>Is seems to me that it is one diode missing...</p>
<p>ah yes, the zenerdiode. That is because it is optional. Nevertheless it might be better to include one in the PCB. thanks for noticing. I will adapt it </p>
<p>hi, can i use an electric heater 110v instead of the lamp? my intention is to control the temperature of the heater with the temperature sensor DS18B20, or i need a total different circuit? if that is the case, which circuit should i use, and how can i do it? (sorry if i wrote anything wrong, my english is not 100%)</p>
<p>also... for 110 Volts you need to adapt your voltage divider</p>
<p>Your English is quite OK. If your heather does not have any transformers or electronic circuits in it but is s pure impedance load, then I do not foresee any problems <br>Another possibility is to feed your heater with AC and use a TRIAC with zerodetection optocoupler and send it a full sinus. Ergo, switch the heating on and off, but in the on phase send it a full sinus wave</p>
<p>Hi. I built up this circuit and work just fine with Dimmerizable Led <br>lamps 220V. But now I have a little proble. I&acute;m using a 7W led lamp as a<br> load and put a 250mA fuse for protection before the diode bridge. The <br>problem is that somtimes when I turn on the circuit it make a little <br>short-circuit because of the 100uF capacitor charching sometimess <br>distroying the fuse, I can see a little spark at the line 220v plug, but<br> if the fuse still well then the circuit work just fine. My question, <br>is, How can I eliminate or minimize this effect ??. I was thinking to <br>put a 3MOhm Resistence between de capacitor and the positive(+) OUTPUT <br>of the Diode Bridge.</p><p>Another question, can I eliminate the Capacitor and put another one between the gate and source of the MOSFET ?, 47uF 25V maybe</p>
<p>No surprise the fuse gets destroyed as there is a surge on the Electrolytic capacitor. Although I am not sure why you want a fuse there.. you may try a somewhat heavier fuse and/or a 'slow fuse'.<br><br>What exactly made you think of 3MOhm resistor? Your circuit will not work anymore then. It will take about 15 min for the capacitor is charged then.<br><br>When I designed this circuit I was going for a very fast switching circuit. That is why I put the 100uF capacitor in the main line, so there wouldnt be a delay in charging it.<br>Now suppose you would put that 100uF between gate and source. If for arguments sake we want to load it to 15 Volt and your rectified grid voltage is 220 Volts (it isnt but just for arguments sake). Then your charge time would be 700mS or 0.7 secs. That is a bit long. With a 47uF capacitor it would be 0.332 seconds.<br>The main problem that you have then is that the MOSFET will remain longer in its resistive phase, rather than be either on or off.<br>That has 2 consequences: there might be some flickering and your MOSFET might get warm.<br>So, could you replace the 100uF capacitor with a 47 uF capacitor over the Gate line......... Yes, i think it might be worth trying.... but keep an eye on your MOSFET and check if it doesnt get too hot (pls remove the connection to the grid before you check the temperature).<br>I would be interested to hear your results</p>
Ok. I'll try to replace the cap by 47uF.<br>The 3MOhm I was thinking to start to charge the cap a little until the diode polarize foward, after that, the diode will short the resistor like the resistor doesn't be there.<br>I need to fuse just for protection. I need to put many dimmers at the same line, the short-circuit current at the start makes trigger line protections (thermoswitch, etc...).<br>I'll post my results. Thx a lot for replay.
<p>looking forward to yr results</p>
<p>Is this circuit useable for 220v Dimmerizable Led Lamps ??</p>
<p>By now this must be the most asked question in the comments. All I can say is: it depends on the LED lamp. If it is suitable for dimming by a 'classic' Triac dimmer, it will most likely work on this circuit too, but not all 'dimmable' leds are suitable for that</p>
<p>Well, I built up and use it with 220V Dimmerizable Led lamps and work just fine !!.</p>
<p>Great. Thanks for info. Can you perhaps say exactly which LEDs you used? (brand, type)</p>
<p>I have read all your instructions and informations carefully for AC PWM Dimmer for Arduino Circuit. But what I want is to be able to control immersion water heater which is 1500 watts above 10 amps. I also know that this design supplies DC output but I think that is not problem for this heater as it should work on both AC/DC. It is just heat dissipation. If I choose an heavy duty power mosfet, can this work?</p>
<p>I think I replied this in a PM already :-)</p>
<p>i am usinge this circuit for dimming lamp<br>can i control celling fan speed<br>for this circuit <br>is btter for mee<br><br><br></p>

About This Instructable

37,625views

143favorites

License:

Bio: 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 ... More »
More by diy_bloke:Working With the Funduino W5100 Ethernet Module. Uploading Data to ThingSpeak With MQTT Adding an MCP23017 I/O Extender to Arduino or ESP8266 
Add instructable to: