Introduction: Arduino-based Switching Voltage Regulators
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.
Efficiency
- 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.
Efficiency
- 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.
Efficiency
- 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.
Efficiency
- 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....

Participated in the
Teach It! Contest Sponsored by Dremel

Participated in the
Epilog Challenge VI

Participated in the
Tech Contest
83 Comments
Question 2 months ago on Step 5
thank you for this post, don't know if you still taking questions on this old post but would like to know if this would work in real-time using a solar panel's output. would this maintain the desired voltage, say 12V on a cloudy day where you get @20V in sunlight and maybe @5V if blocked by the clouds and any values in-between 5V to 20V
Answer 7 weeks ago
Maybe. Would the solar panel have enough capacity on cloudy days?
Question 3 years ago
Hi, I'm just trying to analyse this circuit and I am wondering what the NPN/PNP configuration is doing? Why is there 2 transistors there and not just use one NPN or PNP? Just asking out of interest
4 years ago
what are the difference coding between one stage and two stage ?
Reply 4 years ago
First, sorry about my english :)
One stage controlls only one MOSFET (buck or boost), and two stage is needed for non-inverting buck/boost converter (two MOSFETs).
In two stage converter, in buck mode, PWM is driven on PIN D6 (BUCK_0_PWM_PIN), and MOSFET Q7 is closed whole the time (PIN D5 LOW). Boost mode is the opposite situation. PWM is driven on D5, and D5 must be set HIGH whole time, i.e. MOSFET Q4 must be open. Buck or boost mode is selected automatically by the ratio of output and reference voltage
In one stage code u have to controll only one MOSFET, so the code is simpler
It would be nice to make a boost-buck converter, which work at the same time, like thisone
https://www.youtube.com/watch?v=-fii6G_ewdw
First, with boost mode, raise the input voltage to about 3-4 V above the desired output voltage, and then with the buck converter, lower the voltage to the desired voltage. Such a converter is very efficient. But I don't know if an arduino can run two different PWMs at the same time. (I'm still new to arduino)
Reply 4 years ago
I had a typo: "PWM is driven on D5, and D5 must be set HIGH whole time"
Correct is "PWM is driven on D5, and D6 must be set HIGH whole time"
Question 5 years ago
Hello. I`m trying to make a LiPo battery charger and thought this circuit could help me, but the out voltage falls and aren`t stabil when I connect different loads to it. Does anybody know what the problem can be?
Answer 5 years ago
The non-inverting buck-boost converter is the circuit.
6 years ago
Hi,I think it's a very good project,
Can I charge the lead acid battery 12 V from solar panel 50 Wp (max output 20V) with this project (buck boost non inverting)?
What components should I replace from your project?
Reply 6 years ago
I'm guessing that you're designing a smart charger rather than a trickle charger. You'll need to design it to be both constant current and constant voltage. One analog pin measures the current flowing through the battery and another measures the voltage across the battery. Note that there's voltage drop through the current sense resistor. You can try measuring the current with an op-amp.
Reply 6 years ago
Yeah,already test to charge the lead acid battery 12V and it makes the mosfet so hot,
I will make a circuit to limit the current in this circuit,
Reply 6 years ago
The MOSFET shouldn't get so hot. It's possible that the duty cycle of the boost converter was too high, and the saturation current of the inductor was too low for the application, causing a short. A current limiter is a good idea because it can protect the boost converter if it shorts.
6 years ago
Great Work! ( incredible, in fact...). Well done. Learned a lot. Thanks.
6 years ago
Already made this and it works great,thank you very much!
Can you provide arduino code (two stage converter) for just one input and one output? (not three input and output like yours)
I'm already edited your code but it comes to stop working the circuit.
What part of your code which can I erase to make code for just only one input and one output?
Reply 6 years ago
When you edit the code, did you leave the input that corresponds to the output that you're using?
Which pins are you using as analog inputs and PWM outputs? You'll have to make sure that the TCCRnx registers are edited correctly. More information about them is in the ATmega328 datasheet.
6 years ago
Hi ,
I am trying to build something similar but with pic-micro instead of arduino.
aim is to have 6A current at the output (and voltage Vin -(will also be high (from 12V to 48 V)
has any one come across few buck-controller IC
6 years ago
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??
6 years ago
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.
this please.
Reply 6 years ago
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.
Reply 6 years ago
wow that was a quick reply, thanks! I mean i usually declare analog pins using A0 ,A1... how did you declared yours?