The circuit I made in LED exponential current control didn’t solve everything I wanted in an LED controller.
The major issue is that it doesn’t allow for the LED to be fully turned off. Another minor issue is that the LED max current changes with the supply voltage. The first could be solved with adjusting the circuit so the op-amp outputs are never near ground or the supply voltage. The second by adding a voltage reference.
At the start, I wanted to make a circuit without a microcontroller, but solving these issues would add more components and at this point switching to a microcontroller would actually reduce complexity. It adds the need to write code for the microcontroller and to program it.
The original goal of the previous circuit was to make a perceptually uniform LED controller. Making it with op-amps limited the input-to-output transform to be exponential. With a microcontroller this can be programmed to anything, so I chose the sRGB-to-linear transfer function. It is a closer match to human vision.
I choose the ATTiny412 microcontroller for its SOIC-8 package size and having worked with Arduino and AVR microcontrollers in the past. Initially I only had a requirement of a 14-bit PWM output and a 10-bit Analog-to-Digital converter. But after experimenting with different current control schemes I also use the Digital-to-Analog output to set the LED current.
After some experimentation and broken components I settled on the following circuit.

Arduino source code: led_srgb_lightness.cpp
The input is controlled with a potentiometer that is read by the ATTiny412 ADC, pin PA1. It transforms the input using a lookup table into a PWM signal on the PA7 pin.
The PWM output controls the input to the non-inverting input of the op-amp to either be 0V (off) or the DAC-voltage (on) from ATTiny412. The op-amp then uses this to control an NPN-transistor to adjust the current for the LED, such that both inputs to the op-amp have the same voltage.
In the circuit the LED current is set to 1.1V / 220Ω ≈ 5.0mA. This can be adjusted by changing the DAC output or by choosing a different resistor.
I built the circuit on a bread board to check if all my assumptions agree. It works as I want it to.

I have added 100nF decoupling capacitors and supply connections that are not shown in the circuit diagram above.
Switching to a microcontroller from op-amps for transforming the input to a perceptually uniform output was a good choice. The sRGB curve is better than the exponential curve. It also allows for the addition of fully off and fully on zones at the ends of the potentiometer, making the adjustment easier.
The drawback is that there is now a programming step needed to make the circuit operational.
I am overall happy with the changes and plan to use it for future projects needing LED lightness control.
© 2026 Mats Mattsson