Recently I posted fun project with code and circuits to simulate candles (Candlelight Simulation with Arduino NANO - Exhibition / Gallery - Arduino Forum ). The code made use to the standard PWM calls, and the PWM outputs were simply amplifed by transistors to control low voltage "warm white" LEDs, or small incandescent bulbs.
I wonder if anyone can recommend possible electrical and code approaches to controlling the brightness of 120VAC incandescent lamps with the PWM outputs. Obviously it would be nice to be able to take advantage of the properties of triacs, the wy a standard light dimmer does. But that, at the very least, would require synchronizing the Arduino PWM timers to be synchronized with household line frequency. Otherwise, the resulting PWM would be completely unpredictable. So if line frequency in the USA is 60hZ, and the standard PWM divides the timer into 256 possible duty cycle options, that would mean the timers would have to be set 60 x 2 x 256, or 30,720Hz. Not only that, but the these timers would have to synchronize with the line frequency on every zero crossing.
Of course another way, I guess, would be to use high voltage transistors or MOSFETs, and rectify and filter the AC, so the lamps could be driven with DC. But I think that would require some big expensive filter capacitors.
One final method I've considered is to start with standard cheap light dimmers, and replace its potentiometer with resistive photo cells. Then I could direct an ordinary LED at the photo cell and control that LED with the Arduino PWM outputs. It seems like a Rupe Goldberg approach, but it does seem simpler than trying to brute force filter the AC to DC, or trying to synchronize the Arduino timers with household AC.
But I'm sure someone else has already considers this kind of thing.
PeterPan321:
But I'm sure someone else has already considers this kind of thing.
Right, search the forum or web for such projects.
You're on the right track but PWM won't work because a TRIAC won't shut-off 'till the next zero-crossing. You have to monitor the AC waveform to find the zero-crossing, then wait some period of time before triggering the TRIAC. You only have to "pulse" the triac once per half-cycle. Of course, you need electrical isolation (usually optical isolation) on both of these.
[u]TRIAC dimmers[/u]
Of course another way, I guess, would be to use high voltage transistors or MOSFETs, and rectify and filter the AC, so the lamps could be driven with DC. But I think that would require some big expensive filter capacitors.
You wouldn't need filtering.
P.S.
I didn't look at the flickering project, but you can flicker a regular incandescent light bulb by pulsing a TRIAC at random times for a random period of time. You don't need "dimming" or synchronization with the power line. i.e. If you pules the light or less than ~1/10th of a second it won't get up to full-brightness. You'd have to experiment with maximum & minimum limits, but it should work reasonably well. You could even use a relay, although a regular electro-mechanical relay will make a lot of noise and isn't very "high tech".
Thanks Guys. So it looks like a zero crossing detector along with an opto-isolator DIAC (like the MOC3021) to control the triac in an otherwise basic AC light dimmer circuit (and of course appropriate code) is the most straight forward way. I may give that a try.
Since I've already written the code for the candle simulation, which controls up to 6 LEDs via PWM (see my previously linked article, Candlelight Simulation with Arduino NANO - Exhibition / Gallery - Arduino Forum), I still may try my last idea. That is, use a standard existing light dimmer circuit like this one (http://www.circuitstoday.com/wp-content/uploads/2009/09/triac-lamp-dimmer-circuit.jpg) and replace the adjustment pot with with a photo-resitive (Cadmium based) isolator. That way my existing code, outside of its already adjustable parameters, probably wouldn't have to change.
I'm not sure the end result would have a clear technical advantage over just writing some new support code for the other method. I would use up an extra digital input, but I'd only need one zero crossing detector, even if I wanted to independently control multiple lamps. But I would have to build those circuits from scratch. Not lazy, but I'm thinking standard AC light dimmers for regular incandescent bulbs (like the one I linked) can be had for barely $2 in some markets. So it might make an easier starting point.
I'll probably try both methods and see which comes out cheaper. 