I have got the following situation:

  • ESP32 powered through a LIPO Battery
  • 5V (1W) solar panel
  • LIPO Battery charger (through the solar panel)
  • voltage divider to sense current flowing through the solar panel to charger
  • N-Channel MOSFET to switch the solar panel off (so avoiding to charge the battery) if the battery is already charged.


As you can see from the schematics, I connect P2 with the positive terminal of the solar panel, which then flows towards P3, from here I connect to the positive terminal of the LIPO Charger. Then I connect the negative terminal of the LIPO charger to P1. Then P4 to the negative terminal of the solar panel. I was hoping to be able to switch the MOSFET ON and OFF through pin 25 (from the ESP32), but it never goes completely OFF. Please note that the charger has common ground with the ESP32.

Do you know what am doing wrong here? Any suggestion to improve this switching?

  • \$\begingroup\$ Are you connecting the negative terminal of the solar panel to the GND of your circuit anywhere? \$\endgroup\$
    – gcr
    Jul 28, 2021 at 20:19
  • \$\begingroup\$ So one software bug with some solar and your battery explodes from overcharge? Why not a stand alone regulator? \$\endgroup\$
    – winny
    Jul 28, 2021 at 20:20
  • \$\begingroup\$ @gcr if I connect the negative of the solar panel to the GND which is P4 I think I just bypass the MOSFET.p1 is connected to the GND.i agree that not having that connection P4 floats when the MOSFET tries to go off. \$\endgroup\$
    – Edge7
    Jul 28, 2021 at 20:32
  • \$\begingroup\$ Without some connection between the negative side of the panel and your circuit ground, the solar panel might push it's negative terminal low enough Vs. your circuit ground that the FET still conducts even when the gate is at ground potential. I'd change the circuit to switch the positive side. \$\endgroup\$ Jul 28, 2021 at 20:42
  • \$\begingroup\$ @unimportant can you please show me how to switch the positive side?it does not seem to be straightforward,maybe using a p channel? \$\endgroup\$
    – Edge7
    Jul 28, 2021 at 20:52

1 Answer 1


Here's a simplified schematic of what is possibly going on:


simulate this circuit – Schematic created using CircuitLab

The solar panel's positive terminal is connected to the charger chip (omitted the current sensing resistor / voltage dividers for clarity). The charger chip will have some leakage to ground.

Since we are trying to model the situation where the MOSFET is off (solar panel negative terminal "disconnected") there is no current flowing. No current means no voltage drop across this leakage resistance. So we can say the solar panel's positive terminal is at ground potential.

This means the solar panel's negative terminal is below ground potential. So there is a negative voltage on the MOSFET source.

Thus, even when the MOSFET gate is connected to ground to turn the MOSFET off, there is a gate-source voltage, which prevents the MOSFET from fully turning off.

It can't turn on fully in this state. That would connect ground (gate) to source which would turn the MOSFET off, so it is stuck somewhere in the middle in it's linear region.

A possible fix would be to switch the high side of the solar panel:


simulate this circuit

I'm using BJT's in this example because they're current driven rather then voltage driven like MOSFETS. With the low voltage level's involved, and the fact that solar panel voltage might fluctuate with light levels, one might have trouble maintaining enough gate-source voltage to keep a MOSFET fully on.

  • \$\begingroup\$ thanks. It is pretty clear, can you just spend 10 words to explain the BJT circuit? \$\endgroup\$
    – Edge7
    Jul 29, 2021 at 14:39

Your Answer

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

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