Simplest way to build a light dimmer using PWM

In summary: 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?I connected the optocoupler so that the output was "high" when the AC mains voltage was above 5v and "low" when the AC mains voltage was below 5v. I then used a diode to switch between these two voltages using a PWM signal on the
  • #1
TheRedDevil18
408
1
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
  • #2
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:
 
  • #3
Simplest one's I could find where these,
2250358200_1385025158.jpg


upload_2016-9-12_19-41-39.png


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

IMG_20160912_195745.jpg


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
 
  • #4
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.
 
  • #5
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.
 
  • #6
Guys, I tried building the circuit, here's the schematic:
upload_2016-9-16_16-24-26.png


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
 
  • #7
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:
 
  • #8
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...
 
  • #9
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.
 
  • #10
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 TheRedDevil18
  • #11
I modified the circuit to this,
upload_2016-9-16_21-4-55.png


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
 
  • #12
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 TheRedDevil18 and jim hardy
  • #13
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 [Broken] , page 4

upload_2016-9-16_22-43-17.png

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 TheRedDevil18 and Tom.G
  • #14
Thanks guys, I now added some fuses and changed R6 to 220ohms, I now have this circuit

light dimmer 2.PNG


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 ?
 
  • #15
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 TheRedDevil18
  • #16
Thanks jim
upload_2016-9-17_20-7-20.png


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
 
  • #17
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.

edison_neutral.jpg


My two cents. Overpriced at that, probably.

old jim
 
  • #18
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 jim hardy

1. How does a PWM light dimmer work?

PWM (Pulse Width Modulation) is a technique used to control the amount of power supplied to a light source. It works by rapidly turning the light on and off, with the ratio of on-time to off-time determining the perceived brightness. A longer on-time results in a brighter light, while a longer off-time results in a dimmer light.

2. What components are needed to build a PWM light dimmer?

The simplest PWM light dimmer requires a microcontroller, a MOSFET transistor, a resistor, a potentiometer, and a power source. The microcontroller generates the PWM signal, the MOSFET acts as a switch to control the power to the light, the resistor limits the current, the potentiometer adjusts the duty cycle, and the power source supplies the necessary voltage.

3. Is building a PWM light dimmer difficult?

Building a basic PWM light dimmer is not difficult, as it only requires basic electronic components and some knowledge of programming. However, it can become more complex when trying to control multiple lights or integrating it into a larger system.

4. What are the advantages of using a PWM light dimmer?

PWM light dimmers offer several advantages over traditional dimmers. They are more energy-efficient, as they do not dissipate excess energy as heat. They also provide a smoother and more precise dimming control, as the duty cycle can be adjusted in small increments. Additionally, they have a longer lifespan as they do not have any mechanical components that can wear out over time.

5. Can a PWM light dimmer be used for all types of light sources?

In general, PWM light dimmers can be used with most types of light sources, including incandescent, LED, and fluorescent lights. However, some light sources may require additional circuitry or modifications to work properly with a PWM dimmer. It is always recommended to consult the manufacturer's specifications before using a PWM dimmer with a specific type of light source.

Similar threads

  • Electrical Engineering
Replies
23
Views
4K
  • Electrical Engineering
Replies
21
Views
5K
Replies
17
Views
2K
Replies
6
Views
446
  • Electrical Engineering
Replies
10
Views
794
Replies
69
Views
4K
Replies
11
Views
2K
Replies
4
Views
3K
  • Electrical Engineering
Replies
9
Views
3K
  • DIY Projects
Replies
5
Views
304
Back
Top