Go Down

Topic: DC/DC Converter Controller using Arduino (Read 683 times) previous topic - next topic


I want to make DC/DC Converter Controller Using Arduino. I read a lot of information but now I am confused. My aim is to control high power leds and keeping constant current. I also need to use PID controller in project. I found pdf about how to do buck converter  using PIC chip, but my question is if is possible to use instead of PIC chip, Arduino?
Most of all, I'm interested in circuit on page 6  "current source".
Here's a mentioned pdf -> DC/DC Converter Controller Using a
PICmicro® Microcontroller

Can anyone take a glance and answer my question?


You could be interested by that blog ( in French, Google trad is your friend), included the code for a UNO:



Ok, thanks for answer. I used Google Translate. It seems to be good article, but if I got it right there is anything about controlling current using Arduino and PID.

Anyway I found site which someone did thing I would like do too. This is Programmable Switching Current Source Using Arduino as a PID Controller. He uses LM2596-ADJ. My question: is it possible to using at the same time this chip to dimming LED by PWM and changing voltage?

Any tips will be welcome.


I'm fairly sure that the LM2596 project is not going to work.

The LM2596 is designed for voltage regulation. Have a look at its datasheet.


What you probably want is something more like the FemtoBuck


It has a simple buck converter that is designed to control current for a load like an LED.



Hello elecled1

I made the lm2576 based PID controlled constant current source for my programmable NiMh battery charger. The lm2576 can support a max of 3 amps output current, the HV version of the chip can take a max voltage input of 60volts, if this is the kind of power you are looking for you are good to go with this design.

I remember reading that LEDs are current driven as long as the voltage is above Vf. In order to get a dimmer LED just pass a smaller currenr through it no need for PWM voltage control when working with a constant current source.

Hope this helps.


Plus just to add something very important, the lm2576 is an active low enabled device meaning you give a zero ground on its on/off pin to make it start switching, its also on if you leave the pin floating or unconnected, since the circuit was designed for battery charging it will need to be slightly modified for driving LEDs, because say if you use this circuit to light up LEDs the moment you turn off the circuit the on/off pin will start floating as its directly controlled by the arduino, In that instant assuming you're power supply for the lm2576 doesnt instantly go to zero there will be a huge current spike through your LEDs which would most likely damage them.


I'm fairly sure that the LM2596 project is not going to work.

The LM2596 is designed for voltage regulation. Have a look at its datasheet.
The project is probably working somehow. Voltage regulators may be easily used to make current regulator - you just let them regulate voltage over shunt resistor (try Google "LM317 current regulator" for hint). But in the linked project it is used very very very poorly IMHO.

To use this chip as current regulator the voltage over shunt resistor should be applied to Feedback pin. Probably via opamp with Arduino regulating the gain somehow. Or average between "constant voltage" from filtered PWM output and shunt resistor. Or...
On 8-bit (i.e. Uno) use "byte" instead of "int" if possible - it is faster and saves resources!


May 18, 2017, 02:40 pm Last Edit: May 18, 2017, 03:16 pm by waqaszahid
Hello Smajdalf,

Thanks for the honest feedback, this was just the first article in a series of posts that that I wrote on developing this current controller,


This is the final design I settled with which is based on the ATtiny85 and as pointed out the voltage from the shunt goes to the ATtiny85 after being amplified by an op-amp


As far as controlling the gain of the opamp from the arduino is concerned, that is the first direction I went in and searched for a digital potentiometer but such special chips are difficult to find in this part of the world with such low demand, so this PID appoach came up while I was trying to look for an alternative way to make this work. However with all honesty I too do believe the gain approach would have worked alot better and would be much less prone to failure. However when I started getting good results with this approach I gave up on rest of the ideas and started to better this design to minimize the steady state error, this might be a horrible design decision and complicated to work with but I am awfully glad I took this road, the knowledge I gained regarding PIDs was unlike anything I learned in University.


Big thanks for all your replies.
waqaszahid anyway your project is really interesting. It was surely hard but great job :)
Unfortunately, I understood that posts on your site aren't the best solutions for driving powerful LEDs. Am I ok?

ron_sutherland I built already circuit with PT4115 as LED driver. There current is limited using resistor. This solution is really simillar to lmentioned femtobuck.

Maybe I was imprecise, my main goal is to control current of high power LED using PID controller implemented on Arduino. Is it possible?


The PT4115 looks good, does the DIM pin not work? I would think controlling the DIM pin with a PWM output from the MCU would be the way to go.  When the LED output needs to change from one value to another that change could be controlled by calculations from the PID. Just setup the PT4115 to run the LED at a safe current and then use one of the ATmega328p's PWM outputs to do a PID calculated fade. Perhaps this would be a starting point:



The LM2576 you used is trying to source enough current to make voltage on the FB pin equal to internal reference (1.235V). You bypassed this mechanism and implemented it in software again - when the voltage on shunt resistor is too small you let less voltage on FB pin forcing the regulator source more current. In fact there is no need for the regulator in this setup - you could use simple transistor instead.

Using the regulator you could connect

Vcontrol --- R1 --- FB --- R2 --- Vsense

Where Vsense is voltage over your shunt resistor (possibly amplified by op-amp) and Vcontrol is a voltage generated by MCU - probably filtered (and buffered?) PWM. Feedback pin is connected to voltage divider made by R1 and R2. The larger is R1 compared to R2 the more precise is the output current control but the smaller is range. No need for hard to get digital pot. I think it is possible to control op-amp gain with filtered PWM somehow too but I never tried it.
On 8-bit (i.e. Uno) use "byte" instead of "int" if possible - it is faster and saves resources!



I must say thats quite an intreguing idea, so if I understand you correctly, the Vcontrol would be a voltage set in a way that only a particular Vsense voltage would be able to generate the 1.2 reference volts for the LM2576 feedback? Taking into account the values of R1 and R2 ofcourse, if I can make the output voltage from the arduino stable enough or use a DAC for accuracy and stability purposes I can completely eliminate the need for a separate PID chip which I am doing right now.

Yes I too do believe we can get away with controlling the gain through filtered but like you I have yet to try it.

Thanks for the great idea though!


Hi again!
I found application note from Microchip AN1138 - A Digital Constant Current Power LED Driver.
This note describes how to use PI controller to regulate current of LED.

I am going to build a circuit shown on the last page of this document, but my question is:
can I replace PIC microcontroller (PIC12HV615) with Arduino UNO?


Yes, you can do it. But you need to rewrite the program/modify it to work on Arduino. Should be easy if you understand how it works.
On 8-bit (i.e. Uno) use "byte" instead of "int" if possible - it is faster and saves resources!

Go Up