Simplest way to build a light dimmer using PWM

  • Thread starter Thread starter TheRedDevil18
  • Start date Start date
  • Tags Tags
    Build Light Pwm
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
17 replies · 8K views · last reply
TheRedDevil18
Messages
406
Reaction score
2
I need to build a light dimmer using the PWM on the microcontroller to dim an incandescent 60W bulb. What would be the simplest way to do it ?, any suggestions ?, would a optocoupler and triac suffice ?
 
Engineering news on Phys.org
TheRedDevil18 said:
I need to build a light dimmer using the PWM on the microcontroller to dim an incandescent 60W bulb. What would be the simplest way to do it ?, any suggestions ?, would a optocoupler and triac suffice ?
You will need two optocouplers. One to sense the zero-crossings of the AC Mains signal, and one in the other direction to trigger the triac at whatever angle is appropriate for the brightness level. Can you use Google Images to find some typical circuits like this with the isolated uC controlling the dimming, and post them here for discussion? :smile:
 
Simplest one's I could find where these,
Schematic of a triac light dimmer: a microcontroller pin drives an MOC3021 optocoupler through a 330 ohm resistor, its output gates a BT136 triac via a 10K resistor, and the triac switches a 230 V lamp L1 across the AC input J1, with a 100 ohm 1W resistor and 100nF 400V snubber capacitor across the triac.


Circuit schematic of an opto-isolated triac light dimmer: microprocessor GPIO drives an opto-coupler with zero-crossing circuit, feeding a triac that switches the LOAD on the 240 VAC line.


What would be the need for the zero crosser if I know the AC mains frequency is 50Hz, so basically I know when the zero will occur. If I am using pwm to generate a square wave, I thought about something like this

Handwritten sketch on lined paper comparing a 50Hz AC sine wave with a square wave for 80% brightness, with 20 ms period and 8 ms on-time within a 10 ms square wave cycle.


I am using an atmega16 and so if I set the PWM frequency to 100Hz and say for example 80% brightness, that would be 80% duty cycle, which I read is all you need to generate a square wave using the atmega16
 
With a triac - it would be more of a phase delay vs what I would call PWM. To do a true PWM - you will need something that you can turn off, like a MOSFET - - you will need two to switch both the positive and negative AC wave, or you can rectify to DC and then just make a chopper.
 
TheRedDevil18 said:
What would be the need for the zero crosser if I know the AC mains frequency
If your control pulses are not synchronised to be in step with the mains waveform, then the intensity of the light will show variations with time, which we perceive as annoying flicker.
 
Guys, I tried building the circuit, here's the schematic:
Schematic of a triac-based AC light dimmer with an ATMEGA32 microcontroller: a lamp L1 230V in series with triac U6 L4004L3, a PC817 optocoupler U7 driving the triac gate through R4 3k, and a bridge rectifier BR1 with PC817 optocoupler U5 as zero-cross detector feeding PB0 via R3 10k, fed from source V1 VSINE 230V 50Hz.


So bascially, the bottom optocoupler (U5) is the zero cross detector which will send a pulse to pin 3 when a zero is detected and fire an interrupt. This interrupt will trigger a timer which will fire the second optocoupler(U7) when the timer has elapsed (Brightness level will determine the time delay)

Now for my question, I want to know if I connected everything fine before I start the coding, especially the triac part, I am unsure about that
 
TheRedDevil18 said:
Guys, I tried building the circuit, here's the schematic:
View attachment 106043

So bascially, the bottom optocoupler (U5) is the zero cross detector which will send a pulse to pin 3 when a zero is detected and fire an interrupt. This interrupt will trigger a timer which will fire the second optocoupler(U7) when the timer has elapsed (Brightness level will determine the time delay)

Now for my question, I want to know if I connected everything fine before I start the coding, especially the triac part, I am unsure about that
The light needs to be in series with the triac... :smile:
 
As I read this, the triac is in series with the bulb.

I would point out that you could build this using a stepdown transformer first, and run this around 12 vac, to test it. Of course you need a low voltage bulb.

You can then test each section out easier, and less risk of blowing something up.

Fuse that source!

I am a little curious if the rectified portion of the zero crossing signal will go completely to 0v, also in this set up the zero cross signal to the uC will be normally high, and you will turn off at the 0 ceross. Probably will...
 
Windadct said:
As I read this, the triac is in series with the bulb.
Ah, you're right. The "ground" symbol between the triac and the light confused me. The ground symbol needs to be removed, especially if it is meant to be the same as the ground symbol shown on the SELV side of the optos.
 
berkeman said:
The ground symbol needs to be removed, especially if it is meant to be the same as the ground symbol shown on the SELV side of the optos.
Actually, what you need to do is be sure that the opto pullup voltage and the "ground" for the triac are different symbols from the SELV versions. I see now that you want a reference voltage for the triac trigger, which is fine. I think I would reference it to Neutral as a low-side switch, though... How are you making the opto pullup voltage for the triac?
 
  • Like
Likes   Reactions: TheRedDevil18
I modified the circuit to this,
Schematic of a triac dimmer circuit: live and neutral mains feed a triac L4004L3 gated through R6 8k and an optocoupler MOC3021, with a bridge rectifier BR1 2W04G, R2 23k and optocoupler PC817 driving a PIC-style MCU pin, plus R5 360 and R3 10k.


Windadct said:
also in this set up the zero cross signal to the uC will be normally high, and you will turn off at the 0 ceross
Wouldn't the MCU be measuring VCE on the transistor ?, so if their is a zero, the transistor would be off and VCE would be 5V and if its on, VCE would be 0V

I'm having trouble choosing R6 though, in the datasheet for the triac (L4004L3), this one
http://www.littelfuse.com/~/media/f...es/documents/data sheets/e1sensitivetriac.pdf
Igt = 3mA, so if I calculated the resistor value for peak voltage and 30mA current

R = Vpeak/I = 230/30mA = About 8k

But now let's say the triac is triggered when the AC voltage is 10V
I = V/R = 10/8k = 1.25mA

But since Igt is 3mA, the triac won't turn on

If I try choosing higher currents, the resistor power increases
Right now it's sitting at
P = I^2 * R = 0.03^2 * 8k = 7.2W peak power
 
Pin 3 for most of the cycle will be low, but around the zero crossings it will go high.

For resistor power dissipation, don't overlook the fact that once the triac is ON the voltage across it (and across that gate resistor) drops to just a few volts.

In practice, these circuits incorporate RC filtering to reduce false triggering caused by electrical noise, e.g., http://www.bristolwatch.com/ele/triacs2.htm
 
  • Like
Likes   Reactions: TheRedDevil18 and jim hardy
TheRedDevil18 said:
Igt = 3mA, so if I calculated the resistor value for peak voltage and 30mA current

R = Vpeak/I = 230/30mA = About 8k

But now let's say the triac is triggered when the AC voltage is 10V
I = V/R = 10/8k = 1.25mA

But since Igt is 3mA, the triac won't turn on

If I try choosing higher currents, the resistor power increases
Right now it's sitting at
P = I^2 * R = 0.03^2 * 8k = 7.2W peak power

old engineering adage - when all else fails, read the directions :wink:
http://www.ti.com/lit/ds/symlink/moc3021.pdf , page 4

Two circuit schematics from a MOC3020/MOC3023 optoisolator datasheet: Figure 5 resistive load and Figure 6 inductive load with sensitive-gate triac, 220 V 60 Hz, 180 ohm and 2.4 k ohm resistors, 0.1 uF capacitor.

i've seen metal film resistors used around power circuits. They'll burn open like a fuse if needed. Pick one bigger than you need so it'll have some distance between its ends to quench an arc. Maybe an inch ?

Has nobody mentioned the hazards of working with housepower ? Windadct mentioned fusing this thing which you should do..
Additionally, i'd find a GFCI outlet or make one for my workbench. I screw an outlet box to a plank, install a GFCI outlet and wire a 3 conductor extension cord to it . Good way to salvage an extension cord that's got run over by the lawnmower.
Use it only in grounded household outlets, if unsure get one of these and test your wall outlet:

Here they're around six bucks at Walmart. That one's for US Nema 5 receptacles . Surely they make one for the outlets in your country.

Sorry to sound like a worried aunt but we don't know your skill level nor do we know who else might read this thread.
Keep things safe for tiny fingers in your household, they're naturally curious.

old jim
 
Last edited by a moderator:
  • Like
Likes   Reactions: TheRedDevil18 and Tom.G
Thanks guys, I now added some fuses and changed R6 to 220ohms, I now have this circuit

Schematic of a triac light dimmer with a 1.5A fuse, 50mA fuse, MOC3021 optocoupler, Q4004L3 triac, PC817 optocoupler, 2W04G bridge rectifier, and ATmega32 microcontroller pins.


Need some help with the fuse current rating, this is how I calculated it

Since the PC817 can take a maximum current through the LED of 50mA, I used a 50mA fuse.

Then I checked the triac and it says "surge capability up to 55A" http://www.littelfuse.com/products/switching-thyristors/triac/lxx04xx-qxx04xx/q4004l3.aspx
The moc3021 can take max 1.2A

So my total current(peak) = Current drawn by bulb + current drawn by moc3021
= 60W/230V + 230V/220ohm
= 0.26A + 1.05A
= 1.31A

So maybe 1.4A, 1.5A fuse ?

And what type resistors should I be using ?, thick film ones ?

And, do I need a snubber between the triac ?
 
TheRedDevil18 said:
And what type resistors should I be using ?, thick film ones ?
i think my one inch suggestion was way overboard. Some of our equipment used resistors that big to protect against 480 volts...

http://www.vishay.com/docs/28737/nfr25.pdf
http://www.vishay.com/docs/31031/cmffuse.pdf

The fuses you picked should do admirably.
R2 protects U5, R6 protects U6...

Incandescent lamps draw a lot of inrush current so either pick a slow-blow or test for a faster one that reliably lights the lamp when you start it at full brightness. Typical inrush is about 10X normal.
https://en.wikipedia.org/wiki/Incandescent_light_bulb
Current and resistance
The actual resistance of the filament is temperature dependent. The cold resistance of tungsten-filament lamps is about 1/15 the hot-filament resistance when the lamp is operating. For example, a 100-watt, 120-volt lamp has a resistance of 144 ohms when lit, but the cold resistance is much lower (about 9.5 ohms).[57][107] Since incandescent lamps are resistive loads, simple phase-control TRIAC dimmers can be used to control brightness. Electrical contacts may carry a "T" rating symbol indicating that they are designed to control circuits with the high inrush current characteristic of tungsten lamps. For a 100-watt, 120-volt general-service lamp, the current stabilizes in about 0.10 seconds, and the lamp reaches 90% of its full brightness after about 0.13 seconds.[108]
i've used MDL for some high inrush loads. You'd probably be fine with a 1 amp MDL.
http://www1.cooperbussmann.com/pdf/98a9c763-9040-4280-a255-151b3dbca2f3.pdf

Here's a common fast blow fuse
http://www1.cooperbussmann.com/pdf/b040436b-cbc7-495d-95a6-99fe85202786.pdf

and a tutorial on fuseology
http://www.littelfuse.com/~/media/e.../littelfuse_fuseology_selection_guide.pdf.pdf

Have fun !

old jim
 
  • Like
Likes   Reactions: TheRedDevil18
Thanks jim
Schematic of a mains light dimmer circuit with a 1A fuse and R6 220 ohm resistor feeding optocoupler U6 MOC3021, a 300mA slow blow fuse, triac U8 Q4004L3 driving lamp L1 230V, a 50mA fuse, bridge BR1, R2 15k, optocoupler U5 PC817, R3 10k, and an ATMEGA16 microcontroller pin PB0/T0/XCK connected to the circuit.


I now basically put 3 fuses (those black boxes). I read about slow blow fuses and they basically allow a high inrush current for a small period of time before blowing. Since the bulbs normal peak current is I = P/V = 60W/230 = 260mA, I put a 300mA slow blow to allow the inrush current which is about 3.64A (14*normal)

The 1A fuse is for protecting U6

The 50mA is for U5, since 50mA is the LED's max current

Not too sure, what do you think ?, is it fine ?

Not too sure if they even have fuses with those current ratings, I googled a few and they did come up though
 
TheRedDevil18 said:
Not too sure, what do you think ?, is it fine ?

Not too sure if they even have fuses with those current ratings, I googled a few and they did come up though

It's thorough.

Myself i'd loosen up a little
use a single 1 amp to protect both U8 and the lamp socket, rely on R6 to fuse if it needs to save U6.
Old technician's saying: "Semiconductors are great fuse protectors. "

There's no inrush to your bridge so a good fast acting fuse will work.
I'd rely on R2 to protect U5 and pick a fuse that protects BR1. He looks to be a 2 amp bridge, and you need only a fraction of that
AGC is a common fast acting fuse available in 1/16 amp . I think that'd be sensible.

I do like that you placed your triac in the high side line.
When it's placed in the neutral,
that leaves this part of the socket and lamp "hot" when off and it's an invitation to get shocked changing a lightbulb that you think is switched off.

Annotated photo of a lamp socket with red handwritten notes: 'if you switch the neutral open, it makes this hot through the bulb' and 'inviting a shock here when relamping' pointing to the bulb's metal base.


My two cents. Overpriced at that, probably.

old jim
 
I'd go for a 2A fuse if that's still well within the triac's rating. The semiconductors will probably melt well before the fuse; anyway. You don't want the fuse element to be thermal cycling every time you use the equipment or it will slowly degrade. And sooner or later the bulb will blow or get broken and the nearest replacement on hand will be a higher wattage than you'd originally planned.
 
  • Like
Likes   Reactions: jim hardy