Component guide · Advanced · 3 min read
AC Dimmers, Triacs and SCRs
Controlling Mains Loads
By Geekobot Learning Team · Updated 24 Oct 2026
On this page
An AC dimmer controls a mains load by switching a triac on partway through each half cycle. A zero-cross detector tells the microcontroller when the AC wave passes 0 V, and the code waits a delay before firing the triac through an optocoupler. A longer delay means less power. This works for incandescent lamps, heaters and universal motors, but not most LED lamps or induction motors. Mains is lethal, so use an enclosed, isolated module.
Key specs at a glance
- Triacs
- BT136 (4 A), BT138 (12 A), BTA16 (16 A): conduct both directions
- SCRs
- Conduct one direction; used in pairs or with rectifiers, battery chargers
- Zero-cross
- Optocoupler output pulsing at 100 Hz on 50 Hz mains
- Opto driver
- MOC3021 (random phase) or MOC3041 (zero-cross switching only)
- Timing
- 0 to 10 ms delay after each zero cross on 50 Hz mains
- Cooling
- About 1 to 1.5 W lost per amp in the triac; heatsink needed
This part is often wired to 230 V mains. Do all wiring with the plug pulled out, keep mains wires inside a closed box with strain relief, add a fuse, and never touch the board while it is plugged in. If you are new to mains wiring, have an electrician check it before you switch on.
How phase control works
Indian mains is 230 V at 50 Hz, so each half cycle lasts 10 ms. A triac stays off until its gate is triggered, then conducts until the current reaches zero at the end of that half cycle.
- 1The zero-cross circuit sends a pulse at each zero crossing.
- 2The microcontroller waits a delay: 1 ms gives nearly full power, 9 ms very little.
- 3It pulses the opto driver, which fires the triac for the rest of that half cycle.
A library such as RBDdimmer handles the timing using interrupts and a timer. Power does not change linearly with delay, so use a lookup table for even brightness steps.
Which loads you can dim
incandescent and halogen lamps, heaters, soldering irons, universal (brushed) motors in drills and mixers.
LED and CFL lamps; even then, they may flicker.
induction motors (fans, pumps) except with a controller made for them, transformers not rated for it, and electronics with their own power supplies.
For simple on and off switching of mains, an SSR or relay is simpler. Zero-cross SSRs cannot dim; they switch only at zero crossings.
Mains safety
- The triac's heatsink tab is often live. Insulate it or use an isolated-tab part.
- Keep the whole module in a closed, earthed or double-insulated enclosure, with no exposed screw terminals.
- Fuse the live wire and size wiring for the load.
- The microcontroller must connect only to the optocoupler side. Never connect a USB-connected board to mains-side ground.
- Add an RC snubber for inductive loads.
- If you are not trained in mains wiring, use a certified commercial dimmer or have an electrician check your build.
Try it: Power dissipation calculator
Change the values and the diagram and results update as you type.
Common mistakes to avoid
- Touching the module or heatsink while plugged in.
- Dimming non-dimmable LED lamps or induction fan motors.
- Using a MOC3041 zero-cross opto for phase dimming.
- No heatsink on the triac at high current.
- Exposed mains terminals and no fuse.
Frequently asked questions
Can Arduino control a 230 V lamp brightness?
Yes, with an isolated triac dimmer module that has zero-cross detection, in a safe enclosure.
What is the difference between a triac and an SCR?
A triac conducts in both directions and suits AC; an SCR conducts in one direction only.
Can I dim a ceiling fan with a triac module?
Not reliably. Fans use induction motors that need dedicated fan regulators.
Why does my dimmer flicker?
Timing jitter from other code, noisy zero-cross pulses, or a load that is not dimmable.
What is zero-cross detection?
Sensing when the AC voltage passes 0 V so the controller can time each half cycle.
Parts for this guide
Calculators
Terms in this guide
Keep learning
Sources
- WeEn BT136/BT138 triac datasheets
- onsemi MOC3021 and MOC3041 datasheets
- ST AN-439 triac phase control application note
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.


