So basically I want to build a dimmer circuit. If I connect an optocoupler to the PWM pin on the MCU and a triac to the optocoupler with an incandescent bulb and generate a square wave something like this:

enter image description here

In the above example I was using 80% brightness. So basically, the mains frequency is 50Hz and so the generated square wave would be 100Hz with 80% duty cycle. How well would this work ?


2 Answers 2


so the generated square wave would be 100 Hz with 80% duty cycle.

Yes, you would trigger the triac 100 times per second.

No, you don't need a square wave. You just need a pulse. Once triggered the triac will stay on until the next zero cross.



You don't want PWM, what you want is to detect the zero crossing (using an isolated circuit, of course) and then delay between almost nothing and almost one half cycle and at the end of that delay you spit out a narrow pulse (something like 100usec) through a (NON-zero crossing type) triac-output optocoupler MOCxxx.

If you are too close to the beginning of the AC cycle the triac/triac opto will not reach holding current and you get no light rather than close to 100% so you could stretch the pulse a bit if it's at the beginning of the cycle.

If your pulse extends just a bit past the next zero crossing then you will get 100% rather than 0%.

  • \$\begingroup\$ @Deadshot, as said by others, you wouldn't/couldn't produce a PWM waveform but would be using phase control instead. There's plenty on phase control on the Internet that you can read further on. \$\endgroup\$
    – TonyM
    Commented Sep 13, 2016 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.