Build Your Own Battery Power Supply




Introduction: Build Your Own Battery Power Supply

Have you ever needed to power a project that's not near an outlet? Have you needed to test using different voltages? Are you curious about analog circuits and power? Using Autodesk Circuits and a lead-acid battery, you can create a circuit that will act as a variable power supply, outputting a range of voltages from 5V to 20V.

After creating the power supply you could drive motors using variable voltage, power microcontrollers, logic circuits, LED strings, analog circuits, and much more.

This is a good way to learn how basic electronic components can be put together, like a puzzle, to accomplish a task. It will also leave you with an awesome mobile power supply to test your projects with!

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: MOSFET Basics

MOSFETS are incredibly useful devices that are used in everything from basic electronic projects to your computer's CPU! MOSFET is short for Metal Oxide Field Effect Transistor. They can be used in logic circuits (binary circuits: high or low, 1 or 0, 5V or 0V), amplifiers, as switches and more. There are equations that dictate how the transistor acts but we will focus on using a MOSFET as a switch.

MOSFETS have three pins: gate, drain, and source (check your device for the pin-out, the pin arrangement). When a voltage is applied to the gate pin, current will begin to flow through the source and gate. The gate voltage required to allow current to flow is called the 'threshold voltage'. This value is specified by the datasheet of the 'FET. If you apply a voltage less than the threshold voltage, the 'FET will be in 'cutoff mode' and no current will flow. Apply enough voltage and the MOSFET will enter saturation mode, allowing current to flow. This behavior allows us to use a MOSFET as a switch. You can use an Arduino (or another voltage source) to apply a voltage to the gate of a MOSFET, thereby 'turning on' the device and allowing current to flow, just like you would control a light switch.

MOSFETs come in two varieties: N-MOS and P-MOS, which stands for n channel MOSFET and p channel MOSFET respectively. The n and p dictate the material that makes up that type of 'FET (this goes into semi-conductor physics).

  • N-MOS: Current flows from drain to source
  • P-MOS: Current flows from source to drain

The simulation below uses a N-MOS as a switch to light up an LED. The function generator turns the MOSFET on and off. Vary the frequency to change how fast the LED. Vary the amplitude. This controls how 'open' the MOSFET is. It changes how much current we allow to flow. When does it cut off completely?

MOSFETs tend to get hot while running (especially if using high current), so make sure to not touch the device while it's running. Be careful to not exceed the voltage or current capabilities of the device, it will release the magic smoke (aka it will break).

Step 2: How to Boost Voltage

A boost circuit is great when you need a higher voltage source than the battery you have on-hand. For example, charging a Lead Acid battery requires 12.9V, some automotive parts require 16V, and some projects require 14V. Motor speed can also be controlled by the applied voltage. Due to the physics behind the the conservation of energy, a boost circuit can be a little tricky, but it's a great example of an analog power circuit.

The conservation of energy implies that energy cannot be created or destroyed, only transferred. In the case of our boost circuit, this means that power must be conserved. So if we boost up the voltage, we effectively decrease the amount of output current we can pull ('output' meaning: the current being pulled after the voltage has been boosted). To compensate for this, the battery must work harder to supply both the boosted voltage and the requested amount of output current.

Power = voltage * current

Let's look at an example of how power is conserved. We start with 5V pulling 1A which equates to a 5-watt power draw. We want to boost that up to 10V. Power must be conserved, since we doubled the voltage, we only get half the output current, 0.5A. If we wanted to have 1A output current, we would need to provide 2A into the boost circuit.

So far these concepts have been ideal, not taking into account the real world losses. All components and circuits are at least somewhat in-efficient. An example of this is heat. Components will sometimes release energy is the form of heat. What does this mean for our circuit? If we want to double the output voltage, we will have to supply more than double the input current. Use the example above. In the real world, to get from 5V @ 1A to 10V @ 1A, we would need to input more than 2A. The higher you boost the voltage, the more inefficient the system, the greater the power loss to heat. 'Power loss' in this case does not mean that we are breaking the laws of physics, it means that the power is getting diverted to other forms of energy like heat.

Step 3: Components and Tools

Now that you know the physics behind a boost circuit we can begin building. You will need the following items:


Note: The capacitor values do not need to be exact since they are being used for decoupling. The inductor value and resistor values should be close to the listed values. SparkFun, Digikey, and Amazon are all great places to find components. It can also be very helpful to have a resistor kit and a wire kit.


  • 1x multimeter
  • Wire strippers
  • USB cable for uploading Arduino sketch
  • 1x power supply (optional)
  • 1x small Philipps head screw driver (optional depending on the potentiometer)

Step 4: Design and Simulate the Circuit

A good way to visualize circuits is as blocks. Each block does a specific task. Put the blocks together and you get a fully functional circuit. The circuit schematic (first picture) shows the battery power supply circuit. Look a little closer and you will notice that it is made of a few blocks. Scroll over each of these to see their function:

  • Battery: This is the 5Ah 12V lead acid battery to power our circuit. Lead acid is a good choice for this circuit because it can source high current. In other words, the circuit draws a lot of current when powering up and to maintain the boosted voltage. That's one reason why cars use them! Lead acid batteries also run at 12V which makes boosting the voltage easier.
  • InputFiltering: These two capacitors help smooth out power line going into the boost circuit. This helps reduce fluctuations and ripple that could cause issues in a circuit expecting a steady 12V.
  • Microcontroller: An Arduino or other device to control the boost circuit and keep it within its limits.
  • Control Knob for Boost Circuit: A voltage divider and potentiometer allow the user to control the voltage output from the boost circuit. The two resistors on the right drop the voltage down to 5V. This needs to happen because the Arduino can only read signals up to 5V. Now that voltage divider has reduced the voltage to 5V, we use a potentiometer to vary the voltage between 0V and 5V. The Arduino reads this in.
  • Regulating Circuit: This circuit's job is to reduce the voltage depending on the use input from the potentiometer. 5V regulators generally regulate voltages to a static 5V. It does this by matching the output pin to be 5V higher than the GND pin. Generally the GND pin is connected to the common GND (battery ground). To make the regulator something other than 5V, we can apply a voltage to the GND pin. So for example, if we put 3V on the GND pin, the 5V regulator will make the output pin 5V, to give us a 8V output. So to make our circuit output anywhere from 5V to 12V we add a voltage divider that varies the voltage on the GND pin. Depending on the position of the potentiometer, the output of the regulating circuit will be between 5V and 12V.
  • Boost Circuit: This is the part of the system that increases the voltage. It induces voltage spikes (short and sharp increases in voltage) and then smooths them out into a stable power line. This can be modeled using complex equations and concepts but we will take a high level conceptual look. Remember that inductors do not like changes in current, MOSFETs can act as switches, capacitors smooth voltage ripple, and diodes only allow current to flow in one direction. We start by having the Arduino continuously turn the MOSFET on and off very rapidly, which causes the middle node (in-between the inductor, diode, and MOSFET) to be pulled down to ground (0V). This causes a rapid and continuous change of current (positive and negative). The inductor, which hates changes in current, will then induce a spikes to try and counteract this (positive and negative). So this this leaves us with a bunch of rapid spikes. These spikes then go through the diode to only allow the positive ones to pass. The capacitors then take these positive voltage spikes and smooth them out. This leaves us with a boosted and stable voltage source.
  • Boost Feedback: We want the Arduino to know what the system is outputting, that way it can ensure the voltage stay at the user-chosen voltage. The Arduino can read in voltages from 0V to 5V. We use a voltage divider to drop the output voltage from a potential 20V to 5V. The Arduino can now read this value in and interpret it.
  • Load: For the components to do their job, they need a minimum amount of current flow. The 430 ohm load is meant to constantly pull a little but of current so the circuit can run without an external load. This means we can run the system and pick our desired voltage without having to have our load/or project plugged in yet!

That's a lot of information! Remember to look at it one block at a time. Each part is manageable. Put the blocks together and you have your battery power supply!


The simulation below shows the boost circuit:

The leftmost multimeter shows how much current the system draws. You will notice that as you boost the voltage, the current we draw increases. The right multimeter and the o-scope show the output voltage and output waveform respectively.

Step 5: Code!

Now that we have all the analog electronics figured out, we can look at programming the system. To control the boost circuit, we have to apply a pulse width modulated (PWM) signal to the MOSFET's gate pin. This simple means a signal that goes high (5V) and then low (0V) at a set frequency. To control the boost circuit's output voltage, we need to change how long the MOSFET is on or off for. This is referred to as the duty cycle which you can learn more about from SparkFun.

So lets start by defining our variables. This comes at the top of the sketch:

#include "TimerOne.h" //include the library we need to create the PWM signal

double duty = 512; //start the duty cycle halfway between 0 and 1024, aka 50% duty cycle

double feedback; //the variable that tells us the actual voltage
double setVoltage; //the voltage the user wants

double pot; //holds value of potentiometer before it gets translated into user preferred voltage

Now that we have our global variables defined, lets write what happens when the sketch first runs:

void setup()
  Serial.begin(9600); //initialize the serial monitor for debugging
  pinMode(13, OUTPUT); //this is the pin that controls the MOSFET, its an output
  pinMode(A5, INPUT); //the feedback input, lets us know what the voltage is currently at
  pinMode(A4, INPUT); //the input from the potentiometer that sets the preferred voltage

  Timer1.initialize(100);         // initialize timer1 at our set frequency
  Timer1.pwm(9, 512);                // setup pwm on pin 9, 50% duty cycle
  Timer1.attachInterrupt(callback);  // needed for the pwm signal to work

This will allow us to us pin 13 for the signal controlling the MOSFET, and use analog pins 5 and 4 for the feedback and potentiometer control respectively. It also does the initial setup for the timer1 library. The timer1 library also requires a function called 'callback':

void callback(){
  digitalWrite(10, digitalRead(10) ^ 1);

You don't need to understand this function. Just make sure to copy it into your code (but outside any other function).

Now lets get to the fun part. The main loop, controlling the MOSFET:

void loop()
  pot = analogRead(A4); //get the position of the potentiometer
  setVoltage = map(pot,0,1024,118,205); //use the map function to get the value between 11.8V and 20.5V, this allows some margin of error
  setVoltage = setVoltage/10; //since the value is between 118 and 205, but we want it as 11.8 and 20.5, divide by 10
  Serial.println(setVoltage); //print voltage to serial monitor, good for debugging
  feedback = analogRead(A5)*11.11*5/1024; //read in the actual voltage, the math part is to account for the voltage divider and the arduino's conversion to a number between 0 and 1024
  if(feedback < setVoltage && duty < 850) duty += 1; //if the actual voltage is less than what we want it to be, then increase the duty cycle to get us up to where we want
  else if(feedback > setVoltage && duty > 50) duty += -1; //if its greater than we want it to be, lower the duty cycle to get down to the desired voltage
  Timer1.setPwmDuty(9, duty); //set this new duty cycle preference

This section of code reads in the potentiometer and the actual output voltage. Based on this information, the Arduino either increases or decrease the duty cycle signal going to the MOSFET. This will increase or decrease the output voltage. This section of code is in the void loop so it can continuously check the potentiometer value. The Arduino sketch code is attached.

Step 6: Putting It All Together and Testing

Disclaimer: Do not pull too much current from this device (draw less than 250mA). Be prepared to shut off power from the battery to the circuit and do not touch any components with your bare hands.

Now that we have designed, simulated, and coded the project, we get to actually build it!

Tips and Tricks while Building:

  • Use the electronics lab as a guide!
    • I didn't include the 9V regulator in the electronics lab but don't forget to add that! The 12V battery line goes to the 9V regulator input, and the output goes to the Vin pin of the Arduino.
  • Remember to use the power rails on the breadboard to your advantage. I used the top positive rail as the 12V battery input and the bottom rail as the boost circuit output.
  • Don't trim the leads of components until after testing. Resistors and other components will have long leads. but leave them like this until you know everything works.
  • Try to avoid having wires overlap too much.
  • Make sure the diode and electrolytic capacitors are pointed in the right direction.
  • TEST AS YOU GO! When you put in a voltage divider, test that it divides the voltage like you expect. It is a lot easier to troubleshoot each part individually.
  • Connect all grounds together.

Now that everything is connected, you have reached the exciting moment of seeing if it all worked! It might not work the first time, but that's OK! Circuits and electrical engineering takes many iterations. Almost no designer gets it right on their first try!

When powering it on for the first time, use a power supply if you have one. Limit the current to 3A. This will keep everything from blowing up if something was connected wrong. Once everything is working using the power supply, you can use the battery. I would highly recommend adding a switch in-between your battery and the circuit. It makes it easier to turn the circuit on and off, as well as making it safer. Once you get the circuit working with the battery, you are ready to power your electronic projects!

Why are some of the components so big? Specifically the inductor and capacitors are very large because they have to handle a lot of power (a couple amps at 12V). This means they need to be beefier in order to not explode/break. This is similar to why the power brick for your laptop is so big, its handling a lot of power (and also converting from AC to DC).

Step 7: Future Improvments

You should now have a working, battery power supply! It is a great tool to use on those projects that are in the 'field', away from outlets and wall-warts. You could drive motors using variable voltage or power microcontrollers, logic circuits, LED strings, analog circuits, and much more.

If you would like to take this project to the next step, consider creating a PCB and/or 3D printing an enclosure. Tinkercad or Fusion 360 would be great tools for this. Using the PCB Design Tool you can turn a messy breadboard into a compact and reliable printed circuit board. 3D printing would help protect the components and add a personal touch to your device.

A power supply has some complicated concepts, but it is a great example of a fun analog circuit. With a little determination and curiosity, you can have your own battery power supply in no-time!

Be the First to Share


    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Arduino Contest 2020

      Arduino Contest 2020

    11 Discussions


    3 years ago

    HOW TO MAKE AN INVERTER 12v DC ------> 220v AC control by arduino ET 2 IRF transistor

    I have a code functional ardouino mli (pmw)


    3 years ago

    Very nice Instructable, on a contemporary subject!

    important thing that has not made it in your instructions is a fuse
    right at the battery terminal. If you ever have shorted a battery, you
    know why. If not, just trust me. Flames on the bench, or on the
    kitchen table, are never a good thing, Martha be damned...

    that type of 6 and 12V batteries, I simply make a very short jumper,
    less than 1 inch long, terminated at both ends with an INSULATED (fully
    covered) female tab connector, and then connect this jumper to the
    battery, and the other end to an automotive fuse, available in many
    values such as 1, 2, 3,5, 7.5, 8, 10, and more amps. You can use a mini
    or a standard size of fuse, the maxi will not take a 1/4" female tab
    connector, if I recall corectly. The other leg of the fuse receive your
    female tab connector (remember, INSULATED, or at least covered in
    heatshrink, a diameter of 3/16" is about right) that goes to your power
    switch. Voila! You are (mostly) safe and secured! And the fuse is
    easy to replace, while the "fuse holder" is basically the cost of two
    tabs, like, cheap.Don't skip that step with lead acid and
    gelcell batteries, they pack a lot of energy and are always happy (...)
    to dump it out violently. This said, they are great power source, easy
    to recharge and maintain, as long as you use them safely.


    3 years ago

    Hey, this is a bit off topic, but I'm not really sure where/who to ask about this. I'm trying to make a portable 120v power supply capable of at least charging my laptop, and optimally (not sure how much I can really hope for) powering an electric weed whacker. I have a bunch of 18650 3.7v LiPo batteries rated from 2Ah-3Ah. I probably need to use just one type to avoid unbalanced batteries, so lets say a bunch of 2Ah batteries. I also have an inverter meant to be connected to a car via the 12v cigarette lighter socket. I was thinking I could connect 4-8 batteries (4 in series, or 2 parallel series of 4) build a 12v voltage regulator and hook that up to the inverter. I'm not sure what sort of amperage the thing is built to handle, some googling gave me about 40A for a car battery. Peak output for one of my batteries is about 20A, so with 8 batteries (2x series of 4) that should give me 40A. I'm guessing I also want a current regulator or a 12v regulator that also regulates current? Anyways, I know I need some sort of regulator to keep my batteries from overheating. Any assistance and/or advice would be greatly appreciated.


    Reply 3 years ago

    A simple solution is a voltage converter, such as

    which you can power from any (sufficiently powerful) battery within its input voltage range, and set to your required output voltage. I would suggest a 12V lead-acid battery. For a laptop you might need additional smoothing on the convertor output, a big and a small capacitor across the terminals.

    For a smaller laptop supply battery, use an RC car type or power tool battery of (at least) similar physical size to your laptop battery.

    Or you could just buy a spare laptop battery, charge it, and keep it with you. (Doh !-)

    (But you will need to switch off the laptop when changing it.)


    Reply 3 years ago

    Most laptops can use low DC voltages, and don't need a regulator since they have one built in. So just put two 12 VDC batteries in series ans pass that through the DC input.

    As for the weedwacker, you may be surprised that its motor works on DC already! They have a diode bridge to rectify the AC going in to 160 VDC average, so you can either string several 12 VDC batteries in series, use a 12 VDC to 120 VAC inverter, or make a 160 VDC boost supply (the weedwacker need no regulation).

    Lucas Reed
    Lucas Reed

    Reply 3 years ago

    As @neopolitan mentioned, converting from DC to AC back to DC will be inefficient and noisy. Is there any reason you can't convert from 12V DC to 19V DC?
    Also be careful with the battery supply. While batteries are suppose to be able to source a lot of current, doing so for an extended period of time (aka seconds) can damage the cells. Also putting batteries in series and in parallel can cause balancing issues, even if you are using the same type of batteries.


    Reply 3 years ago

    converting 12dc to 120ac and back to 19dc would introduce crazy losses, not to mention digital noise which computers don't like...

    kavish laxkar
    kavish laxkar

    3 years ago

    gr8 instb

    What is the power loss?

    Lucas Reed
    Lucas Reed

    Reply 3 years ago

    Thanks! The power loss is pretty substantial and ranges depending on the voltage difference from the battery voltage. This is definitely not something you want to use as a permanent power solution.


    3 years ago

    Can you use a deferent style of battery?

    Lucas Reed
    Lucas Reed

    Reply 3 years ago

    It will change the output voltage range and will require a couple code tweaks but you can definitely use a different battery! Keep in mind that the higher you boost the voltage, the more current you will draw. Make sure the battery can handle that. I used a 12V lead acid battery because it already has a relatively high voltage and can source a lot of current.