Home     Contact     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Tech-BLOG     RSS     Terms of services     Privacy policy  
 Home     Contact     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Tech-News     RSS   

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

IMPORTANT
DANGER 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.




Adjusting the circuit

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
R1Resistor 1 KOhm 1/4 Watt 5% Carbon Film 
R2Resistor 10 KOhm 1/4 Watt 5% Carbon Film 
R35 KOhm potentiometer
R4Resistor 4.7 KOhm 1/4 Watt 5% Carbon Film 
R5Resistor 470 KOhm 1/4 Watt 5% Carbon Film 
R6Resistor 10 KOhm 1/4 Watt 5% Carbon Film 
R72.2 KOhm potentiometer
R8-9Resistor 220 Ohm 1/4 Watt 5% Carbon Film 
Capacitors
C1100 pF ceramic capacitor
C21000 uF 16 Volts electrolytic capacitor
Integrated Circuits
IC17805 Positive Voltage Regulator 
IC2PIC12F615 Microcontroller 
OK1MOC3021 Random Phase Optoisolator TRIAC Driver Output 
Transistors - TRIACs
Q1BC548 Switching and Applications NPN Epitaxial Transistor 
T1BT136D Sensitive gate TRIAC 
Diodes
D11N4001 General Purpose Diode Rectifier 
B12W10M 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




  •  Rate this article!


    Comments

  • At 25 January 2012, 14:51:06 user Kammenos wrote:   [reply @ Kammenos]
    • @Scottie no there is no problem with this. You may wanna replace R7 with a 5K potentiometer instead and remove this resistor.


  • At 25 January 2012, 14:27:56 user Scottie wrote:   [reply @ Scottie]
    • Hi there again (wrote on 13 Jan). Tried the circuit, works well. Only I found that I needed a 2k2 Ohm resistor between 5V and the 2k2 trimpot to get a turn off point middway otherwise the trimpot had to be fully anticlockwise. Any downside in the PIC ADC calculation by adding this ?


  • At 13 January 2012, 18:03:46 user Kammenos wrote:   [reply @ Kammenos]
    • @Scottie i think i had this 7805 with the heatsink already... not necessary indeed.


  • At 13 January 2012, 9:51:33 user Scottie wrote:   [reply @ Scottie]
    • Hi there, great circuit, looking forward to trying this out next week. Can you tell me one thing - why do you have a heat sink on the 7805, I would expect only a relatively small current used in the 5 volt section with only the PIC and optocoupler devices ?


  • At 13 December 2011, 0:52:47 user Kammenos wrote:   [reply @ Kammenos]
    • @Rich i've been told that again from people using a specific IE version. Try with mozilla or chrome


  • At 10 December 2011, 2:26:58 user Rich wrote:   [reply @ Rich]
    • Hi:

      2nd e-mail about this. For some reason I can not view the assembly code listing. I like to build this circuit and need to program the PIC. Could you e-mail me the assembly code listing? Many thanks in advance. Richard


  • At 2 November 2011, 2:49:38 user Kammenos wrote:   [reply @ Kammenos]
    • @Pratik if you know how dimmer works and a little bit about assembly, then this is a simple program. The main idea is that within the MainLoop, it constantly reads the ADC to get new TriggerDelay value, which is actually the delay from the time that the circuit detects a zero-cross, until the PIC triggers the triac.
      Then, in Cont1 the pic tests the timer0 module. This module becomes zero every time that the PIC detects zero-cross (interrupt routine). If the tmr becomes higher than the TriggerDelay, then the PIC activates the triac (bsf Trigger). The triac gate is also cleared within the interrupt routine.
      Dimmers always add some kind of noise in the power lines. To avoid noise, you need to add filters, but i am not good at this. A small load will not add significant noise. But remember that a hair dryer adds much more noise than any dimmer.
      As for the halogens, i have never test anything with them, so i cannot answer.


  • At 1 November 2011, 12:50:49 user Pratik wrote:   [reply @ Pratik]
    • Great post and great work,
      I am doing this same project and i want to dim three halogen. It would be great of you if i get some help in understanding your assembly program. I need to know what are you doing in the program. About How and when is the triac triggered . A good flowchart and little explanation will clear my doubts.I have heard that noise is generated with this methos . Is it true.If yes what is the other solution.
      Also i want to know whether i can convert ac to dc and then make use of IGBTS or Mosfet to dim the halogens. If so How can I do this. Any ideas can be useful to me.
      regards,
      Pratik


  • At 25 July 2011, 5:35:29 user Alex Houben wrote:   [reply @ Alex Houben]
    • Ok thanks for the quick respond!

      I'll try to write my own code, keep up the good work!
      Alex


  • At 25 July 2011, 0:47:47 user Kammenos wrote:   [reply @ Kammenos]
    • @Alex Houben i'm sorry there is no picbasic code, only assembly.


  • At 24 July 2011, 14:56:20 user Alex Houben wrote:   [reply @ Alex Houben]
    • Hi,
      I have build the project and it works perfectly!!!

      Is it possible to post the picbasic sourcecode, if it exists.
      I want to build a multichannel dc controlled dimmer with one pic.

      Thanks in advance!

      Alex

      Belgium


  • At 22 April 2011, 1:46:50 user Kammenos wrote:   [reply @ Kammenos]
    • @DAVID there is no mistake. I checked. This is what datasheet states about ANSEL,3
      bit 3 - ANS3: Analog Select Between Analog or Digital Function on Pin GP4
      1 = Analog input. Pin is assigned as analog input(1).
      0 = Digital I/O. Pin is assigned to port or special function.

      It is for GP4 (pin 3)


  • At 16 April 2011, 11:30:02 user DAVID wrote:   [reply @ DAVID]
    • bsf ansel,3 ; 1000 GPIO 3 IS ADC INPUT

      YOUR CODE SEEMS TO SET gpio3 AS INPUT FOR ADC BUT IS INFACT CONNECTED TO GPIO4 ON PIN 3 WHICH bit is wrong the code or the schematic..

      All the best David


  • At 6 April 2011, 8:52:50 user Kammenos wrote:   [reply @ Kammenos]
    • @nmol sure, any pic can run similar code and circuit. Choose one with more pins.


  • At 6 April 2011, 8:24:57 user @nmol wrote:   [reply @ @nmol]
    • is there any pic controller which can be useful fr 4 channel ac load dimmer


  • At 3 April 2011, 1:54:01 user Kammenos wrote:   [reply @ Kammenos]
    • @Bryan microgeo answered


  • At 3 April 2011, 1:42:46 user microgeo wrote:   [reply @ microgeo]
    • I was interested in the zero-crossing too but that is unfiltered "DC" after the rectifiers. Enough to trigger the pulse in his circuit. I used this to learn circuit modeling and the model generates a beautiful pulse just like his video.


  • At 2 April 2011, 23:02:46 user Bryan wrote:   [reply @ Bryan]
    • Zero crossing point detection is only used on AC circuits, so why did you bother putting it on this DC circuit, its not doing anything. the bridge rectifier is producing DC from the AC, so anything after the bridge is DC, and does not have a sinusoidal wave for the zero point to detect. Your just wasting components and potentially endangering your life by messing around with mains voltage when you obviously have no idea what your doing.


  • At 1 April 2011, 5:14:11 user Kammenos wrote:   [reply @ Kammenos]
    • @Raavan i have also upload the assembly file. No C code is available. I program only in assembly.


  • At 1 April 2011, 1:52:43 user Raavan wrote:   [reply @ Raavan]
    • Hello Everyone.
      I have a doubt regarding the programming of the microcontroller. You have actually given the binary file, is it possible for the programmer(the brain behind the heart of the circuit) to upload the algorithm and if possible the c program of the same binary file.
      Thank You well in advance and I hope for a quick reply.


  • At 18 March 2011, 14:44:17 user Kammenos wrote:   [reply @ Kammenos]
    • the assembly listing fits only for this PIC.


  • At 18 March 2011, 6:43:01 user dee wrote:   [reply @ dee]
    • and If I use an ATMEGA 8 BIT MCU will the code/assembly listing will remain same?


  • At 18 March 2011, 6:41:14 user dee wrote:   [reply @ dee]
    • Can I use a different MCU of same configuration like that of ATMEGA MCU of 8 bits?


  • At 17 March 2011, 16:09:58 user Kammenos wrote:   [reply @ Kammenos]
    • the chip is enough, but you need the programmer.


  • At 17 March 2011, 15:37:35 user dee wrote:   [reply @ dee]
    • hi Kammenos
      For PIC12F615 , just this chip will work or I have to also get the development board?


  • At 4 March 2011, 9:29:06 user Kammenos wrote:   [reply @ Kammenos]
    • dee, it is tie T1 BT136D triac.


  • At 4 March 2011, 3:53:00 user dee wrote:   [reply @ dee]
    • hi
      in the circuit ,what is the part in the end numered as 1 2 3. and is this lamp getting an ac circuit or DC. Could you explain me the lamp part..


  • At 3 March 2011, 16:26:22 user Kammenos wrote:   [reply @ Kammenos]
    • R7 is to be changed but the specification you have to find it yourself


  • At 3 March 2011, 14:48:16 user dee wrote:   [reply @ dee]
    • hi,
      for using it for automatic light regulation , which part is to be replaced with photocell and which photocell(specifications)we have to use.
      pls help its urgent.


  • At 11 January 2011, 9:47:40 user microgeo wrote:   [reply @ microgeo]
    • This is an excellent and well-explained analog and digital project. Being new to PICs, while the circuit and video make sense, I am struggling with programming since I use basic. Would you mind helping myself and others with a description of the logic of your programming? Much appreciated!


  • At 23 December 2010, 9:20:53 user Kammenos wrote:   [reply @ Kammenos]
    • I would never sleep quiet if i had a dimmer without galvanic insulation between mains and PIC. I began with a huge resistor (4 o 8 MOhms i do not remember), and worked perfectly, until i asked myself one single thing: And if the resistor fails??? It is most unlikely, but again, this galvanic insulation keeps the circuit itself safer as there is no connection with ground.


  • At 23 December 2010, 7:34:52 user Matt wrote:   [reply @ Matt]
    • Excellent approach, especially with regards to electrical safety. I have seen other designs which are directly coupled to the mains but I prefer this way to get the zero-crossing signal after isolating from the mains with the transformer. Use of the optocoupler on the triac side again keeps the pic safely isolated from the mains. Brilliant - I will choose this approach for my dimmer circuit design and I hope others will too.


  • At 22 December 2010, 0:24:31 user Kammenos wrote:   [reply @ Kammenos]
    • No sorry. i do only assembly.


  • At 21 December 2010, 17:44:08 user Mert wrote:   [reply @ Mert]
    • Hi,
      this is very good project but i can't understand assembly code. Do you have ccs code of this project?

      Pls help


     

      Name

      Email (shall not be published)

      Website

    Notify me of new posts via email


    Write your comments below:

          






    delicious
    digg
    reddit this Reddit this
    Faves

    Search PCB Heaven


     HOT in heaven!



    PCB Heaven chirps on Follow me on Twitter

    TAGS cloud

    Dimmer  PIC Microcontroller  Light  AC Light Controller  Electronic Circuit 



    NEW in heaven!



    New Calculus: Common Base transistor amplifier - Design Calculator

    Random Circuits!
     PIC 3-Wire Fan RPM Controller
     PWM LCD Contrast Adjustment



     Home     Contact     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Tech-News     RSS   

    Site design: Giorgos Lazaridis
    © Copyright 2008
    Please read the Terms of services and the Privacy policy