Digital Dimmer With Microcontroller

In the answers to this question is explained how you can do that complete zero-crossing detection circuit with just U1, R12 and 2 series resistors on the 220 V side. One solution uses a common optocoupler, the other one a Darlington optocoupler, which needs less current to drive the optocoupler's LED, so that's less power in the series resistors (less than 200 mW for the complete zero-crossing detector).

enter image description here

This replaces the red box plus the rectifier at the left.

edit dd. 2012-07-14
If an AC input optocoupler is too expensive, then you can use a common optocoupler with a 1N4148 in anti-parallel:

optocoupler

You'll have the advantage of lower cost and wider offering. The LTV-817 costs only 10 cent in 1000 quantity, yet has a respectable 50 % CTR. For only 2 cent more you get the LTV-815, which has a Darlington output. Instead of 1 positive pulse every half period you'll have a positive pulse a bit longer than half a period.

enter image description here

If the mains frequency is 50 Hz then one period is 20 ms. If then the positive pulse is 12 ms long you know that it covers two zero-crossings symmetrically. Since the zero-crossings are 10 ms apart there was one 1 ms after the start of the 12 ms pulse, and one 1 ms before the end. So you know that the next zero-crossing will be 9 ms after the end of the pulse.
This is very easy in software and keeps BOM cost low.
(end of edit)

But watch out with the triac driver. The input is isolated from the mains through the optocoupler, but apparently they forgot that on the driver side, so the circuit is directly connected to the mains after all, and therefore possibly lethal!

You need an optocoupler on that side as well. Typical application from the MOC3051 datasheet:

enter image description here

Make sure to use a random phase optocoupler (like the MOC3051).


I'm not aware of any IC that can replace a full zero-cross-detector, but I have been using this circuit and it works quite well and it has a very low power consumption.

Zero cross detector

You can find more information here.


This application note (AVR182: Zero Cross Detector) from Atmel describes how you can do zero-crossing detection with two 1MΩ resistors. This involved connecting the mains signal directly to the MCU which may or may not be a good idea, but it is very efficient in terms of components. If you're only going to drive the TRIAC it might not be a bad idea.

Just remember to insulate stuff when if you're debugging etc.

Edit: Updating URL to relocated application note.