DC to DC converters are used to efficiently convert DC voltages. They have a conversion efficiency of up to 95% making them useful for LED strips, bike lights, battery chargers and solar powered devices. A voltage converter requires a PWM source such as a microcontroller. Although you could use specialty ICs I used the Arduino because it is commonly used on Instructables and six converter outputs are possible. You can write your own code to the Arduino as well. In this Instructable I will show you how to use the Arduino-based boost (step-up), buck (step-down) and buck-boost (step-up or step-down) converters.

Step 1: Material Required

PWM source

  • 1 - Arduino

Boost Converter (per output)

  • 2 - 150 ohm resistors
  • 2 - 1k resistos
  • 1 - 10k resistor
  • 1 - 10k potentiometer
  • 1 - 10M resistor
  • 1 - 2.2nF capacitor
  • 1 - 10uF capacitor
  • 1 - 2A 100uH inductor
  • 1 - 2A schottky diode
  • 1 - 4.7V zener diode
  • 1 - N-channel power MOSFET (eg. IRFZ44N)

Buck Converter (per circuit)

  • 1 - 10 ohm resistor
  • 2 - 150 ohm resistors
  • 1 - 1k resistor
  • 1 - 4.7k resistor
  • 1 - 10k potentiometes
  • 2 - 10M resistors
  • 2 - 10uF capacitors
  • 1 - 2A 100uH inductor
  • 1 - 2A schottky diode
  • 1 - 4.7V zener diode
  • 1 - P-channel power MOSFET (eg. IRF9540N)
  • 1 - N-channel small signal MOSFET (eg. 2N7000)
  • 1 - NPN transistor (eg. 2N3904)
  • 1 - PNP transistor(eg. 2N3906)

Non-Inverting Buck-Boost converter (per circuit)

  • 1 - 10 ohm resistor
  • 3 - 150 ohm resistors
  • 2 - 1k resistors
  • 1 - 4.7k resistor
  • 3 - 10M resistors
  • 1 - 10k potentiometer
  • 1 - 2.2nF capacitor
  • 2 - 10uF capacitors
  • 2 - 2A schottky diodes
  • 1 - 4.7V zener diodes
  • 1 - NPN transistor
  • 1 - PNP transistor
  • 1 - N-channel small signal MOSFET
  • 1 - P-channel power MOSFET
  • 1 - N-channel power MOSFET
  • 1 - 2A 100uH inductor

Inverting Buck-Boost converter (per circuit)

  • 1 - 10 ohm resistor
  • 1 - 1k resistor
  • 1 - 4.7k resistor
  • 2 - 100k resistors
  • 2 - 10M resistors
  • 2 - 150 ohm resistors
  • 1 - 10k potentiometer
  • 2 - 10uF capacitors
  • 1 - 2A 100uH inductor
  • 1 - 2A schottky diode
  • 1 - 4.7V zener diode
  • 1 - NPN transistor
  • 1 - PNP transistor
  • 1 - N-channel small signal MOSFET
  • 1 - P-channel power MOSFET
  • 1 - low voltage op-amp (eg. LM358N)

When designing the circuits, please wear goggles! Capacitors can explode when overcharged or installed incorrectly.

Step 2: Boost Converter Circuit

In boost converters the output voltage is higher than the input voltage. The Arduino maintains the output voltage by monitoring it and adjusting the duty cycle based on it. The frequency is 62.5 kHz. If the output voltage falls below or rises above its desired value the duty cycle increases or decreases.The higher the MOSFET's on time the more the voltage is stepped up. The feedback voltage is maintained around 500mV. The outputs can be adjusted with the potentiometers.

The converter circuits have protection features. When first powered it starts at 0% to minimize the inrush current. The zener diodes at the analog inputs are used for overvoltage protection. They ensure that the feedback voltage does not exceed their breakdown voltage of 4.7V. The RC snubber reduces the ringing at the drains of the MOSFETs. In this circuit R13 prevents you from setting the voltage too high. The maximum voltage to use depends on the breakdown voltage of the schottky diode, the Vdss value of the MOSFET and the voltage tolerated by your load. The formula R13=Vref/((Vmax-Vref)/(R11+R12)) calculates the value of R1 that should be used. The same formula can also be used for the other converters with resistors' numbers substituted.


  • Load: 1.70W, Input: 11.9V@150mA, Output: 17.0V@100mA, Efficiency: 95.1%
  • Load: 15.3W, Input: 10.3V@1.66A, Output: 21.9V@700mA, Efficiency: 89.5%

Step 3: Buck Converter Circuit

In buck converters the output voltage is lower than the input voltage. Unlike the boost converter this one as well as the inverting buck-boost converter uses a P-channel MOSFET for its switch. This means a NOT gate is needed to drive it at 12V and 0V which cannot be done by the Arduino. The transistor will be permanently on if driven by the Arduino's pins. The NOT gate also allows the same sketch to be used. The lower the MOSFET's on time the more the voltage is stepped down.


  • Load: 5.09W, Input: 460mA@11.5V, Output: 11.3V@450mA, Efficiency: 96.1%
  • Load: 2.00W, Input: 11.8V@200mA, Output: 4.42V@453mA, Efficiency: 84.7%

Step 4: Non-inverting Buck-Boost Converter

In non-inverting buck-boost converters the output voltage is positive and may be higher or lower than the input's voltage. The buck and boost converters were cascaded to step-down or step-up as necessary. At any given time only one of the converters is active. When the Arduino powers up it soft starts in buck mode. If the output voltage is below its desired value and its duty cycle is 100% it switches over to boost mode with the gate of Q2 low. If the output is above its desired value and its duty cycle is 0% it switches back to buck mode with gate of Q3 low. You can set it to buck instead of buck-boost mode if you prevent the buck stage's duty cycle from reaching 100%. Since this circuit uses two switches a different sketch is needed.


  • Load: 3.15W, Input: 340mA@11.6V, Output: 630mA@5.00V, Efficiency: 79.9%
  • Load: 3.94W, Input: 370mA@11.6V, Output: 368mA@10.7V Efficiency: 91.7%
  • Load: 2.53W, Input: 260mA@11.7V, Output: 143mA@17.7V Efficiency: 83.2%
  • Load: 9.23W, Input: 1.06A@10.9V, Output: 446mA@20.7V, Efficiency: 79.9%

Step 5: Inverting Buck-Boost Converter

In inverting buck-boost converters the output is negative and may be higher or lower in magnitude than the input voltage. Since the 500mV feedback is negative and the Arduino's ADC pins cannot read negative voltages the op-amp inverts it to a positive value. The higher the MOSFET's on time the higher the output voltage. Based on my measurements this circuit is relatively inefficient. The transistor was hot at heavier loads which may be caused by its resistance. This circuit uses the one switch sketch.


  • Load: 5.28W, Input: 11.3V@670mA, Output: 18.9V@280mA, Efficiency: 69.7%
  • Load: 7.49W, Input: 10.8V@1.1A, Output: 19.7V@380mA, Efficiency: 62.7%

Step 6: Boost and Buck Converter Sketch

The two sketches were written for the Arduino Uno. To adapt it for other chips such as the ATtiny you can refer to their datasheets. The sketch "one_stage_converter" is for the buck, boost, and inverting buck-boost converter. The sketch "two_stage_converter" if for the non-inverting buck-boost converter. Any of the PWM pins 6, 5, 9, 10, 11, and 3 can be used for the one-stage converters, allowing six outputs. For the two-stage converter each output must use the same timer with the OCxA pins for the buck stage and the OCxB pins for the boost stage, allowing three outputs. Since the prescaler for timer 0 is changed the millis() and delay() functions will be 64 times faster and their values will need to be 64 times larger. I have enabled only one output. You may re-enable the other outputs by uncommenting them in the setup() function.

In the sketches you can adjust timer 1's PWM frequency, the feedback voltage, and the maximum duty cycles for each output with the following:

  • TIMER_TOP_1 - sets timer 1's output frequency. f=16MHz/TIMER_TOP_1
  • desiredFeedbackVoltage - sets the feedback voltage between 0 and 1100mV
  • MAX_DUTY_nx - sets the maximum duty cycles (One-stage converter only)
  • MAX_BUCK_DUTY_n - sets the maximum duty cycle for the buck stages (Two-stage converter only)
  • MAX_BOOST_DUTY_n - sets the maximum duty cycle for the boost stages (Two-stage converter only)

A higher frequency allows smaller inductances to be used. This allows higher current ratings because when inductors are in parallel they have a higher current rating and a lower combined inductance. Only timer 1's frequency can be changed with two outputs available. To change it for the other timers refer to the datasheet. You can use the following calculator for selecting the inductors and other parts: https://learn.adafruit.com/diy-boost-calc/the-cal....

<p>Hi, I am trying to implement buck converter. I am really impressed with your work. I want to know the buck converter code only. Can you explain only buck converter code??</p>
<p>Hi, i am trying to understand the two_stage_converter code but fail to understand how you declared your analog input, could you explain this please.</p><p> this please.</p>
<p>There's three analog inputs instead of six because for two stage converters, two PWM outputs are used for each regulator instead of one. Because there's only six PWM pins on the Arduino, there can be up to three two stage converters.</p>
<p>wow that was a quick reply, thanks! I mean i usually declare analog pins using A0 ,A1... how did you declared yours?</p>
<p>In the code, they still mean A0, A1, and A2 for the lines</p><p>#define FEEDBACK_PIN_0 0</p><p>#define FEEDBACK_PIN_1 1</p><p>#define FEEDBACK_PIN_2 2</p><p>You can change them to const int FEEDBACK_PIN_0 = A0,...</p>
<p>okay! Thanks!</p>
<p>Great little project here, but how does the code know when to apply the boost or buck converter?</p>
The code for the two stage converter would start at buck mode. If it's at 100% duty cycle and the output is still too low, it goes boost mode. If at boost mode the duty cycle is 0% and the output is too high, it goes into buck mode.
<p>where is the code for boost converter only ?</p>
<p>This code works for the boost converter: one_stage_converter.</p>
Can I have the arduino code for buck converter?
<p>hello, can I have the code and circuit for buck boost converter. Kindly mail me to narmimuthu123@gmail.com if possible. </p>
<p>Genius!!! There is no more to say...</p>
The code is at the bottom of the article, just before the comments.<br><br>&quot;one_stage_converter.ino&quot;<br><br>&quot;two_stage_converter.ino&quot;
<p>where is the code for boost converter only ?</p>
<p>The best thing about using an Arduino is that you can control the voltage via I2C, SPI, etc. using other controller.</p>
<p>Hello,</p><p>I have taken great inspiration from your work.</p><p>Could you please have a look at my schematic and tell me what you think.</p><p>Thank you.</p>
Hello,<br>Thanks for the encouragement.<br><br>It looks like you're trying to make a high current buck-boost converter.<br><br>I think you've reversed the drain and source pins of the P-channel MOSFETs for the buck stages. For the boost stages, you may want to drive their MOSFETs with the same driver used for the buck stage or drive them with a gate resistor in series with one of the microcontroller's PWM pins. Make sure that the mcu's total current isn't exceeded.
<p>I want to make buck converter 12V, 5A . but I want to use pwm libraray for it and I can't understand how to write the code for it please tell me how to write it ? I use two IRFZ44N Mosfets for synchronous and One for non synchronous and also use IR2104 mosfet driver for switching the mosfets Please guide me what should I do?</p>
<p>Hey!</p><p>I built this circuit and powered it from a 3s lipo.</p><p>I added an LCD and buttons to adjust the output voltage.Also, the inductor and the capacitor are very large as i was looking to 100+ amps.</p><p>Whenever i have some load on the output and press the fire button, the arduino restarts itself. Yet, if you keep pressing the fire button and spam press other buttons, it ends up giving full voltage on the output and upon disconnecting the battery, the arduino is fried.</p><p>Why does the arduino fry in this situation? (i fried 2 up to this moment, only the mcu, the ftdi chip is still recognised)</p><p>How can i make it work?</p>
<p>I am talking about the buck converter**</p>
<p>I'm sorry to hear that you've fried two Arduinos. Did you wire it correctly? I've damaged the Arduino before when I've printed a circuit board for boost converters. I think I've made a mistake of daisy chaining power and ground lines. Do you have a schematic?</p>
<p>The schematic is the one posted by you. I think i should include a softstart of some kind. Something like: calculate predicted pwm, for counter in 1 to predicted pwm do OCR0A = predicted and then loop around OCR0A = output0a while the button is still pressed. Or maybe i could use an opto coupler between the arduino and the buck converter, but i don't know what to say... The ardus could have fried due to back emf or something...</p>
<p>Hi,</p><p>i am trying to build the project of the buck converter.</p><p>Can someone email me the code for the Arduino?</p><p>Thank you in advance.</p>
<p>Check this:</p><p><a href="http://www.emergingtechs.org/p/r-d-lab-design-industrial-training-and.html">http://www.emergingtechs.org/p/r-d-lab-design-indu...</a></p>
<p>Did you get the code?</p>
No,do you have it?
<p>what is the purpose of the zener diode? can someone help me?</p>
<p>The zener diodes at the analog inputs are used for<br>overvoltage protection. They ensure that the feedback voltage does not exceed their breakdown voltage of 4.7V</p>
<p>I want to design a buck boost dc-dc converter with Vin= 25 to 65V, Vout=30V and generate Pout=300W. Can you help to get C and L as well as the type of Mosfet and diode can be used. Thx.</p>
<p>300w is A LOT especially at 30v. Things will be getting pretty hot especially if you're pulling 10 Amps which is what you're suggesting. I would have a look around google to see how to figure out the needed capacitance and inductance and by doing this you'll actually learn something more about electronics. Despite this, i would look at look at something of around 90W meaning you can draw 3 amps @ 30v which is enough for most situations</p>
<p>Boost converter may overheat or even stop switching when used on TIMER1 (that is: PWM on pin 5 and 6). After making the circuit on breadboard and playing around, this happened to me after approx 15-20mins; I looked for the reason and the below is what I uncovered after approx 3 weeks of banging my head against the problem.</p><p>The one_stage_converted.ino uses the CPU freq as the clock-source (no prescaler - see the &quot;TCCR1B = _BV(WGM12)|_BV(WGM13)|_BV(CS10);&quot;). Which means the shortest duty cycle (OCR1A=1) will require a duration of 1/16MHz=62.5ns to complete.</p><p>Now, IRFZ44N specs says:</p><p>* Turn-On Delay Time - 12 ns (time to &quot;get the turn-on message&quot;)</p><p>* Raise time - 60 ns (time to &quot;execute the turn-on&quot;)</p><p>* Turn-off delay time - 44 ns (time to &quot;get the turn-off message&quot;)</p><p>* Fall time - 45 ns (time to &quot;execute the turn-off&quot;)</p><p>Which means a fully-on transition is about 72ns and fully-off transition is about 89ns; the *minimal* fully-on/fully-off cycle would be 161ns (even neglecting the &quot;get the message&quot; delays, the execution would still take 105ns).</p><p>As a result, for duty cycles shorter than 3 (&quot;only a bit of boosting, please; larger duty cycles overshoot the voltage I need&quot; **), the MOSFET will work in the ohmic mode, get into heat (... and try to hump your leg). Among other things, the Vgs(th) increases with temperature, so my 5V input will manage less and less to saturate the NMOS, which means more ohmic mode and more heat.</p><p>Another two problems arising from directly using the Arduino output pins to drive the IRFZ44N. As a preliminary, IRFZ44N spec says:</p><p>* Input Capacitance (1MHz, Vgs=0) - 1470pF</p><p>* Vgs(th) - between 2V and 4V</p><p>Now, model the switch-on/off of the NMOS as charging/discharging the gate &quot;capacitor&quot; through a 150R; this from a source/sink of 5V (arduino pin 5/6). My computation (corrections appreciated, if needed) shows:</p><p>1. poster boy IRFZ44N - time to charge from 0 to 2 V (switch on) - 107ns. Time to discharge from 5V to 2V (switch off) - 109ns</p><p>2. Lev Andropov's &quot;all made in Taiwan&quot; IRFZ44N - time to charge from 0 to 4V - 338ns. Time to discharge from 5V to 4V - 46ns.</p><p>If you are unlucky (like me) and got a lousy IRFZ44N, sourcing/sinking the current through a 150R will limit your shortest on-off duration to 380nS (use a base frequency of 2.6Mhz to build your PWM by counting pulses). This letting aside that Vgs(th) guarantees conduction, but not saturation.</p><p>Perhaps using a CS11 (instead of CS10) on timer1 settings would do the trick, but for sure having a gate driver circuit is better (takes only 3 transistors, you've done it on the buck side).</p><p>And finally, the last problem: the max current you draw from the PWM pin - this is Vs/R=5V/150R=33.33mA. Well, I know that this is &quot;peak current&quot;, but still... at least Arduino Mini has a spec of max 40mA/recommended 20mA on output pins. So, don't try direct-PWM-ing something else while boosting on the same Arduino board, you may fail both.</p><p>---</p><p>** Got into these snags while trying to solve the recharging of a bank of 4x2500mAh LiPo batteries is series from a 12V solar panel using the above. The recharging cycle passes through a phase of &quot;only a bit of boost please&quot;.</p>
<p>If you want faster switching times, you can use the AO3400. </p><p>http://www.aosmd.com/pdfs/datasheet/ao3400.pdf</p>
<p>Thanks for the ref.</p>
<p>Thanks for sharing details. </p>
<p>I want to make buck converter which convert 100V to 48V...can i still use the same arduino based principle for different rating of MOSFET,diode,capacitor,etc?</p>
Pls I need your help with the code. I implemented the boost exactly the way it was in the diagram, and used the &quot;one-stage&quot; code u gave without making any changes, but the system still isn't working. I connected the output pin6 of the arduino to the mosfet of the boost converter. I gave the whole system a common gnd as in d diagram.The only difference is that I used a power diode instead of schottky diode. So pls I need a little explanation of the code, so I can interface my arduino to the converter and complete my school project.
<p>I'm sorry that my diagram has mistakes. For D6, A0 is used.</p>
<p>hye hanlin..kindly pls respond.. D6 change to A0? means D6 is not used?</p>
<p>thanks alot, the boost is now working, but it kept blowing up my inductor. i dont know the current rating of the inductor, but it is 100uH. And pls could u teach me or direct me to a place where i could learn the pulse width code, i would love to be able to manipulate the code to suit my project. the code looks really complex. (by the way my school project is a maximum power point tracker which uses a buck boost converter to regulate the voltage from a solar panel)</p>
<p>You are welcome. You could try a higher current inductor. I designed the code for six outputs but you may comment out the areas for the unneeded outputs. For buck-boost, you may want to use the two-stage converter code.</p>
Ok got it. But pls I still need explanation on the 6 timers, like how to change their frequency and duty cycles, and how they are related to the inductor and capacitor values. (I hope am not asking too much, but I'd like for us to exchange contacts so that we can have this conversation on whatsapp where I can share u pictures and videos of what I'm doing. Because I still have lots of questions concerning my school project. Plsssssssss!!!! My contact is +2348064954840 - Nigeria)
<p>To change the frequency for outputs 9 and 10, you change the value for TIMER_TOP_1. It's only possible to change it for 9 and 10. To change the duty cycles for outputs 6, 5, 9, 10, 11, and 3, change the values for MAX_DUTY_0A, MAX_DUTY_0B, MAX_DUTY_1A, MAX_DUTY_1B, MAX_DUTY_2A, and MAX_DUTY_2B.</p><p>At higher frequencies, you will be allowed to use smaller inductors and capacitors. You can use the calculators from the following site for designing your converter. </p><p><a href="http://www.coilcraft.com/apps/selector/selector_1.cfm" rel="nofollow">http://www.coilcraft.com/apps/selector/selector_1....</a></p>
I used the 0.6 duty cycle in the boost converter and it boosted 7.96v to 8.85v. I changed the duty cycle to 0.8, and it still produced the same thing. I really don't know what am doing wrong. And I also don't know how am supposed to adjust the variable resistor to suit the 500mv feedback to my arduino uno. The only conversion you showed for the desired feedback in the code is stating the change from analog to digital value, but u didn't show the one from analog to the actual value using voltage divider. Or am I to add the code myself?
<p>The variable resistor sets the output voltage. If it's working properly, the feedback voltage should always be 500mV.</p>
<p>If the diode gets hot, try using a schottky diode.</p>
<p>please l need more comments on the program i donnot understand the interaction between the different converters</p>
Good job gentlemen. Please which resistor controls the output voltage and can you throw more light on PWM for the non-inverting converter.
<p>The potentiometer controls the output voltage.</p>
<p>Hi there<br>Nice tutorial ;)<br>Could you please explain the need, on the buck converter circuit, for the N-Channel FET to drive the base of the totem pole?<br>Can't it be done directly from the arduino output?<br>Thanks</p>

About This Instructable




Bio: Autistic person who's interests include in utility cycling, recreational cycling, cycling safety, electronics, gardening, Arduino, and LEDs.
More by hanlin_y:Microcontroller Based DC-DC Converters ATTiny84 Based 3A Step-Down LED Driver 12V SLA Powered 15W LED Lamp 
Add instructable to: