I have relay conected with arduino and high voltage bulb, now how can I control voltage to fade in and out bulb? I know that a relay is an on off device so maybe a triac or IGBT would be needed?Would an optpcoupler be good for isolation? Should I use a PWM output on the arduino?
2 Answers
With a relay? You can't.
The relay contacts are either open (lamp fully off) or closed (lamp fully on) and can't switch a relay fast enough to give a dimming effect.
simulate this circuit – Schematic created using CircuitLab
What you're looking for is a triac controlled dimmer.
In this case an opto-coupled triac is used. Your micro would switch the LED D1 on at the appropriate point in the mains half-cycle turning on the triac. The triac stays on until the next zero-cross of the mains and then turns off. At 100 (50 Hz) or 120 (60 Hz) half-waves per second the flicker is not noticeable.
Your code would have to monitor the mains zero-cross somehow, ramp the delay in triggering the triac and pulse the optoisolator at the right time. Plenty of examples on a web search.
+1 for the opto-coupled triac.
Opto-couplers are nice because you can "drive" the circuit as if you were controlling an LED. Throw a resistor in series and you can separate your arduino from the high voltage.