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:
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.
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:
@Giorgos Lazaridis Thanks for your reply. I have tested my optocoupler and triac and both seem to be working, but the problem persists. The incoming voltage is 240V, would I have to change the assembler code? I noticed your circuit runs of 220V. Thanks again.
I have built this circuit using and LDR instead of R7, and programmed my PIC in MPLAB. However, when I give the circuit power, the lap flicks on for an instant, and doesnt come back on. Any suggestions what that might be?
Hi George. Can you suggest an alternative to the BT136D triac? I have replaced the potentiometers with light dependent resistor circuit to make it automatic dimming. If i wanted to add a PIR sensor circuit, where would that go?
When I check my scoop you trigger in the rising edge. Is it also possible to send me of publish a hex file for descending edge. I want to use my own zero cross, but it is wider. If you want I'll send you a scoop picture of my zero cross.
I'm trying to rewrite program for c but I don't understand assembly code(what are commands exactly doing).
Can you write comments in the commands line so I can know what is code exactly doing.You can upload notepad with comments here or send it to my mail adress.
Hy once again.
Yesterday I bought 220/12V 3.2VA.They oferred me trafos betwen 2 and 30 VA.
Is that ok or should I take another trafo with different VA?
And also I bought W10M Single Phase 1 Amps Silicon Bridge Rectifier.They didn't have 2 Amps rectifier.
@Alek well, 5V after the 2 diodes of rectification will become some 3.4V which are not suitable for stable operation. The wires i used are all thin wires from UTP cable... there are no large currents on the board, unless you use a big bulb in watts.
Remember to use precision potentiometers for the setup otherwise you will get a headache to stable it.
@Giorgos Lazaridis Thank you for your answer.I have two more questions.
Which transformer did you use?I have 220/5V transformer at home.If I use that one should I remove R2 resistor or change something in schematic?
And can you tell me what thickness of the wire did you use for breadboard test-run
@Alek I kinda chose them from an educated guess. Resistors R4 R5 will perform a voltage divider to the base of Q1 which makes the voltage much less. C1-R1 performs a small low pass filter. R2 can be omitted if the transformer's voltage is small.
Whenever the base voltage is above 0.7 volts (Q1's Vbe voltage), Q1 saturates and current passes through the CE contact. So, the output voltage of the transistor is 0 (or nearly 0). But whenever the voltage is below 0.7, the transistor is in cutoff and no current goes through CE, so all voltage appears at the edge of R6. This is your pulse...
I have one question that is maybe not usual.How did you calculate elements(resistors,capacitors and transistor) for zero crossing detection and how this sheme exactly works.How we get impuls at the zero crossing.
@Delusional hmmm i'm not quite sure, but actually i do not think that you need to change anything. The transformer mst be 110/12, the MOC works for 110 as well... the timing is flexible so you can adjust it for 60... so hopefully it will work as-is.
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 ?
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 ?
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
@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.
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.
@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.
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.
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.
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.
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!
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.
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.