Home      Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science

24 April 2010
Author: Giorgos Lazaridis
PIC DCV Controlled AC Light Dimmer

 IMPORTANTDANGER OF ELECTRIC SHOCK!Read this before taking any further action!!!Precautions to avoid electric shock

The circuit mounted on a breadboard for test-run

Safety First: The high voltage circuitry is covered with a plastic transparent cup.

Actually, i plan to make a 4-channel DC controlled lamp dimmer. Unfortunately, looking in my stock cabinet, i found out that i had run out of 16F690... Yet, i had to make the programming ASAP! Thus, i made a single channel PIC with the 12F615. I will use the same routine for the 4-channel dimmer, when the courier arrives.

If you do not know how the AC Dimmer works, try this link:

How Dimmer works

You may also want to know more about TRIACs:

How TRIACs work

If you want to see another dimmer without a microcontroller (only with a 555), visit this link:

Voltage Controlled AC Light Dimmer

The circuit in operation

The Circuit

This dimmer, like the 555 dimmer that i made some weeks ago, will be controlled with a DC voltage level. The original design will be controlled with 0 to 5 volts, but using a voltage divider, you can increase this number as much as you like. I use a potentiometer to adjust the control DC voltage, you can use whichever DC voltage source. You may use for example a photocell and a resistor to make an ambient light equalizer...

Here is the schematic diagram:

The transformer is used to provide both power to the circuit and to get the zero cross detection pulse. The 7805 is used to fix the supply to 5 Volts. There are 2 potentiometers connected in series. The first one (R7), is used to set the minimum luminosity (that needs the maximum trigger delay). The R3 is used to control the dimmer! This is actually the control potentiometer.

I hate messing high and low voltages. SAFETY FIRST! That's why i use the transformer for the zero cross detection (and not just some 4 MOhm resistors), and that's why i use the optocoupler. I use the MOC3021, for Greece has 220V mains. For 110/120 volts you may consider using the MOC3011. Check out the datasheet of the MOC series (find it in the Bill Of Materials section at the end of this article).

I use the BT136D TRIAC to control the lamp. It can handle up to 4 Amperes load. Translated into wattage for 220 Volts lamp, this is up to 880 Watts lamp... It is enough for your household lamps, isn't it? If not, then use another TRIAC.

The adjustment of this circuit is very simple. First of all you need to connect the potentiometer R3 correctly, so that when is turned to the left, the lamp will fade. If you are sure that is connected correct, proceed to the next step.

Put the R7 in the middle. Turn the R3 completely to the left (OFF position). Then turn it a few degrees to the right, not too much, about 2 degrees. Using a insulated small screwdriver, turn the R7 slowly and steady, so that the lamp is turned off. When the lamp is off completely, the dimmer is adjusted! That's it.

The Firmware

Not much to say about the firmware. There are 2 parameters that you may need to change, if the frequency of your power supply is not 50Hz. The GLMinVal, sets the minimum trigger delay value - that is the maximum luminosity. This parameter defines the point above which the lamp will be 100% powered. The GLMaxVal on the other hand, controls the max trigger delay - that is the minimum lamp luminosity. This is the value below which the lamp is turned off completely. Change the values with caution if you are not 100% sure what you are doing.

Here is the full assembly listing for the firmware, to compile and upload:

 PIC Dimmer - Assembly listing

If you do not want to change anything and simply upload the firmware, here is the binary ready for upload:

 PIC Dimmer - Binary file

Bill Of Materials (Second circuit)
 Resistors R1 Resistor 1 KOhm 1/4 Watt 5% Carbon Film R2 Resistor 10 KOhm 1/4 Watt 5% Carbon Film R3 5 KOhm potentiometer R4 Resistor 4.7 KOhm 1/4 Watt 5% Carbon Film R5 Resistor 470 KOhm 1/4 Watt 5% Carbon Film R6 Resistor 10 KOhm 1/4 Watt 5% Carbon Film R7 2.2 KOhm potentiometer R8-9 Resistor 220 Ohm 1/4 Watt 5% Carbon Film Capacitors C1 100 pF ceramic capacitor C2 1000 uF 16 Volts electrolytic capacitor Integrated Circuits IC1 7805 Positive Voltage Regulator IC2 PIC12F615 Microcontroller OK1 MOC3021 Random Phase Optoisolator TRIAC Driver Output Transistors - TRIACs Q1 BC548 Switching and Applications NPN Epitaxial Transistor T1 BT136D Sensitive gate TRIAC Diodes D1 1N4001 General Purpose Diode Rectifier B1 2W10M Single Phase 2 Amps Silicon Bridge Rectifier

Relative pages
• Learn how dimmers work
• The SCR (Silicon Control Rectifiers) theory
• The TRIAC theory
• The voltage divider theory
• How to make an Ambient Light Level Equalizer
• How to make a light / dark activated switch - 3 different circuits under the microscope
• Voltage controlled light dimmer circuit
• Learning PICs @ PCB Heaven On-Line Book