TP4056 load sharing problem, output voltage flactuates from 2.5 to battery voltage (4~4.2 V)

I'm trying to bulid a li ion battery charger with TP4056 module (with battery protection) with load sharing, so that connected ESP32 dosen't restart, when external power supply is turned off. I've attached the schematic.

  1. When the ac-dc adapter (which is giving 5V DC at input), is turned off, voltage at SYS OUT flactuates from 2.5~2.6 V, then gradually increases to battery voltage, usually 3.9~4 V. When the adapter is turned on, then the voltage at SYS OUT is 4.8~4.9 V.

  2. Both led is turned on of TP4056 module, when the battery is connected and external 5V is applied at input, battery voltage is measured 4.0~4.1 V in this condition.

The SYS OUT is connected with 3.3V LDO (MCP1925S), when external power is turned off and SYS OUT flactuates from 2.5 V, the output of LDO isn't 3.3 V, hence the connected ESP32 restarts. I need to build this, so that the esp32 gets uninterrupted power supply, 3.3V.

How to solve this?

The IRF9540 is a poor choice for this circuit.
You need a logic level FET with a low Rds(on).
You might only be able to find that in an SMD package.
Leo..

See this post for better Q3 choices.

In addition to the mosfet issue, both LEDs on the TP4056 module should not be lit up at the same time. It's possible you have a bad battery connection. One of my modules lights up both LEDs when it thinks no battery is present.

If you can find one on Ebay or Aliexpress, the NDP6020P mosfet is a TO-220 package P-channel mosfet that should work. It is logic level, with typical threshold of 0.7V, maximum 1V. But it has been discontinued, and doesn't show up on Digikey or Mouser. Be sure it's the NDP6020P. There's an NDP6020 that's N-channel, which is not what you want.