A variable power supply is a must have for anyone wanting to do some serious electronics. There are many guides and videos about making a simple adjustable power supply. The things that make this power supply special is that it is digitally controlled via an encoder, the powerbank is part of the design and it is portable. In this instructable I will show you how I made my variable power supply powered by an Anker powerbank.

Step 1: The Plan

The goal of this project is to create a variable power supply with the 5v 2A input of my powerbank. Since the only voltage the powerbank will provide is 5v, I will use a dc-dc converter to step up and step down that voltage to any desired level.

Normally, a cheap dc-dc converter uses a potentiometer to regulate the output voltage. These potentiometers are usually the small blue multiturn ones. The advantage of multi turn pots is that they can be used to adjust the output voltage very precisely (theoretically). A serious downside of multiturn pots are the amount of turns (duh). This means that in normal usage if I want to change the voltage from, say, 2v to 30v, I have to turn the pot quite a few times. For use in an enclosure I could have used a bigger multi turn potentiometer to adjust my converter to the desired voltage. I decided, however, to use a rotary encoder instead, because, since they are digital, I can program the 'turning speed'. This way I can change voltages far quicker while still maintaining a high resolution in adjusting the voltage. Where I first had to turn the pot multiple times to go to a certain value, I can now go through the full range in one, maybe two turns. Also, I can instantly change the voltage to a set voltage by pressing the rotary encoder's switch.

To realize this plan, I needed a way to have the rotary encoder 'communicate' with the dc-dc converter. An Arduino was my go to choice for this. And to give the arduino a proper analog output to control the dc-dc converter I decided to use a DAC (digital to analog converter).

All the parts can be found in the next step.

Step 2: Supplies

Whoohee, ain't this part fun?

The parts I used for this project:

  • Arduino Nano (or any other arduino board, I just like the built in USB) ($2.09)
  • DC-DC converter XL6009 step up step down ($1.52)
  • MCP4725 12bit (!) DAC ($0.74 on Aliexpress)
  • Dual Female Banana plug ($1.15)
  • Alligator test leads banana plug cable ($0.72)
  • USB Type A 4pin A male socket connector PCB 90 degree ($1.21)
  • DC 100v 10A Voltmeter Ammeter (be sure to include the ammeter search term) ($2.52
  • AC 250v 3A mini rocker switch 10pcs ($0.99)
  • Rotary encoder (it's been a while since I bought them but they are less than $1 a piece)
  • Anker PowerCore 5000 (I got this from germany) ($12)


  • USB-C socket connector 24pin ($2.65 on Aliexpress)
  • Micro usb socket pcb DIP adapter 3pcs ($0.99)

Total= $27.58 including the powerbank

Most items were bought on ebay.

The USB-C socket is useful for me because I have a 5v 3a charger and the micro usb port is in case I want to use a different power bank or a charger. These items could be bought for less maybe, but the $30 dollars should be achievable for anyone, since you can also use a different powerbank.

Step 3: Enclosure

For the design, I just use sketchup. Sketchup for me is the quickest way to get from known parts to a design since almost all parts can either be found in the sketchup component libraries, or just quickly drawn in simple shapes.

With all parts drawn in sketchup, designing the enclosure is where you could design some wickedly awesome forms and intricate plans. I just kept it kinda basic, a box with an angled side. I also used sketchup to draw lines on my design to divide it in shapes I can cut out with my jig saw.

I just printed the designs and drew them on my 4mm MDF plate with a carpenter's square and measuring tape.

Some of the edges are cut at a 45 degree angle, this can be seen in the attached picture where the beveled edges are indicated by double lines.

Step 4: Electronics

Electronics for this project are relatively simple.

The somewhat more challenging part to understand is how the DAC will control the DC-DC converter. To understand the principle behind this, it is usually valuable to download the datasheet of the part you want to manipulate and look at the information presented there.

The information we are interested in from the datasheet of the XL6009E1, is mainly the feedback pin voltage. This feedback voltage is crucial to understanding how these dc-dc converters work. A switching regulator like the type I used in this project work by making sure the feedback pin stays at a specific voltage, in my case this is 1.263v, which is within the specified range in the datasheet, this voltage can be measured using a multimeter. The regulator will try to maintain this voltage at the feedback pin by changing the output. A potentiometer in combination with a fixed value resistor form a voltage divider and by turning the potentiometer, one can change the ratio at the output vs the feedback pin, and since the feedback pin voltage is maintained the ratio determines the voltage output.

If you are interested in a better and/or more elaborate explanation, you should probably google a bit to get the finer points of these devices.

Now that we roughly know how these converters work we can try to influence it. Instead of using a potentiometer we will be applying a voltage on the feedback pin. This changes the voltage divider network in such a way that we can control the output by applying a voltage at the intersection point. A very good website that explains how this control mechanism works is this website, it even supplies a calculator. It will take you through all the steps of setting up the control circuitry.

I will be using a 500 ohm resistor on the feedback pin, where the DAC will apply a maximum of 3.3v which will result in a range from 0-40v. And because the amount of steps the DAC can do is 4096, the resolution will be a theoretical ~0.01V. Which is quite nice.

Step 5: Arduino Code

With the electronics part complete, the fun tinkering with code can begin!

The Arduino's job is to take the encoder's turns and translate it to a number between 0-4095 that the DAC can converter in a 1/4096th step of between 0-3.3v. I mentioned in a previous step that I chose a rotary encoder so that I could have an 'accelerated' increase of the voltage. This took me a while to get right, because it has been some time since I programmed an Arduino, so please forgive me any clutter in the final code.

The program works by taking into account all the possible values the rotary encoder can take and making it so clockwise and counterclockwise movement can be counted. This site explains how this works and also contains part of the Arduino code that I used as well.

The pushing of the button causes the DAC to go up to the voltage that translates to exactly 5.00 volts on the output of the device. I first had it set to go to the lowest possible voltage, but 5v seemed like a more logical choice.

Step 6: Painting

After I glued the entire box shut, it was time to make my little box look a little better.

I taped off any parts I didn't want covered in paint and mixed some acrylic paint to match my intended colour. The colour I ended up with was slightly different than I had hoped, but I think the final colour is decent enough. After painting I spray painted the result with some acrylic transparent finish paint. And that's it for the painting part, really the shortest step for me in any build process. If it works it doesn't have to be pretty (as can be seen in my not so neatly packed electronics) but some finishing always gives me more satisfaction in having build something that looks decent as well. Otherwise I might be the only person that likes it, since it doesn't look like anything anyone would want to have. Moving on.

Step 7: Result

I encountered some problems while testing my device. The accelerated steps of the encoder caused my powerbank to turn off, possible because of a sudden spike in current. I tried hooking the device up to a more capable power supply, but then my arduino would just stop responding and the voltage would stay fixed.

I hope someone with more insight in electronics can shed some light on this, because it is a rather annoying "feature". To fix the issue I just limited the amount of acceleration the code would allow, as can be seen in the final code of the previous step, where I limit "K" to be a maximum of 40. Using the encoder's push button to go to a high output voltage instantly also resulted in the same crash of the device.

While under load, specifically inductive load, the voltage would vary about 1v with a period of roughly one second. So when connecting a fan, the fan would speed up, slow down, speed up, slow down, etc. Also something I would like some insight into, since the dc-dc converter should be able to handle this? The operation during other load tests was fine, however, when flipping the switch when a load is attached, the powerbank would again have its safety triggered and turn off. When using the supply, high loads should be ramped up slowly.

Also the output voltage isn't the same on every startup, I would think the 3.3v regulator would produce a stable voltage and that the DAC would also produce a constant voltage, so then it would have to be the dc-dc converter. I should look into this some more and maybe get a simple oscilloscope one day...

If I were to make a new or other similar device, I would add an op-amp to isolate the DAC from the converter circuit. I would also look into a circuit to limit inrush current, with a microcontroller at my disposal this would be very doable (switching in and out a limiting thermistor for example). A dedicated voltage reference would also be a nice thing to have, but that would probably be for another project, where having a fixed value would be far more important.

Hopefully some of you will find this instructable interesting, I would love to hear your thoughts.

Thank you for reading!

<p>Hi, interesting concept to control the XL6009 with a DAC and nice enclosure but you will need to invest a bit more in your feedback circuit. </p><p>Because you are adding a DC voltage from the DAC, the feedback from the output which the converter is trying to control, is being interfered with. Keep in mind that it is trying to keep the 1.2V on the FB pin by changing the PWM on the output. That is why you see the &quot;ringing&quot; on the output, basically the control circuit goes unstable.</p><p>Also when you make big changes on the FB pin with the DAC, you cause massive over reaction on the converter which causes big surge currents on your source which probably goes over the 2.1A that your powerbank can deliver and it goes into self protection.</p>
Thank you for your response. I'm not sure I get what you are saying. If the DAC worked like it's​ supposed to, the functionality of the XL6009 shouldn't change, right? But since there is a problem I figured there would have to be a problem with the dac in combination with the feedback. Would a voltage follower help here to isolate the DAC from the feedback circuit?
<p>Hi. I am sure that your DAC circuit works, hope to use your code myself soon. You can test that by decoupling it and checking that it is supplying the voltages that you expect. </p><p>The problem with the feedback is that the Vout = 1.25 x (1+R2/R1) normally but + Vdac in your case. </p><p>Have a look at the basic circuit from the datasheet below. R2 is supplying direct feedback on the output to pin 5. R1 to ground is trying to maintain 1.25V but if you add Vdac to that, you take the circuit out of design envelope.</p><p>What I would try, have not attempted this on this regulator, but have done it on linear versions, is to tie R1 instead of ground to pin 1, decouple pin 1 from ground and add your DAC output, buffered/amplified 'under' the XL6009 to lift it above ground. That will keep the feedback loop and stability intact. </p><p>Have a look at Guido Socher's design and how he multiplies the voltage and add current capabiltiy after the DAC circuit in his power supply design: <a href="http://main.linuxfocus.org/English/June2005/article379.meta.shtml" rel="nofollow">http://main.linuxfocus.org/English/June2005/articl...</a></p>
<p>The DAC does produce the wanted voltage, but I think I should've checked it while it was connected to the XL6009 when it misbehaved. </p><p>The voltage at the feedback pin is 1.263v because there is a third resistor in the network, changing the topology. There will actually be a negative current flowing through the DAC at some point. </p><p>I'm curious to see what will happen to the converter when you change its ground. In my case it's probably not usable since the potential between Vin and Gnd would become less than 5v.</p>
<p>The DAC will not be happy with a negative voltage on it's output, be careful. </p><p>Yes, you might need a negative voltage rail as well to get to 0V, in which case you could also consider an op-amp to buffer/drive a power transistor in linear mode, rather than swithmode. </p>
Negative current, and the DAC should work in sink mode. But yes, the opamp could limit the lowest voltage since the DAC is rail to rail.
<p>Nice design. I think this is the first portable power supply that I have seen with a digital readout. </p>
<p>I might have to correct you on that one : <a href="https://www.instructables.com/id/Digital-Battery-Operated-Powersupply/">https://www.instructables.com/id/Digital-Battery-O...</a> :p<br>Concerning this project: the fact that the powerbank plugs right into this one is very cool!</p>
<p>I really like your power supply, I'd love to build one from scratch one day and your instructable is very informative. And thanks!<br></p>
<p>Thank you!</p>

About This Instructable




More by rohmega:Variable Powerbank Supply 
Add instructable to: