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.
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:
@Alex Houben The analog input cannot be PWM, it must be a smooth DC voltage. Also make sure that you have tune the circuit properly with the potentiometers
I use your pic dimmer in combination with a velleman VM140 ( http://www.velleman.eu/products/view/?country=be&lang=en&id=369162 )
The analog outputs are used a input for your dimmer. But when I dim the lights they blink approximately > 20% dim.
I was wondering: This Analog out generates a PWM DC voltage; how does your dimmer handle this? Perhaps it is better with a capacitor?
Alex
At 1 December 2014, 18:00:28 user taher wrote: [reply @ taher]
Hi
It's nice project. I want to make one on PIC. Can you show me the way how to load .Hex(binary) file to PIC12f615 micro controller using PIC2Kit? please reply ASAP
At 22 September 2014, 14:45:00 user nadmie wrote: [reply @ nadmie]
Hello.do you build the mini project for ir remote control for dimmer that can adjust the brightness such as from 0% until 100% or From dim to bright. Please reply asap. Tq :)
@Mat The PIC dimmer needs no setup, the 555 version needs to set up the period of the signal. Also the PIC dimmer can operate through all 0-100% brightness, the 555 cannot.
At 30 August 2014, 22:23:59 user Mat wrote: [reply @ Mat]
Hi there
Can you help me compare this circuit with the 555 version you wrote about?
What is different between this and the 555 dimmer? I see you can set GLMinVal and GLMaxVal which is really good and I guess there is no equivalent in the other circuit?
Basically I'm looking to make a 4 channel 5V DC controlled standalone dimmer which can be controlled by arduino from the analog outputs...
Sir,
This circuit of zero crossing detector is not working.I have used same circuit.in this the transistor Q1 is always ON. So I am not getting Pulse output. Any help would be appreciated.
Sir,
I have a simple question. I didn't got how you connected triac. you have connected the gate terminal directly with live. How? according to my knowledge gate terminal has to be connected to microcontroller using transistor to provide negative triggering to triac. Please explain.
At 14 September 2013, 18:49:26 user Miro wrote: [reply @ Miro]
Hello. I have one simple question.
When I'm connecting this dimmer to mains voltage should I always check in wall socket (where I want to plug dimmer) where is neutral and where is line and connect it as it's shown in schematic.
What will happen if I reverse neutral and line?
For example in my house sockets are mainly connected with line on the right side, but some of them are different. It'll be absurd if I have to check in every room where are line and neutral if I want to use this dimmer.
I hope you understand what I mean.
Cheers!
@Cheerio Hello Cheerio! The point is that when the TRIAC is turned ON, it will not turn OFF until the voltage across A1 and A2 is 0. That being said, if you send a pulse to the gate at say 10 degrees and you turn this pulse off at 11 degrees, the TRIAC will continue to conduct until 180 degrees where the voltage becomes 0 again. In other words, sending PWM to a TRIAC will only keep the TRIA ON all the time.
Hey kam!
I am just wondering why you bother with ther zero cross detection. What about generating a pwm signal and use a dutycycle stepping of 10ms. the zerocrossing detection is done by the optocoupler and the dimming effect will average i guess.
Can you give me your opinion on this? your zerocross detection is most likely not a coincidence.
At 14 April 2013, 2:01:58 user ZHEN wrote: [reply @ ZHEN]
just wondering this circuit .. i saw the lamp is connect to DC part ...and why called AC dimmer ..... and i want to know how to control to the AC lamp in high voltage site...may u reply me ...
@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?
@Hrinkleson Actually almost any other triac (that fits your needs) will work. Choose one according to your power requirements. PIR sensor is a totally different case - it will not work here.
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?
@Alex Use an inverting transistor to invert your signal. The 555 cannot accept other pulse to operate.
At 17 October 2012, 14:23:00 user Alex wrote: [reply @ Alex]
Hi Giorgos,
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.
At 27 July 2012, 16:04:28 user Erik wrote: [reply @ Erik]
@Giorgos Lazaridis Thanks.I saw in your code (correct me if I'm wrong) that MCLR is on.If it is,shouldn't then be something connected on pin GP3(5 volts through 4,7 Kohm resistor)?
@Erik I'm sorry but i cannot offer changes in programs whatsoever, i have too little time.
At 22 July 2012, 22:56:02 user Erik wrote: [reply @ Erik]
Hello.
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.
Thank you.
@Alek 3.2VA at 12V is some 250mA, which is more than enough. And the rectifier is ok as well.
At 17 July 2012, 19:42:38 user Alek wrote: [reply @ Alek]
@Giorgos Lazaridis
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.
At 8 July 2012, 22:34:12 user Alek wrote: [reply @ Alek]
@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...
At 4 July 2012, 16:52:19 user Alek wrote: [reply @ Alek]
Hello.Great project!
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.
Thank you.
Alek
@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 ?
@Rich i've been told that again from people using a specific IE version. Try with mozilla or chrome
At 10 December 2011, 7: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
@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, 16: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
@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, 15: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..
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.
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.
R7 is to be changed but the specification you have to find it yourself
At 3 March 2011, 19: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.
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.
At 23 December 2010, 12: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.