Discrete Alternating Analog LED Fader With Linear Brightness Curve




Introduction: Discrete Alternating Analog LED Fader With Linear Brightness Curve

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.

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.

Be the First to Share


    • Make it Glow Contest

      Make it Glow Contest
    • Clocks Contest

      Clocks Contest
    • Cold Challenge

      Cold Challenge



    5 months ago

    This is an excellent tutorial. Thank you for the all the time it must have taken to put something like this together. The current squaring circuit is fascinating. Could you by any chance direct me to a source where I could learn more about how it works?

    In a test circuit the current through the left hand transistor seems to remain linear but the right hand transistor has the demonstrated exponential properties. The output voltage seems to be proportional to (x-1)^2 and the output current to 1-(x-1)^2. (Just guessing comparing curves.)

    Also the output amplitude seems to peak at a certain value for the right hand emitter resistor.

    function graphs.pngcircuit.pngmeasured results.png
    Roel Arits
    Roel Arits

    Reply 5 months ago

    Hi shawcp,

    Thank you for your nice words.I designed the circuit for an analog LED fader contest that was organised by the Elektor Magazine. I won the contest with it because of the use of techniques to create a semi-exponential current. Our eyes, as well as our ears have a logaritmic intensity curve, so you need to compensate for that using an exponential intensity curve or something that comes close to an exponential curve, f.e. a square curve. There are several ways to do that with electronics (anti-log circuit with an OPAMP using the non-linearity of a diode..), but i chose for the current squarer. You really need to think in currents instead of voltages with that circuit, because it is the current through a LED that defines the intensity and not the voltage.
    If you check the squarer circuit and you leave out the 2 diode, you have a simple transistor current mirror (for more info, see: https://sites.google.com/site/roelarits/home/articles/current-related-topics/current-sources
    When you would feed the simple current mirror with a triangular waveform (via the R10 resistor from your simulation schematic), the output current would be a reproduction of the input triangular waveform. The resistor + current mirror convert the triangular voltage into a triangular current. Adding equal value emitter resistors between the emitter of both transistors and reference ground creates some negative feedback. This makes the current mirror less sensitive for differences between the characteristics of both transistors and for temperature changes.
    And now comes the trick: by replacing one of the emitter resistors with 1 or multiple diodes, you add non-linearity to the current mirror. Now the current mirror will not reproduce the triangular waveform and convert it to a triangular current, but it will add non-linearity (due to the exponential voltage/current curve of the diode(s)). That is the basic of how the squarer works. The resistor that is still in the emitter of the other transistor defines the size of the output current, which is 2x the diode voltage drop (because we use 2 diodes in series) divided by the value of that resistor.
    So now we have a current that is non-linear with "upward round bumps", but in fact we want to reverse these bumps, so we get "upward sharp peaks" that show an exponential/square rising and falling current. That is where the constant current source comes in. This constant current source is built using 2 transistors and runs a constant current through the LED. The current squarer sinks current away from this constant current source and thus away from the LED. So the LED gets a constant current, but the current of the squarer is subtracted from it. That is where you see the (a - X^2) kind of function where a is the constant current and X^2 is the current from the squarer that is subtracted from this constant current. The constant current from the constant current source defines the maximum intensity of the LED fader. The current from the current squarer has to be tweaked so it subtracts just enough current from the constant current source for the LED to dim almost completely when the current of the current squarer is at it's maximum. This way the LED will fade in and out between maximum and minimum with a nice exponential/square curve.

    I came across the schematic for the current squarer in a book: "Analogue IC Design: the current mode approach" by C. Toumazou, F.J. Lidgey and D.G. Haigh of 1990

    You can also find it in: "Handbook of analog circuit design" by Dennis L. Feucht of 1990.

    It is kind of complex if you are a beginner or are not used to think in currents, but you already got close to figuring out how it works and i hope this explanantion helped you a bit. :-)


    Question 3 years ago on Step 6

    could you input the triangular waveform into a LM317 that acts as a current source for mid-power leds?

    Roel Arits
    Roel Arits

    Answer 3 years ago

    The current source used in the instructable has an exponential behaviour to compensate for the logarithmic perception of our eyes. When you use the triangular waveform to control the LEDs, the brightness of the LEDs will not fade in a linear way

    An LM317 can be used as a fixed constant current source by using its internal reference voltage of 1.25V, but i don't see how you would turn the LM317 into a variable current source in combination with the triangular waveform generator output.
    You could simply connect an NPN medium power transistor configured as an emitter follower to the output of the triangular waveform generator so you have a higher output power to drive LEDs directly.
    The next problem will be that the triangular waveform generator output does not swing from rail to rail. That means that the output does not go down to 0 volts, So if you want the LEDs to go off completely, you will need to bring the output voltage down with a couple of diodes in series or a zener diode.

    DIY Hacks and How Tos

    These are some really well written electronics tutorials. Thanks for sharing with the community.

    Roel Arits
    Roel Arits

    Reply 5 years ago

    Thank you for the nice compliment !