Arduino Forum

Using Arduino => General Electronics => Topic started by: kilian23 on Jul 15, 2013, 01:11 pm

Title: Controlling Triac by Arduino
Post by: kilian23 on Jul 15, 2013, 01:11 pm
Hello!

Because I want to avoid messing around with DMX, I decided to dim up and down some 220V lights with a triac instead. I have googled a little bit, but the codes I found so far are not clear to me. I have no schematics either. Can anyone help me out? Maybe someone has done that before. I would need specific parts number, a wiring diagram, and some code. Would be great! AC in my case means 220V, 50Hz, by the way. Dimming means increasing or decreasing the light intensity seamlessly between 0 and 100 percent. If someone has a code how to use values received from a regular 10K analog potentiometer on the input of the Arduino for the Triac's gate - then I can figure out the rest for my own purpose.

Thanks,

Kilian
Title: Re: Controlling Triac by Arduino
Post by: PaulS on Jul 15, 2013, 03:23 pm
Quote
I have googled a little bit, but the codes I found so far are not clear to me. I have no schematics either. Can anyone help me out?

After googling, you have no schematic? That's hard to believe.

As for the code not being clear, you haven't shown any code or explained what isn't clear. So, clearing it up will be problematic.

Quote
If someone has a code how to use values received from a regular 10K analog potentiometer on the input of the Arduino for the Triac's gate - then I can figure out the rest for my own purpose.

What is the potentiometer to be used for? The analogRead() function already reads the data. How to use that data is up to you.

The amount of dimming you get from a triac is based on the time after the zero-crossing event occurs that you trigger the output. Short time == little dimming. Long time == lots of dimming.
Title: Re: Controlling Triac by Arduino
Post by: DVDdoug on Jul 15, 2013, 08:31 pm
The amount of dimming you get from a triac is based on the time after the zero-crossing event occurs that you trigger the output. Short time == little dimming. Long time == lots of dimming.
Which means you have to detect the AC zero-crossing.  It's usually easier to detect only the positive-going zero-crossing.   At 50Hz, you know the negative-going zero-crossing is comming 10 milliseconds later. 

I built a dimmer several years ago with a different microcontroller, so I can only give you some hints & concepts -

The most important thing is isolation.  You need to isolate yourself and the Arduino from the AC line voltage.  There are special optoisolators (http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/MOC302x.pdf) designed to drive TRIACS.  Do NOT get a "zero-crossing" optoisolator.  It won't work as a dimmer.

You'll also need to isolate your phase detection (zero crossing) circuit.   For that, you can use a "regular" optoisolator, or a transformer.  (In my circuit, I used the same transformer that was powering my microcontroller.)

Wikipedia (http://en.wikipedia.org/wiki/TRIAC#Application) has a little animation showing how a phase-controlled AC dimmer works with a TRIAC.
Title: Re: Controlling Triac by Arduino
Post by: KeithRB on Jul 15, 2013, 08:42 pm
For my senior project in college I created a slide-projector dimmer. I used a transformer-isolated zero crossing detector that interrupted my CDP1802 microproccesor. It then counted down by a preset amount. small counts - like zero - would make for a bright bulb, while long counts would dim it. I always allowed for a small amount of power in the bulb to decrease in-rush current and lengthen bulb life.
Title: Re: Controlling Triac by Arduino
Post by: kilian23 on Jul 20, 2013, 08:09 pm
OK, thanks for your input.
If I reach more problems or any solutions, I will post them here.
K
Title: Re: Controlling Triac by Arduino
Post by: joemcder on Jul 20, 2013, 10:13 pm
Check out this instructable:

http://www.instructables.com/id/Arduino-controlled-light-dimmer-The-circuit/

Note the safety warnings.  There MUST be an optoisolator in the circuit.

Title: Re: Controlling Triac by Arduino
Post by: dc42 on Jul 20, 2013, 11:04 pm
You can simplify the circuit in that instructable, by replacing the opto isolator used to detect zero crossings by one that accepts AC input, such as this http://uk.farnell.com/avago-technologies/hcpl-814-w60e/optocoupler-ac-wide-vde/dp/1604640 (http://uk.farnell.com/avago-technologies/hcpl-814-w60e/optocoupler-ac-wide-vde/dp/1604640). Then you don't need a bridge rectifier to feed it.
Title: Re: Controlling Triac by Arduino
Post by: kilian23 on Jul 23, 2013, 04:58 pm
Quote
Check out this instructable:

http://www.instructables.com/id/Arduino-controlled-light-dimmer-The-circuit/

Note the safety warnings.  There MUST be an optoisolator in the circuit.


Thanks a lot!
I'm trying right now, based on your schematics and code.
I'll post my results.

Kilian
Title: Re: Controlling Triac by Arduino
Post by: kilian23 on Jul 23, 2013, 05:08 pm
Quote
You'll also need to isolate your phase detection (zero crossing) circuit.   For that, you can use a "regular" optoisolator, or a transformer.  (In my circuit, I used the same transformer that was powering my microcontroller.)


Yes, I'll use a transformer for isolating the AC power source from the zero detection circuit. For detection, I'm trying with an ET1102 right now.
Let's see...
Title: Re: Controlling Triac by Arduino
Post by: kilian23 on Jul 24, 2013, 07:40 pm
First of all: Thank you all very much for your help. I know very well, I'm just one more of those annoying noobs, and the more I appreciate your assistance.

Okay, as promised: results...

I have accomplished
to detect the (falling) zero crossings and to drive my triac behind the optocoupler using the code on http://www.instructables.com/id/Arduino-controlled-light-dimmer-The-circuit/step3/Arduino-Controlled-Lightdimmer-The-Software-II/, as provided in the link posted by joe mcd. (For some reason, I could not get the code working that was written by the author personally, as available on http://www.instructables.com/id/Arduino-controlled-light-dimmer-The-circuit/step2/Arduino-controlled-light-dimmer-The-software/.)

At some point, I will post the schematics I'm using (zero-crossing as well as triac unit), as soon as I have all details figured out completely. In my final result, I will use a transformer to galvanically separate the 220V AC power source from the zero detection optocoupler, and I will use the power output from that same transformer (after rectifyer and capacitor) to feed my Arduino. So it will be an all-in-one-box dimmer solution with an Arduino, 220V plug input, 220V dimming outlet, a few indicator LEDs, switches and trimmers, and a connector to my external sensors (ultrasonic range finders SRF02).