As an Amazon Associate we earn from qualifying purchases.
This project shows how to build a high voltage buck converter using an Arduino. The Arduino generates a fast PWM signal that drives a power switch, and the converter steps a DC input of about 275V down to about 165V DC. The video below shows the project, followed by the circuit, the code and an explanation of how it works.
What a buck converter does
A buck converter is a DC-DC step-down converter. It switches the input voltage on and off very quickly, then smooths the result with an inductor and a capacitor. The average output voltage depends on how long the switch stays on in each cycle, which is the duty cycle.
For an ideal converter running in continuous conduction, the relationship is simple:
- Vout = D × Vin, where D is the duty cycle from 0 to 1.
- To get 165V from 275V, the duty cycle needs to be about 0.6 (60%).
- Real circuits lose a little voltage in the switch, diode and inductor, so the duty cycle usually needs a small adjustment.
If you are new to the topic, start with the basic Arduino buck converter at low voltage. It is much safer for learning, and the same ideas apply here.
Circuit
The diagram below shows the power stage and the connection to the Arduino. Check the diagram for the exact parts and values used in this build.
Main parts of the power stage
- Arduino (Uno or similar): creates the PWM signal on pin 11.
- Power switch: a MOSFET or IGBT rated well above the input voltage and the load current.
- Gate driver: the Arduino’s 5V output is usually not enough to drive a high voltage switch properly, so a driver stage sits between them.
- Freewheeling diode: a fast-recovery or similar diode that carries the inductor current while the switch is off.
- Inductor and output capacitor: store energy and smooth the output into steady DC.
- Input capacitor: supports the supply during each switching pulse.
Every part in the high voltage path needs a voltage rating with a safe margin above 275V, and the capacitors need the same margin. For a related design aimed at higher power, see this adjustable buck converter using an IGBT.
Program
The sketch does two things. It raises the PWM frequency on pin 11, then outputs a fixed duty cycle with analogWrite(11,100). The setPwmFrequency() function changes the Timer2 prescaler. With a divisor of 1, pin 11 runs at the base frequency of about 31 kHz, which is far above the default Arduino PWM frequency. A higher switching frequency lets you use a smaller inductor and capacitor.
void setup()
{
setPwmFrequency(11, 1);
analogWrite(11,100);
}
void loop()
{
/*
int a=analogRead(3)/4;delay(1);
if(a>220) a=220;
analogWrite(11,a);
*/
}
void setPwmFrequency(int pin, int divisor) {
byte mode;
if (pin == 5 || pin == 6 || pin == 9 || pin == 10) {
switch (divisor) {
case 1: mode = 0x01; break;
case 8: mode = 0x02; break;
case 64: mode = 0x03; break;
case 256: mode = 0x04; break;
case 1024: mode = 0x05; break;
default: return;
}
if (pin == 5 || pin == 6) {
TCCR0B = TCCR0B & 0b11111000 | mode;
} else {
TCCR1B = TCCR1B & 0b11111000 | mode;
}
} else if (pin == 3 || pin == 11) {
switch (divisor) {
case 1: mode = 0x01; break;
case 8: mode = 0x02; break;
case 32: mode = 0x03; break;
case 64: mode = 0x04; break;
case 128: mode = 0x05; break;
case 256: mode = 0x06; break;
case 1024: mode = 0x7; break;
default: return;
}
TCCR2B = TCCR2B & 0b11111000 | mode;
}
}
/**
Divides a given PWM pin frequency by a divisor.
The resulting frequency is equal to the base frequency divided by
the given divisor:
- Base frequencies:
o The base frequency for pins 3, 9, 10, and 11 is 31250 Hz.
o The base frequency for pins 5 and 6 is 62500 Hz.
- Divisors:
o The divisors available on pins 5, 6, 9 and 10 are: 1, 8, 64,
256, and 1024.
o The divisors available on pins 3 and 11 are: 1, 8, 32, 64,
128, 256, and 1024.
PWM frequencies are tied together in pairs of pins. If one in a
pair is changed, the other is also changed to match:
- Pins 5 and 6 are paired on timer0
- Pins 9 and 10 are paired on timer1
- Pins 3 and 11 are paired on timer2
Note that this function will have side effects on anything else
that uses timers:
- Changes on pins 3, 5, 6, or 11 may cause the delay() and
millis() functions to stop working. Other timing-related
functions may also be affected.
- Changes on pins 9 or 10 will cause the Servo library to function
incorrectly.
Thanks to macegr of the Arduino forums for his documentation of the
PWM frequency divisors. His post can be viewed at:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235060559/0#4
*/
Setting the duty cycle
analogWrite() takes a value from 0 to 255. A value of 100 is a duty cycle of about 39%, so with an ideal converter and a 275V input the output would be roughly 108V. To reach 165V you need a duty cycle near 60%, which is a value of about 153. Treat that as a starting point, then adjust the number while you measure the real output.
The commented-out block in loop() shows how to make it adjustable. It reads an analog input on A3, scales it to 0-255 and limits it to 220 before writing it to the PWM pin. Use it with a potentiometer or a scaled feedback signal. Any feedback from the high voltage side must go through a proper resistor divider, and ideally isolation, so the analog pin never sees more than 5V.
Timer note
The function’s comment warns that changing some pins can break delay() and millis(). On the ATmega328P boards, those functions depend on Timer0, which drives pins 5 and 6. Pin 11 uses Timer2, so this sketch leaves them alone. If you move the PWM output to pin 9 or 10, the Servo library will no longer work properly.
How to test it safely
A 275V DC supply can cause serious injury, and large capacitors stay charged after you switch off. Work carefully and follow these points:
- Test the code and gate drive first with no high voltage connected. Check the PWM signal with an oscilloscope.
- Start with a low input voltage and a small resistive load, and raise the voltage in steps.
- Keep the Arduino and your computer isolated from the high voltage side. Do not connect a USB cable to a PC while the power stage is not isolated.
- Use a fuse on the input, and mount the circuit on an insulated base with no exposed live parts.
- Discharge the capacitors with a suitable resistor and confirm with a meter before touching anything.
- Never leave the converter running unattended, and check that the switch and diode are not overheating.
Improving the design
- Add closed-loop feedback so the output stays near 165V when the input or load changes.
- Add overcurrent protection, such as a current sense resistor with a comparator that turns off the PWM.
- Use a heatsink on the switch and diode if the load current is significant.
- Compare it with a larger high voltage buck converter design on this site.
The same switching idea is used in a buck-boost MPPT charger for solar panels, where the Arduino adjusts the duty cycle based on measured voltage and current.
FAQ
Can an Arduino directly drive the switch in a high voltage buck converter?
Usually not. The Arduino pin outputs 5V at a small current, which is not enough to switch a high voltage MOSFET or IGBT quickly and fully. A gate driver is normally placed between the pin and the gate.
What duty cycle do I need to convert 275V to 165V?
In an ideal buck converter the duty cycle equals Vout divided by Vin, so 165 / 275 is 0.6, or 60%. On an Arduino that is an analogWrite() value of about 153. Real losses mean you will need to fine-tune it.
Why change the PWM frequency on the Arduino?
The default PWM frequency on most Arduino pins is only around 490 Hz or 980 Hz. That would need a large inductor and capacitor. Raising it to about 31 kHz allows smaller, cheaper parts and a smoother output.
Is this circuit isolated from the input?
No. A buck converter is a non-isolated design, so the output shares a connection with the input. Treat the whole circuit as live high voltage, including the Arduino side, unless you add isolation.