Summary of How to control LM2596 buck-converter with microcontroller
Summary: The article explains how to control a cheap LM2596 buck converter with a microcontroller by injecting an external voltage into the converter's feedback node. A microcontroller generates PWM, the PWM is low-pass filtered and buffered with an op amp, and that voltage is summed with the converter's feedback divider to change output voltage. Stable MCU supply and proper resistor sizing (example: 990 ohm with 330 ohm lower resistor for 5V PWM to get 1.25V) are emphasized.
Parts used in the Control LM2596 Buck-Converter with Microcontroller:
- LM2596 buck converter module
- Microcontroller (for PWM generation, e.g., Arduino)
- RC low-pass filter (resistor and capacitor)
- Operational amplifier configured as voltage follower
- Fixed resistor on buck converter feedback divider (330 ohm in example)
- Adjustable resistor or external resistor for feedback divider (calculated 990 ohm example)
- Stable power supply for the microcontroller
- Wiring/connectors
Every now and then someone asks on different forums if there is an way to control cheap LM2596 modules with an Arduino or another microcontroller. I decided to demonstrate one solution that might be basic electronics for some, but still many don’t know about.
Those buck converters will change the output voltage to make the feedback pin, connected to the output via a voltage divider, become 1.25V or so. If feedback is higher, output gets lower and vice versa. If one changes the ratio of resistors in voltage divider, output voltage will change. This is usually done by turning a trimmer resistor with a screwdriver. That is good enough for many applications where voltage will be set only once, but sometimes there is a need to adjust the output voltage more frequently.
External voltage can pull the feedback pin’s voltage higher or lower when applied to it through a resistor. That would make a summer circuit where output voltage of buck converter and external voltage are inputs and output is junction which connects to the feedback pin connects. That external voltage can be generated with just about any microcontroller. Microcontroller generates PWM signal, which is smoothed with RC low pass filter and then buffered with an operational amplifier configured as a voltage follower. Thanks to Hackaday’s Al Williams for pointing this out: I didn’t remember to mention this clearly enough in the video: Circuit shown in this demonstration needs to have really stable power supply for the microcontroller, as the PWM signal’s amplitude depends on the power supply. So any changes on power supply’s voltage will affect the amplitude of the generated voltage and therefore the buck-converter’s output voltage.
In my demonstration the PWM-signal’s maximum voltage and therefore maximum signal generated is 5V. When buck converter’s maximum output is set high enough (lets say 12->V) adjustable resistor’s (which is one between output and feedback) resistance will be relative high compared to the resistance of buck converter module’s fixed resistor (which is 330ohm in this case). Therefore when trying to adjust converter’s output to zero or as low as possible with microcontroller, the output voltage’s effect to voltage on feedback pin will be marginal. Therefore we just need to figure out resistor for voltage divider that divides 5V to 1.25V, where lower resistor is 330 ohm. That is simple task: R = (5V * 330ohm – 1.25V * 330ohm)/1.25V = 990ohm
For More Details: How to control LM2596 buck-converter with microcontroller
- How does the buck converter regulate its output?
The buck converter adjusts output so the feedback pin voltage becomes about 1.25V using a resistor divider from the output to the feedback pin. - Can a microcontroller change the buck converter output?
Yes, by generating an external voltage via PWM, low-pass filtering it, buffering with an op amp, and applying it to the feedback node through a resistor the MCU can adjust the output. - What role does the RC low-pass filter play?
The RC low-pass filter smooths the PWM into a DC voltage that represents the desired adjustment voltage. - Why use an op amp as a voltage follower?
The op amp buffers the filtered PWM voltage to provide a stable drive into the feedback network without loading the filter or MCU. - Does the microcontroller supply need to be stable?
Yes, the MCU supply must be very stable because the PWM amplitude depends on the MCU supply and will directly affect the generated voltage and the buck output. - What resistor values are used in the example?
The fixed lower resistor on the buck module is 330 ohm and the calculated upper resistor for dividing 5V to 1.25V is about 990 ohm. - How is the 990 ohm value calculated?
Using the divider relation to get 1.25V from 5V with lower resistor 330 ohm: R = (5V*330 - 1.25V*330)/1.25V = 990 ohm. - What happens if the buck converter output is set much higher than the PWM amplitude?
When the converter output is high and the adjustable resistor is large relative to the fixed resistor, the converter output has only marginal effect on the feedback pin, letting the external PWM-derived voltage control the output down toward zero.

