Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Simplest way to build a light dimmer using PWM

  1. Sep 12, 2016 #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 ?
     
  2. jcsd
  3. Sep 12, 2016 #2

    berkeman

    User Avatar

    Staff: Mentor

    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:
     
  4. Sep 12, 2016 #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
     
  5. Sep 12, 2016 #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.
     
  6. Sep 13, 2016 #5

    NascentOxygen

    User Avatar

    Staff: Mentor

    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.
     
  7. Sep 16, 2016 #6
    Guys, I tried building the circuit, heres 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
     
  8. Sep 16, 2016 #7

    berkeman

    User Avatar

    Staff: Mentor

    The light needs to be in series with the triac... :smile:
     
  9. Sep 16, 2016 #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...
     
  10. Sep 16, 2016 #9

    berkeman

    User Avatar

    Staff: Mentor

    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.
     
  11. Sep 16, 2016 #10

    berkeman

    User Avatar

    Staff: Mentor

    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?
     
  12. Sep 16, 2016 #11
    I modified the circuit to this,
    upload_2016-9-16_21-4-55.png

    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 lets 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 wont 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
     
  13. Sep 16, 2016 #12

    NascentOxygen

    User Avatar

    Staff: Mentor

    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
     
  14. Sep 16, 2016 #13

    jim hardy

    User Avatar
    Science Advisor
    Gold Member
    2016 Award

    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: May 8, 2017
  15. Sep 17, 2016 #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 ?
     
  16. Sep 17, 2016 #15

    jim hardy

    User Avatar
    Science Advisor
    Gold Member
    2016 Award

    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.
    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
     
  17. Sep 17, 2016 #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
     
  18. Sep 17, 2016 #17

    jim hardy

    User Avatar
    Science Advisor
    Gold Member
    2016 Award

    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
     
  19. Sep 17, 2016 #18

    NascentOxygen

    User Avatar

    Staff: Mentor

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Simplest way to build a light dimmer using PWM
  1. Automatic Light Dimmer (Replies: 2)

Loading...