Introduction: Variable 0-12V, Digitally Controlled, Power Supply Using a Laptop Wall Wart & Ardunio

The goal of this Instructable is to make a functional, Ardunio digitally controlled, power supply. We tested the supply and controller so that you can grab your old laptop wall wart (output voltage between 14 and 20V), connect it to the supply's Vin line and digitally specify what output voltage you want in the range between 0 and 12 V. Assuming you already have an Ardunio and a laptop charger with the right specs, a single source should cost around $15 in parts. This Instructable will walk through building a single supply (with the option of building two) that is controlled by a single Ardunio Uno.

To build a single switching buck supply, as show in the circuit below, you will need the following parts (about $15):
1 x 22uF Cap - Link
2 x 1000uF Cap - Link
1 x 680uH Inductor - Link
1 x 10k Res - Link
2 x 100k Res - Link
1 x IRF9Z34N PMOS - Link
2 x 1N5818 Diode - Link
1 x LT1632 Opamp - Link

You have the option of building two supplies. You'll need to double the above order if you want to build two supplies.

Your supply will need to drive a load. We suggest first starting with resistors to ensure that the circuit is working properly. Please be aware of Ohms law and avoid using loads which are not rated for the wattage that will appear across them... unless you love the smell of magic smoke. Use good judgment.

You will additionally need the following:
1 x breadboard to assemble the circuits on - Link
1 x Ardunio Uno (will work with other Ardunio distributions, but code modification is up to you) - Link
1 x laptop charger / wall wart with a Vout between 14 and 20V (most chargers) at a minimum of 3A - Link
Lots of cabling (wires, alligator clips, etc as you need) to make the connections

You may also want:
Heat shrink & a heat shrink gun
Electrical tape
Multimeter (for testing)
Oscilliscope (for testing)

This Instructable was made as a class project for EE 122A at Stanford University under Professor Greg Kovacs. The team included Michael Digman and Christian Elder. 

Step 1: Laptop Adapter Selection and Modification

The first step on your journey is to pick a laptop power adapter. For our version, we used a Lenovo 65W adapter, which outputs DC 20 V. Although we used this adapter, any laptop adapter with < 20 V and > 40 Watts should suffice, and we’ve tested our power supply with input voltages down to 14 V with minimal effect on the supply output characteristics.

Now that we have a power adapter, we need to alter it for use with the breadboard. Although you can choose to use a female barrel plug adapter, we chose to remove the barrel plug. We should take the time now to note that this probably voids the adapter’s warranty, so if you’re thinking of ever returning the adapter, you probably should buy a barrel plug adapter.

Removing the barrel plug entailed cutting the cord below the plug, stripping the outermost plastic shielding, and grouping the ground wires, which surround the inner plastic shielding. After grouping the ground wires into a bundle, we strip the inner plastic shielding, making sure to avoid letting the ground wires contact the inner power wires. With the two bundles of wires separated, we soldered each bundle to a wire, red for the power (inner) wires and black for the ground (outer) wires. For additional safety, we used electrical tape to separate the two wires. Now we can build our power supply circuit.

Step 2: PWM Signal Amplifier

We begin our supply circuit build by building an amplifier to amplify the Arduino PWM signal from 0-5V to the rails provided by our laptop adapter using an LT1632 op amp.

  1. Short the rails, red to red (positive), blue to blue (ground) (see first image)
  2. Place the op amp across the middle of the breadboard.
  3. Connect pin 8 (V+) to the positive rail and pin 4 (V-) to ground
  4. Connect the 10 kOhm resistor from pin 2 to ground (Note: the image incorrectly connects the resistor to the positive rail. This is amended in later images)
  5. Connect the 100 kOhm resistor from pin 2 to pin 1 (see second image)

Step 3: Power Supply Circuit - Part 1/3

Now that we have adequately amplified the Arduino’s PWM signal, let’s add the switch the PWM is controlling, the IRF9Z34N PMOSFET. The pins on this component are, from left to right, Gate, Drain, and Source. We will connect:
  1. the gate pin to the output of the LT1632 (pin 1)
  2. the source pin to the positive rail
We will connect the drain in the next step.

Step 4: Power Supply Circuit - Step 2/3

With the switch in place, we add the passive and energy storing components: input and output capacitors, diodes, and an inductor.
  1. one terminal of the inductor to the drain pin of the IRF9X34N
  2. cathode of 1N5818 diode to the same terminal of the inductor, anode to ground
  3. anode of a second 1N5818 diode to the other terminal of the inductor
  4. the two 1000 uF capacitors in parallel from the cathode of the second diode to ground
  5. the 22 uF capacitor from the positive rail to ground
The node connecting the anodes of the 1000 uF capacitors is the output of the power supply.

Step 5: Power Supply Circuit - Part 3/3

To sense the output voltage on the Arduino, we need to step the output voltage down to a range of 0-5V. We accomplish this by using a resistive divider with sufficiently large resistors to reduce current draw. Connect:
  1. one side of the 300 kOhm resistor to the output node, the other to a floating node
  2. one side of the 100 kOhm resistor to the floating node, the other to ground
The middle node will be fed back to the Arduino for control. We will now connect the Arduino to the power supply. We begin by shorting the PWM ground terminal to one of the ‘analog in’ ground terminals. See first image.

We then connect:
  1. the other ‘analog in’ ground terminal to the ground rail on the breadboard
  2. PWM pin 9 to pin 3 of the LT1632 op amp
  3. A1 to the middle node of the voltage divider
See second image.

We have now built a power supply circuit. Before connecting it to the laptop adapter, let’s look at the code controlling the supply.

Step 6: Arduino Code

Let’s get the Arduino up and running:
  1. Download and install the Arduino “language”
  2. Download and unzip the Arduino code, (attached below)
  3. Open arduino_2src/arduino_2src.ino
  4. Adjust the variable 'inputVoltage' to the voltage rating of your laptop adapter (see first image)
  5. Connect Arduino Uno to computer via USB and record its serial port
    1. Select Tools > Serial Port > /dev/tty.usbmodemXXXX (see second image)
    2. Write down this serial port designation for the next step
  6. With the Arduino Uno plugged into the computer via USB, upload the code

The Arduino is now controlling the PWM signal, defaulting to the “Off” state, in which the output voltage of the power supply is 0. We will set the output voltage using a GUI which communicates with the Arduino over the serial port.

Step 7: GUI Code

Now for the GUI part:
  1. Download and install the Processing language
  2. Download and unzip the GUI code, (attached below)
  3. Open processing_gui/processing_gui.pde
    If we try to run the GUI code at this point, we see that we need to install the g4p_controls library.
  4. Install g4p_controls library
    1. Select Sketch > Import Library… > Add Library… (see second image)
    2. Search for ‘g4p_controls’
    3. Install ‘G4P’ (see third image)
  5. Set the variable ‘portName’ to the Arduino’s serial port, as captured in the previous step, as a string (see fourth image)
  6. With the Arduino plugged in, run GUI code (see fifth image)
  7. To adjust the power supply's voltage
    1. select the desired output voltage from the drop-down menu
    2. press 'On'
We now have the control loop for our power supply. Only one more step before we let you run loose with your new power supply!

Step 8: Connect Laptop Adapter

Well, now we have a fully functional control loop and a power supply circuit, but no input voltage!

Remember that laptop adapter we made you modify in the first step? Go ahead and connect it to the rails of the breadboard now.

Remember to attach a test load resistance between the output node and ground. As mentioned before, ensure that the resistor can handle the power drop you intend to put across it. Hook up your multimeter to the output of the supply and change the voltage of 'Source 1' in the GUI. The reading on the multimeter should adjust to the voltage you set.

You now have a working digitally-controlled 0-12V power supply!! Congrats!

Step 9: Building Dual Supplies

Should you want to build two supplies, you will use the same Ardunio and the same wall wart but you much build up another buck supply. Follow steps 2 through 8 again. The Ardunio needs to read in the feedback voltage from the new supply and must drive with a PWM generator that is separate from the first supply. This means you'll need to make a few simple modifications:

1) Both supplies must share the same Vin rails (V+ and ground)
2) PWM pin 10 to pin 3 of the LT1632 op amp
3) A2 to the middle node of the voltage divider

For comparison with the first source:
Source 1 must be driven by a PWM generator on pin 9 and must read in source 1's feedback voltage in A1
Source 2 must be driven by a PWM generator on pin 10 and must read in source 2's feedback voltage in A2

That's it! The picture shows two supplies built on separate breadboards, but two supplies can easily be built on a single breadboard. The Ardunio code and Processing GUI are already setup to handle two sources.

Step 10: Closing Notes

Basic Supply Characterization:
  • Each supply can source about 0.6A. We do not suggest going above this as the sag in the output voltage increases with smaller Rload.
  • There is at most a sag of 0.2V and this occurs in a two source configuration at driving 12V when both sources are connected to small Rloads.
  • The worst supply ripple observed is about 0.2V at with very low loads
  • For small Rout, the buck supply can reach an efficiency (Pout/Pin) of about 90% at around 12V. This efficiency does not include the power required to operate the Ardunio.
  • It is possible for the supply to output voltages up to approximately Vin-1, we leave doing this as an exercise.

Discharging Output Caps and Settling Time:
The load resistance and the output capacitors have an associated time constant. When switching from a high voltage to a low one (ex: from 12 to 1V), the output caps discharge the excess voltage through the load resistance. With very high load resistances (>10K), the output caps discharge much slower than with low load resistances (<1K). With an Rload at 20 Ohms, we've observed a settling time from 12 to 0V of about 260ms. With an Rload of 100K, we've observed a settling time from 12 to 0V of 3 minutes. Be very aware that when driving a high Rload, switching to a lower output voltage will take time. This can always be circumvented by placing a low resistance (<1K) in parallel with your Rload, again make sure that the low resistance is rated for the desired power dissipation.

Part Sizing:
The input capacitor, inductor and output cap were initially sized using this excellent documentation from TI.

The output capacitors were changed to be much larger than predicted because we wanted to cut down on the output ripple caused by the controller.

Design Fundamentals:
This video explains the very basics of a buck circuit in theory:

To learn more about Buck design check out this amazingly detailed document by TI:

You may notice that our topology has an additional schottky diode between the inductor and the output capacitor, feedback network and load resistance. This diode was placed intentionally to aid in mitigating the effects of discontinuous mode for small output currents (large Rout). The proportional controller running on the Ardunio should be capable of working with the circuit without this diode in place, however we recommend that you leave it there.


ArifSae (author)2016-09-27

problem, have you faced it, even with 1% duty cycle the output dosent seems to zero volts, event with load resistance. I get 7 volts minimum. I want it to goto zero.

ArifSae (author)ArifSae2016-09-28

I have found my answer finally. When even using 1% pwm, the voltage might not go low to zero, (using 0 pwm will cause fluctuationswhen feedback controlled),

To do this you will also have to used Amplitude modulation i.e varying the voltage of pwm

ArifSae (author)ArifSae2016-09-28

highlighted on top right, this iwll be the problem, going to 0 and 1 pwm will cause a jump of 6-7 volt when working with a 20 v supply.

layla juma (author)2016-09-01


LawrenceK12 (author)2016-02-20

Looks like the YouTube link is broken too.

LawrenceK12 (author)2016-02-20

Thanks for the write-up! Your first TI link is broken. This is probably a good replacement:

PotateMeHard (author)2015-07-21

Looks great, good job, although i don't really like the lack of electrical schematics. A bit hard to understand what's going on, without actually building it myself or reading the Instructable thoroughly.

JonnyG1 (author)2015-01-13

Hi, This is a great project. I wonder if it would be possible to use a Pure Data interface to connect to the supply instead of using Python. Would you have any pointers on how to achieve this? I'm having a difficulty to understand the Arduino code and how this connects to the Python code. Thank you.

gigabiter (author)2014-06-23

Hi, just wondering if someone could help. I have followed these steps precisely and built the project over 5 times now and still am unable to get it to work. The only difference is I have the Arduino Mega 2560. Have also tried 2 different laptop supplies.both around 19v, 3.1amps. I am getting a flash from the rx light on the arduino when I use the GUI to control the voltage so am guessing the board is receiving the command down the port. the debug on the monitor of sketch is showing the input from the analog read at around 962 without the power connected but when I apply the 19v from the laptop power supply it jumps to 1023. As you can tell I am a bit of a noob, sorry ;)

rsyah1 (author)2013-12-07

If i can't find LT1632, what the best replacement beside LT series?

digman (author)rsyah12013-12-07

You'll need a rail to rail, general purpose op amp that can can take input voltages of at around 30V in a DIP package. If the LT1632 is not an option, check out the LT1490 but you'll need to figure out the differences in pin mapping.

rsyah1 (author)digman2013-12-09

How value for switching frequency (fs) that used?

uwezi (author)2013-12-08

This is a nice demonstration on how a buck-regulator works, but I am bit skeptic of using a software loop for the regulation. For one thing you are limited in the reaction time on load changes, for the other a software hick-up can possibly destroy what ever you have connected to the power supply.

With almost the same number of components you could use the opamp as error-amplifier in an analog feedback loop between Vfb and a setpoint defined by the low-pass filtered PWM signal. Of course this would result in a lossy linear power supply, but you would get much less ripple and higher accuracy and resolution.

Another alternative would be to let the PWM signal change the setpoint for an integrated switching regulator, like MC34063 och a "smart switcher".

robotmaker (author)2013-12-08

i did little like that for work ,but much higher voltage 0-1000 volts
i build in-house tester for a electronics test equipment company

nice design

Faulty LED (author)2013-12-06

What is the max current draw?

digman (author)Faulty LED2013-12-07

We managed to pull 1A through at 12V but got significant (around 0.2V) sag. We saw very little sag around 0.6A. Haven't tested it above 1A, but I'm positive that the output voltage would sag.

rsyah1 (author)2013-12-07

if i can't find LT1632, what the best replacement beside LT series?

Saeed Nazarian (author)2013-12-06

Hi, first i think you use buck(step down) converter; but diode #2 make me confused.
what type of Dc to DC converter do you use?

digman (author)Saeed Nazarian2013-12-06

From my comments on the last page:

You may notice that our topology has an additional schottky diode between the inductor and the output capacitor, feedback network and load resistance. This diode was placed intentionally to aid in mitigating the effects of discontinuous mode for small output currents (large Rout). The proportional controller running on the Ardunio should be capable of working with the circuit without this diode in place, however we recommend that you leave it there.

Discontinuous mode causes the right (according to the uploaded schematic) side of the inductor to have a non-zero voltage when it should be zero. This creates a non-linearity that the proportional controller must compensate for. While our controller does work without the 2nd diode in place, we recommend leaving it in as the diode mitigates the non-linearity induced by discontinuous mode by clamping the voltage spike during discontinuous mode at the diode's forward drop.

Saeed Nazarian (author)digman2013-12-06

thank you for answering.
couse i dont see any buck with a diode like that, i ask that question.
so you test it and it work well in full load and small load.?
and diode , except power losing has no bad effect?

About This Instructable




Bio: MS EE student at Stanford University
More by digman:Variable 0-12V, Digitally Controlled, Power Supply using a Laptop Wall Wart & Ardunio
Add instructable to: