As an Amazon Associate we earn from qualifying purchases.
A buck converter is a DC-DC circuit that steps a higher voltage down to a lower one without wasting the difference as heat. An Arduino is a handy way to drive one, because it can generate the PWM signal and, if you add a voltage divider, measure the output and correct it. The video above shows a buck converter built around an Arduino. This article explains how the circuit works, what you need, and how to set it up.
What a buck converter does
A linear regulator drops extra voltage as heat, so it gets inefficient when the gap between input and output is large. A buck converter instead switches the input on and off very quickly and smooths the result with an inductor and a capacitor. Because the switch is either fully on or fully off, little power is lost in it.
In ideal conditions, with the inductor current never dropping to zero (continuous conduction mode), the output voltage is:
- Vout = D × Vin, where D is the duty cycle (the fraction of each switching period that the switch is on).
So a 12 V input at about 42% duty gives roughly 5 V at the output. Real circuits lose a little to diode drops and resistance, so the duty cycle needs a small correction, which is where feedback helps.
How the circuit works
The basic power stage has four parts: a switch, a diode, an inductor and an output capacitor.
- When the switch is on, current flows from the input through the inductor to the load, and the inductor stores energy.
- When the switch turns off, the inductor keeps current flowing through the diode to the load.
- The capacitor smooths the pulses into a steady DC voltage.
Changing the duty cycle changes the average output voltage. That is the only control the Arduino needs to provide.
Parts you need
- Arduino board (an Uno or Nano works for small circuits).
- Power MOSFET rated well above your input voltage and load current.
- MOSFET gate driver if you use an N-channel MOSFET as a high-side switch. The Arduino’s 5 V output pin usually cannot drive it properly on its own. A P-channel MOSFET with a simple level-shifting stage is an alternative.
- Fast diode, preferably a Schottky type, rated for the load current and the input voltage.
- Inductor rated above the peak current so it does not saturate.
- Output capacitor, ideally low-ESR, plus an input capacitor close to the switch.
- Two resistors as a voltage divider for feedback to an analog input.
- A load resistor or a small test load, and a breadboard or perfboard that can handle the current.
Choosing the switching frequency
This is the step beginners most often miss. The default PWM from analogWrite() on an Arduino Uno is around 490 Hz on most pins and around 980 Hz on pins 5 and 6. That is very low for a buck converter, and it would need a large inductor and capacitor.
On an Uno, you can change the Timer1 prescaler (pins 9 and 10) so the PWM runs at about 31 kHz. This is done by setting the prescaler bits in the TCCR1B register to 1. A higher frequency lets you use a smaller inductor and capacitor, but switching losses in the MOSFET rise with frequency, so very high settings are not always better. Other boards have different timers, so check the datasheet for yours.
Sizing the inductor and capacitor
Two common starting formulas for continuous conduction are:
- L = (Vin − Vout) × D / (f × ΔIL)
- C = ΔIL / (8 × f × ΔVout)
Here f is the switching frequency, ΔIL is the ripple current you accept (often 20–40% of the load current) and ΔVout is the ripple voltage you accept.
For example, take a 12 V input, a 5 V output, a duty cycle of about 0.42, a switching frequency of about 31 kHz and a ripple current of 0.3 A. The inductor works out to roughly 300 µH. For 50 mV of ripple, the capacitor comes out at about 24 µF. In practice you would pick a larger standard value, such as 100 µF or more, to allow for capacitor ESR and tolerance.
Open-loop and closed-loop control
Open loop
In the simplest version, you set a fixed PWM value and read the output with a meter. This is fine to see how duty cycle affects voltage, but the output will shift when the load or input changes.
Closed loop
For a stable output, scale the output voltage down with a resistor divider so it stays under the Arduino’s 5 V analog limit, then read it on an analog pin. The program compares the reading with a target and adjusts the duty cycle:
- Read the divided output voltage with analogRead() and convert it back to the real output voltage.
- Calculate the error: target voltage minus measured voltage.
- If the output is low, increase the duty cycle a small step. If it is high, decrease it.
- Limit the duty cycle to a safe range so it never reaches 0% or 100%.
- Repeat continuously.
A simple step or proportional correction is enough for many hobby builds. A full PI controller gives a smoother response once you are comfortable with the basics.
Testing safely
- Start with a low input voltage and a light load, and increase gradually.
- Keep the Arduino ground and power-stage ground connected, and make sure the feedback divider can never put more than 5 V on an analog pin.
- Keep the high-current loop (switch, diode, inductor, input capacitor) short, with thick traces or wires, to reduce noise and spikes.
- Check that the MOSFET and diode do not get hot, and watch the inductor for signs of saturation.
Be especially careful with mains-derived or high DC voltages. If you want to see a design that goes beyond low-voltage hobby levels, look at this adjustable buck converter project, or the high voltage buck converter example. These need proper isolation, ratings and safety practice.
Where to go next
Once the basic buck stage works, you can explore related converters. A boost converter using Arduino does the opposite job and steps voltage up. If you want to apply a converter to a real task, MPPT for solar battery charging is a common next project, since it uses the same PWM and sensing ideas.
FAQ
Can an Arduino drive a buck converter directly?
It can generate the PWM signal, but it usually cannot drive a power MOSFET gate directly, especially a high-side N-channel one. Use a suitable gate driver or a logic-level MOSFET arranged for low-side or P-channel switching.
What PWM frequency should I use?
The default Arduino PWM of a few hundred hertz is too low for a compact design. Changing the timer prescaler to reach around 31 kHz on an Uno is a common starting point. Pick a value that balances inductor size against switching losses.
Why does my output voltage not match D × Vin?
The formula is for an ideal circuit. Diode drops, switch resistance, inductor resistance and operation in discontinuous conduction all shift the result. Feedback from an analog input lets the Arduino correct for these.
Is a buck converter better than a linear regulator?
When the input voltage is much higher than the output, usually yes, because it wastes much less power as heat. A linear regulator is simpler and produces less switching noise, so it can suit low-current or noise-sensitive circuits.