# Switching between power sources- when getting to current threshold

I would like to switch between the two power sources- solar panel and battery. In order to avoid the Raspberry Pi restarting \ damaging (when fed from solar panel), I though of making the switching this way:

1. if the current to the MOSFET's gate is lower than 100mA:
MOSFET off (Pi will get current from battery)
2. if the current to the MOSFET's gate is bigger than 100mA:
MOSFET on (Pi will get current from solar panel)

I made some reading about Ina219 current sensor but I think its not a good solution because when I will stop the current after the sensing, there is no way to bring it back- the sensor will have to sense more that 100mA and currently the solar panel is disconnected. so this solution, in this case, is only for detach the solar panel from the load :)

Ill be happy for ideas of making that switching so ~100mA is the threshold.

EDIT

This is the updated circuit

when the solar panel will produce ~0v, the MOSFET will be 'on' and th RPI will get current from the battery

My concern is if I need to worry about under voltage when the solar panel produces ~1v\2v. the RPI will not get current from the rechargeable battery..

This circuit is good for source (solar panel) connected or not connected. if I replace the solar panel with stable DC source, this circuit is good solution I guess. but in solar panel case, the voltage can be vary and too low for the RPI.

And the question is- I guess there is a need with controlling the MOSFET when the solar panel produces low voltage. ill be happy for a solution \ idea for that problem.

Thanks again

• "current to the mosfet's gate": nope, (practically) no current flows into the gate of a MOSFET. It's not a BJT! Commented Aug 27, 2020 at 8:11
• Can’t you just simply the system and have the solar panel charge the battery? Then just one path from the battery to the RPi? Commented Aug 27, 2020 at 8:12
• That circuit will not switch between the two sources, but maybe it's also a representation of the components you're trying to add. I'd go with a similar solution as Winny suggests. But if you really want to swap between the two sources, you want to measure the voltage of the solar panels and not the current. Commented Aug 27, 2020 at 8:16
• winny, im not sure what you mean: just connecting the RPI in parallel to battery? the controller will never stop the charging if so.. Commented Aug 27, 2020 at 8:18
• @user1673206 that's not what winny said, but also, then you'd have not actually built a charge controller. Commented Aug 27, 2020 at 8:19

You need a charging controller, not something that turns of the solar panel if it's not significantly higher in output voltage than your 5V battery¹.

So, buy one of these. Texas Instruments has plenty, and they're not the only one. They typically include a step-up converter so that you can charge your battery and supply voltage to your output even if the sun isn't brightest right now, and control circuitry to keep the output voltage stable, no matter whether fed from the battery or the solar panel.

This is what a TI bq25505 circuit would look like:

Notice how there's a boost converter on the solar cell input, so that the battery can always be charged until it's full, and power is drawn either from battery or solar cell (or combination) depending on load, light and charge situation.

If you don't want to charge your battery, then your approach based on current still doesn't work: your Pi defines how much current is drawn, not the sun.

So, you'd want to use a voltage-based switchover (there's really many answers if you search for "switch 5V power source", I promise), and you still want to add protection to your battery.

¹ there's no chemistry of batteries that does 5V. You're probably confusing "battery" with "USB power bank, which is battery plus charge controller plus step-up converter plus protection circuitry".

• Thank you for the detailed answer. the battery in my diagram, represents charging controller + protection + chargeable battery bank (7.2v). the solar panel is same input for the charging controller AND the MOSFET. I should of mentioned that. the idea of this question was to switch to battery when input is too low (I agree that I need to measure voltage and not current in case of MOSFET). the main issue that im trying to solve is- if I connect the as I described here, do I need to worry about under power to RPI? if so, there is a need for switching by voltage.if not, we are good Commented Aug 27, 2020 at 16:49
• I saw a lot of answers about switching between DC sources- ONLY in case of one source is DISCONNECTED. here, the switching occurs when low voltage (not sure yet about the exact value). so, I guess that in order the RPI will not be restarted in low voltage, there is a need in that switching.. FYI im reading the data sheet of  TI bq25505 you suggested. Commented Aug 27, 2020 at 16:50
• so, your diagram doesn't represent what you have at all... you might want to fix that :) ! Commented Aug 27, 2020 at 19:30
• I edited the question, hope its more clear now. thanks :) Commented Aug 30, 2020 at 16:53