I have a Raspberry Pi model B+ and I've been trying to design a solution so that I can switch power supply without having to shutdown.

The idea is this: I have 2 li-ion 18650 batteries with protection board(DW01+) which disconnects the batteries when they reach a lower threshold of 2.4V and an upper threshold of 4.3V. I want to connect those in parallel to a step-up power converter (mt3608) which will give a steady output of 5V to power the Raspberry Pi.

I also have a charger circuit TP4056 which can supply up to a maximum of 1 Amp that I want to connect to the battery pack. The Pi requires around 0.56 A and 5V with a few peripherals connected but I want to supply extra power for whenever it might need it.

When I have access to an electric outlet I want the battery pack to be disconnected and the Pi powered with a 5V 2.1 Amp DC adapter. I want it to power the Pi and at the same time charge the battery pack and if I disconnect the DC adapter it should switch back to running of the battery pack again without the need to shutdown first. The reason for this is that I want to use the full capacity of the charging circuit to charge the batteries and because I haven't found a suitable charger that can supply a higher current than 1 Amp.

Is it possible to do this with mosfet transistors to switch on and off the inputs? I thought of using a relay to switch between the power supplies but that's too slow and would require a big capacitor as I understand it. Every solution I can think of seems to require a diode but that would lower the voltage below the threshold for what the Raspberry Pi accepts. I should also add that my knowledge of electronics is a bit limited.

Edit: This schematic is far from pretty but maybe it helps to show how I want to connect things. I put two transistors in the schematic but part of the problem is that I don't know where I should connect the gates. enter image description here

Edit 2: Added clarification about the batteries, the power converter and about my goal.

  • \$\begingroup\$ Can you add a schematic? \$\endgroup\$
    – Gomunkul
    Apr 9, 2015 at 10:39

1 Answer 1


It seems you are making this overly complicated. Have the battery power the Pi always. When you have wall power available, it powers the battery charger. During that time the battery is getting charged since presumably the charger produces more current than the Pi draws. If not, get a different charger.

Nothing needs to be specifically switched. Whether the battery is being charged or not, either way the battey voltage is used to run the Pi.

  • \$\begingroup\$ Thanks for your input! I have considered to always run it of the battery as you say, but the chargers I've found produce around 1 Amp and while that is enough for the Pi it would increase the charging time of the batteries by too much. \$\endgroup\$
    – Jimmy
    Apr 9, 2015 at 15:26
  • \$\begingroup\$ @Jimmy: Assuming that you want to both charge the battery and run the Pi, you're going to need a bigger supply anyway. And then you might as well use Olin's solution. I think you're going to end up there no matter how you approach it. \$\endgroup\$
    – AaronD
    Apr 9, 2015 at 18:52
  • \$\begingroup\$ It doesn't really have to be a battery charger either. A simple DC supply should be fine; the battery will naturally stop charging when its open-circuit voltage equals the supply. Maybe some current-limiting into the battery...maybe. \$\endgroup\$
    – AaronD
    Apr 9, 2015 at 18:53
  • \$\begingroup\$ @AaronD: Wouldn't 2.1 Amps be enough to both charge and power the Pi? The charging circuit would draw a current of 1 A to charge the two batteries and leave 1.1 A for the Pi. I don't know a whole lot of charging li-ion batteries but if a apply 5 Volt to the batteries wouldn't that damage them since they are normally just charged to 4.2 V? Also I've heard that they should be charged with CV and CC. \$\endgroup\$
    – Jimmy
    Apr 10, 2015 at 7:41
  • \$\begingroup\$ @Jimmy: Is 2.1A enough? Ehh, maybe. Depends on what the Pi is trying to do at the time and how dead the battery is. I'd go a bit bigger, like around 5A or so. As for using a 4.2V battery to power a 5V device, that may have its own can of worms, regardless of how you charge it. I'm pretty sure the Pi wants 5V, not 4.2V down to 3.something when dead. Given that information, I'd look at using 2 cells in series + a regulator for the Pi + a 2-cell balancing charger that can keep up with both. \$\endgroup\$
    – AaronD
    Apr 10, 2015 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.