# Digital Dimmer With Microcontroller

I want to build a digital dimmer for resistive Loads. I have found this circuit for that:

• The input voltage is 220VAC 50Hz.
• The red box in the picture is for Zero Crossing Detection.

When the AC voltage crosses the zero, the Microcontroller will be interrupted an therefore detects the zero crossing. so you can reach to the required voltage by triggering the Triac after a specific Delay.Do you recommend this circuit? if so, please let me know if there is any IC to replace with the Red Box (shown in the picture) to detect the zero points of AC voltage (as my circuit should be as small as possible)?

P.S. As I need this circuit to reduce the consumed energy of Loads, the circuit itself must dissipate at most 5 watts.

-

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).

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:

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.

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:

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

-
This other answer of yours also explains it very well. –  m.Alin Jul 13 '12 at 15:23
Of course. I was just pointing to an additional source of information. –  m.Alin Jul 13 '12 at 15:29
Steven I am really sorry but I am not very professional. will you help me figure this out?? where shall I put my Microcontroller? and as you said the first Image can be replaced by the Red Box plus rectifier. So can I connect the R1 and R2 directly to the 220VAC???? If yes what should be the Values of R1 and R2?? I am confused. :( –  Mehrdad Kamelzadeh Jul 13 '12 at 16:48
@Mehrdad - Yes, R1 and R2 go directly to the 220 V. The calculation is somewhat involved, and depends on the type of optocoupler you choose. This question explains the calculation in complete detail. Read it, twice if necessary. The 2k pull-up resistor goes to +5V, it agrees with your R12 (value: again, see calculation). The pin indicated by the pulse goes to PD2INT0, the bottom pin is ground. –  stevenvh Jul 13 '12 at 16:57
@stevenvh the SFH620A you suggested was exactly what I wanted. But the price of that is expensive in my country as I want that for mass production. So I used the Zero Crossing Detector circuit which Bruno has sent here. Now to make everything clear for myself and to see that I have gotten everything right, I redraw the circuit and combined them. Just tell me your recommendations and if I have made mistake in that or it's just fine. I did that according to your post and the datasheets. imagetoo.com/images/toshow.jpg –  Mehrdad Kamelzadeh Jul 14 '12 at 7:55

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.

-
I have to use Microcontroller. Where should it be in this circuit? –  Mehrdad Kamelzadeh Jul 13 '12 at 19:32
You should connect the signal marked as OUT to your interrupt pin. –  Bruno Ferreira Jul 13 '12 at 19:34
Do you agree with the Load part of my circuit? have you got any suggestion or recommendation or it's just fine? –  Mehrdad Kamelzadeh Jul 13 '12 at 19:41
For the load I would follow stevenvh advice. If you want isolation from mains for zero cross detection, you should also isolate the load control. Depending on the output current of your microcontroller and the characteristics of the opto-triac you use you may not nedd the transistor to drive the opto-triac. –  Bruno Ferreira Jul 13 '12 at 19:46

This application note 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.

-
I have seen that but I think this is not energy efficient. Is it? –  Mehrdad Kamelzadeh Jul 26 '12 at 10:07
How would it not be? The current through 2M&ohm; resistors at 220V is ~24mW. –  trygvis Jul 26 '12 at 22:53
so would please tell me what are the pros and cons between this method and the other which @Stevenvh has provided here (I am sorry If I raise very fundamental questions as I am not very professional) ? –  Mehrdad Kamelzadeh Jul 27 '12 at 10:20