Most of the circuits to fade/dim a LED are digital circuits using a PWM output of a microcontroller.
The brightness of the LED is controlled by changing the duty cycle of the PWM signal. Soon you discover that when linearly changing the duty cycle, the LED brightness does not change linear. The brightness will follow a logarithmic curve, meaning that the intensity changes fast when increasing the duty cycle from 0 to lets say 70% and changes very slow when increasing the duty cycle from lets say 70% to 100%.The exact same effect is also visible when using a constant current source and increasing the current linear f.e. by charging a capacitor with a constant current.
In this instructable i will try to show you how you can make an analog LED fader that has a brightness change that appears to be linear to the human eye. This results in a nice linear fading effect.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Theory Behind the Circuit
In the figure, you can see that the brightness perception of a LED has a logarithmic curve due to the Weber-Fechner law, saying that the human eye, just like the other senses, has a logarithmic curve. When the LED just starts "conducting" the perceived brightness increases fast with increasing current. But once "conducting", the perceived brightness increases slow with increasing current.
So we need to send an exponential changing current (see picture) through the LED so the human eye (with a logarithmic perception) perceives the brightness change as being linear.
There are 2 ways to do this :
- Closed loop approach
- Open loop approach
Closed loop approach:
When taking a close look at LDR (cadmium sulphide) cell specifications, you will see that the LDR resistance is drawn as a straight line on a logarithmic scale. So the LDR resistance changes logarithmic with light intensity.Furthermore, the logarithmic resistance curve of an LDR seems to match the logarithmic brightness perception of the human eye pretty close. That is why the LDR is a perfect candidate to linearize the brightness perception of a LED.So when using an LDR to compensate for the logarithmic perception, the human eye will be pleased by the nice linear brightness variation.
In the closed loop, we use an LDR to feedback and control the LED brightness, so it follows the LDR curve.
This way we get an exponential changing brightness that appears to be linear to the human eye.
Open loop approach:
When we don't want to use an LDR and want to get a linear brightness change for the fader, we need to make the current through the LED exponential to compensate for the logarithmic brightness perception of the human eye. So we need a circuit that generates an exponential changing current. This can be done with OPAMP's, but i discovered a simpler circuit, that uses an adapted current mirror, also called a "current squarer" because the generate current follows a square curve (semi-exponential).
In this instructable, we combine both the closed loop and the open loop approach to get an alternating fading LED. meaning that one LED fades in and out while the other LED fades in and out with opposite fading curve.
Step 2: Schematic1 - Triangular Waveform Generator
For our LED fader, we need a voltage source that generates a linear increasing and decreasing voltage.
We also want to be able to change the fade in and fade out period individually.
For this purpose we use a symmetrical triangular waveform generator that is constructed using 2 OPAMPs of an old workhorse : LM324.
U1A is configured as a schmitt trigger using positive feedback and U1B is configured as an integrator.
The frequency of the triangular waveform is determined by C1, P1 and R6.
Because the LM324 is not capable of delivering enough current, a buffer consisting of Q1 and Q2 is added. This buffer provides the current gain that we need to drive enough current into the LED circuit. The feedback loop around U1B is taken from the output of the buffer, instead from the output of the OPAMP. because OPAMPs don't like capacitive loads (such as C1).
R8 is added to the output of the OPAMP for stability reasons, because emitter followers, such as used in the buffer (Q1, Q2) can also cause oscillations when driven from a low impedance output.
So far, so good,
The oscilloscope picture shows the voltage at the output of the buffer formed by Q1 and Q2.
Step 3: Schematic2 - Closed Loop LED Fader Circuit
To linearize the brightness of a LED, an LDR is used as a feedback element in a closed loop arrangement. Because the LDR resistance versus light intensity is logarithmic, it is a suitable candidate to do the job.Q1 and Q2 form a current mirror that converts that output voltage of the triangular waveform generator into a current via R1, which is in the "reference leg" of the current mirror. The current through Q1 is mirrored to Q2, so the same triangular current flows through Q2.D1 is there because the output of the triangular waveform generator does not fully swing to zero, because i'm not using a rail-to-rail but an easy obtainable general purpose OPAMP in the triangular waveform generator.The LED is connected to Q2, but also the Q3, that is part of a second current mirror.Q3 and Q4 form a current sourcing mirror. (See : Current mirrors) The LDR is put in the "reference leg" of this current sourcing mirror, so the resistance of the LDR determines the current generated by this mirror. The more light falls on the LDR, the lower it's resistance and the higher the current through Q4 will be. The current through Q4 is mirrored to Q3, which is connected to Q2. So now we have to think in currents and not in voltages anymore.Q2 sinks a triangular current I1 and Q3 sources a current I2, that is directly related to the amount of light that falls on the LDR and follows a logarithmic curve. I3 is the current through the LED and is the result of the linear triangular current I1 minus the logarithmic LDR current I2, which is an exponential current.And that is exactly what we need to linearize the brightness of a LED. Because an exponential current is driven through the LED, the perceived brightness will change in a linear way, which has a much better fading/dimming effect than just running a linear current through the LED.
The oscilloscope picture shows the voltage over R6 (=10E), that represents the current through the LED.
Step 4: Schematic3 - Open Loop LED Fader Circuit Using Current Squarer
Because LED/LDR combinations are not standard components, i searched for other ways to geneate an exponential or squaring current through a LED in an open loop configuration. The result is the open loop circuit shown in this step.
Q1 and Q2 form a current squaring circuit that is based on a current sinking mirror. R1 converts the triangular output voltage, which is first divided using P1, to a current, flowing through Q1. But the emitter of Q1 is not connected to ground via a resistor, but via 2 diodes. The 2 diodes will have a squaring effect on the current through Q1. This current is mirrored to Q2, so I2 has the same squaring curve.Q3 and Q4 form a constant current sinking source. The LED is connected to this constant current source but also to the current sinking mirror Q1 and Q2. So the current through the LED is the result of the constant current I1 minus the squaring current I2, which is an semi-exponential current I3.This exponential current through the LED will result in a nice linear fading of the perceived brightness of the LED.
P1 should be trimmed so the LED just goes off when fading out.
The oscilloscope picture shows the voltage over R2 (=180E), that represents the current I2, which is subtracted from the constant current I1.
Step 5: Schematic4 - Alternating LED Fader by Combining Both Circuits
Because the LED current in the open loop circuit is inverted when compared to the LED current in closed loop circuit, we can combine both circuits to create an alternating LED fader in which one LED fades in while the other fades out and vise versa.
Step 6: Build the Circuit
- I only build the circuit on a breadboard, so i don't have a PCB layout for the circuit
- Use a high efficiency LEDs because these have a much higher intensity at the same current than the older LEDs
- To make the LDR/LED combination, put the LDR (see picture) and LED face to face in a shrinking tube (see picture).
- The circuit is designed for supply voltage from +9V to +12V.