5v USB and Vbattery selection for LDO input

I need Help in a circuit for power selection for esp32 i have 2 options

1)USB_C 5v

2)Battery 4.2V

I need circuit in which USB is first priority mean if 5v USB available it doesn't use Battery because my device is battery operated

I know a solution is using 2 diodes but issue is diode voltage drop as i say project is battery operated so unnecessary voltage drop for battery is not affordable
Circuit is below

I searched about Oring method use mosfet for power source selection .I connect battery at drain . Please check will this circuit works or not

Please Suggest me what should i do ?

Is this 4.2V battery actually a 3.7V Li-ion battery?

You need LDO with very low dropout to make it work with normal li-ion/ lipo battery.
May I suggest you to use Esp32 board with built in battery management. It resolves your problem and few others eventually, battery protection and charging.

Just one example:

There is at least one specific chip/board that does that but I can't find a link. Some boards will auto select power but you need to look at the Espressif documentation about power to know for sure.
I will bet your 4.2vdc battery is really a 18650 Lithium, which means it's really a 3.7vdc battery, and not strong enough. If the VIN pin has an LDO attached, then the usual approach is to use two 18650s in series, and the LDO will drop the 7.4vdc to 5vdc.

A google search of
chip for managing two power sources
gives the following high level result (AI)

A Power Management Integrated Circuit (PMIC) is a chip designed to manage two or more power sources in a device. PMICs are commonly used in battery-operated devices and embedded systems to efficiently manage voltage regulation, power switching, and monitoring, often consolidating these functions onto a single chip to reduce component count and board space.

Many specific chips are also mentioned.

But if you want to use your circuit, you just need to move the 1K pulldown resistor over to the 5V input:

And yes, the mosfet is oriented correctly.

Edit: The pulldown resistor should be 10K, or possibly higher, not 1K.

yes

If you plan on using the ESP32 with WiFi, then you won't find an LDO that will work unless you test many different ICs and find one that works under load.

Right, i am going with this circuit

But your ESP need 3.3V. You will destroy it with 5V



Is this Mosfet okay? i have check vgsth which is good
ID= 2Amp it is okay
VGs=+-12v it is okay

before ESP32 LDO is attached to convert it to 3.3V

And what's the dropout voltage of that LDO (at >200mA)?

Almost every LDO you find needs an input voltage of at least Vout +1.0V in order to stay in regulation, so Vin to the regulator need to be 4.3V


From datasheet of my selected LDO ,In recommended operating condition input voltage is 2.5v to 16v

Voltage Dropout 1.4V@(1A)

And how that matches with your battery voltage when at nominal or below (3.0-3.7V) compared to Esp32 minimum supply voltage?

How do you get 3.3V out if the input is only 2.5V.

So the input need to be at least 3.3+1.4 = 4.7V,
See a problem?

in my POV 1.4V dropout mean if we want to get 3.3v we have to apply at least 4.7Vbut i don't know if input voltage is below the fixed output voltage (3.3V) .let say 3v ii think it would give 3v at output not 1.6V.If the voltage is above 4.7V like 5v,10,v,16v it will cut it to 3.3V if voltage is below 4.7V it give will output same as it get in input

Even if it could work with a 3V input, It is not posstble to get 3V out.

What are the test conditions for all of the parameters listed in the datasheet?

Under what conditions does it stay in regulation?