With TJ Byers
I am a beginner just learning electronics. Can you tell me how to fade an LED up and down?
LEDs are current operated devices, where the brightness increases as the current through the LED increases. The current through the LED is defined by a series resistor, where I = E - Vdiode / R. (A full discussion of LED operation can be found in the February ‘06 issue.) For the sake of this discussion, let’s assume we have a red LED at full brightness, with a six-volt voltage source and a 1K current limiting resistor. Plugging the values into the formula, we get I = 6 - 2 / 1000 = 4 mA.
To reduce the brightness by one-half, simply reduce the voltage to four volts (I = 4 -2 /1000 = 2 mA). This can be done manually using the potentiometer. The output voltage of the op-amp follows the voltage at the tap of the potentiometer, and controls the brightness of the LED. If you want to do this automatically, then you need to add another op-amp.
In this circuit, the first op-amp serves as a square wave oscillator. The second amp is an analog integrator that extracts a triangular wave from the square wave. When this slowly rising voltage is applied to an LED, it gradually brightens to full. On the downswing, it grows dimmer until it eventually goes off.
This method has the disadvantage of going dark when the input voltage goes below the LED’s forward voltage. In the example above, the LED turns off once the declining voltage across the diode drops below two volts. And it stays off until the waveform voltage exceeds two volts — after which it brightens to full and instantly starts dimming. The solution is pulse-width modulation (PWM).
With this technique, full voltage is always applied across the LED, so there is no “dead time.” What causes the brightness to change this time is the width of the driving pulse. When the supply voltage is applied only 50% of the time, the LED appears — to the eye — to be half as bright. By varying the duty cycle of the voltage, we can go from off to full brightness without any dead time. The figure below shows a 555 timer circuit that lets you manually adjust the duty cycle from 0%
The bottom circuit replaces the pot with a digital up/down counter. There are four outputs, each of which carries a weighted value. That is, when Q3 is on, it represents a current that’s eight times (8x) more than the current value of Q0. Be placing equally-weighted resistors in series with the outputs and the LED, we create a perfect fade-on/fade-off effect. A single 4093 gate generates the clocking pulses. A 4027 J-K flip-flop changes the direction from count up to count down — causing the outputs to go from full off to full on and back again.
I’m sure readers have their own LED fader circuits. If you wish to share your favorite with other readers, just post them in the comments.