Fade light 220VAC

NOTE _ I've done this before, but with a different microcontroller.

I'm a newbie in electronics so i think to put a capacitor (with a diode I think) to allow an slow increase voltage in the light, this means a simple fade in and fade out...

:frowning: It's not quite so simple with AC power. A light dimmer works by turning on & off once per half-cycle (100 times per second at 50hz line frequency).

For example, if you turn the power on at the positive AC peak (90 degrees), off at the zero-crossing, and on again at the negative peak (270 degrees), you effectively get half-voltage. If you turn-on near 0 degrees, you get full-brightness. If you turn-on near 180 degrees, the light will be very dim. Of course, you don't need to know the phase angle, you just calculate the time from the zero-crossing, based on your power line frequency.)

You also need to isolate the power line voltage from your low-voltage control circuit.

First, you need to detect the zero-crossings (or near zero crossings). A comparator on the secondary of your power transformer should work. (The transformer provides isolation for the phase-detection part of the circuit.) There may be some phase-shift through the transformer, so you might have to experiment with the timing.

On the AC power side, you use a triac. Once a triac is triggered, current flows until the power is cut-off. i.e. If you give it a short trigger pulse at 90 degrees it will stay on 'till the zero crossing, then it will shut-off 'till you trigger it again.

There are special opto-isolators designed for driving triacs, and this provides isolation on the output side of the circuit.

I'd suggest you start by building the AC triac/isolator part of the circuit, and write a program to turn the AC on & off, before working on the phase/dimmer part of the project. (It's hard to debug the phase detector without the AC side working. :wink: )

P.S.
You should be able to use an analog input, rather than a comparator. And, a full-wave rectifier (separate from the power supply rectifier, and not filtered with a capacitor) will allow you to detect both-halves of the AC cycle. Since there is a voltage drop across the rectifier, you'll be looking for a voltage a short time after the zero crossing... But you can calculate (and experiment) to compensate for the delay and trigger on the next half-cycle.

P.P.S.
Actually, a single rectifier (diode) should work... Once you find a zero crossing, you know exactly when the next one is coming...