Choosing and Wiring Load-Switch Power-Gating MOSFETs for Battery-Powered ESP32 Projects
ESP32 deep sleep gets a battery-powered sensor node down into the microamp range, but deep sleep only turns off the ESP32 itself. Every peripheral still wired to the battery rail — a sensor module, an SD card, a display, an external ADC — keeps drawing its own quiescent current the entire time the ESP32 is asleep, and for a lot of cheap breakout boards that quiescent draw is tens to hundreds of microamps per board, which adds up to dominate a project's total power budget far more than the ESP32's own sleep current does. A load switch — a MOSFET (or a purpose-built load-switch IC) wired to physically disconnect a peripheral's power rail whenever it isn't needed — is how you actually get those peripherals' current draw to zero between measurements, instead of just the processor's.
Why This Matters More Than It Looks Like It Should
Consider a typical battery sensor node: an ESP32 in deep sleep draws roughly 10–150µA depending on which peripherals inside the chip stay powered (RTC memory, ULP coprocessor, etc.). A cheap BME280 breakout board, left powered the whole time, can draw anywhere from a few microamps (if its onboard regulator is efficient and the sensor itself sleeps) to tens of microamps just sitting there doing nothing useful. An SD card holder with a card inserted can draw hundreds of microamps to a few milliamps even when idle. None of that is doing any work between wake cycles — it's pure waste, and on a project sleeping 99% of the time and waking briefly to sample, that idle peripheral draw is frequently the single largest term in the whole power budget, bigger than the ESP32's own sleep current and bigger than the brief active-sampling current.
A load switch fixes this by physically breaking the power rail to that peripheral except during the brief window when it's actually being read.
Two Ways to Build a Load Switch
Discrete P-Channel MOSFET, High-Side
The classic approach: a P-channel MOSFET sits between the battery rail and the peripheral's VCC pin, with its gate pulled high (off) through a resistor and driven low by a GPIO pin (through an NPN transistor or a direct connection, depending on the ESP32's GPIO voltage versus the MOSFET's gate threshold) to turn the peripheral on.
- Why P-channel for high-side: an N-channel MOSFET switching the high side needs its gate driven above the source voltage to turn on fully, which means above the battery rail — awkward without a charge pump. A P-channel device turns on with its gate pulled low relative to its source (the battery rail), which a simple GPIO-driven pulldown can do directly.
- Common parts: AO3401, DMG2305U, and similar small-signal P-channel MOSFETs in SOT-23 packages are inexpensive, widely available, and handle the modest currents (tens to a few hundred mA) most sensor peripherals draw.
- Gate resistor sizing: a pull-up resistor from gate to source (100kΩ is typical) ensures the MOSFET defaults to off if the GPIO is floating or the ESP32 is mid-boot, and a series gate resistor (1–10kΩ) limits inrush current into the gate capacitance when switching.
- Bulk capacitance on the peripheral side: if the peripheral has its own bulk capacitor on VCC, that capacitor has to charge through the MOSFET every time you turn the rail on, which draws a brief inrush spike and adds a small settling delay before the peripheral's supply is stable — budget a few milliseconds after power-on before trying to communicate with it.
Dedicated Load-Switch ICs
Parts like the TPS22918, AP2281, or similar integrated load switches package the MOSFET, a controlled turn-on ramp (to limit inrush current), and often a quick-output-discharge feature into a single small IC, controlled by a simple logic-level enable pin directly from a GPIO — no discrete gate-drive resistor network to get wrong.
- Controlled slew rate: unlike a bare MOSFET switching on instantly, these ICs ramp the output voltage up over a controlled time (often in the microsecond-to-millisecond range), which reduces the inrush current spike into downstream bulk capacitance — useful if your battery or a supercapacitor-backed supply can't tolerate a hard inrush without sagging.
- Reverse current protection: some parts block current from flowing backward from the peripheral into the switched rail if the peripheral has its own power source or a charged capacitor, which a simple discrete MOSFET's body diode will not do on its own.
- When to choose this over discrete: for a one-off breadboard prototype, a discrete MOSFET is cheaper and easier to source from a generic parts bin. For a design you're actually going to deploy in the field, the predictable turn-on behavior and smaller footprint of an integrated load switch is worth the few extra cents per unit.
Wiring It to the ESP32
- Pick a GPIO that's safe to leave in a known state through boot and deep sleep — several ESP32 GPIOs have specific boot-strapping behavior (GPIO0, GPIO2, GPIO12, GPIO15 among them) and are poor choices for a power-gate control line since an unexpected level during boot can affect flash mode or cause unintended power-up. Stick to a general-purpose GPIO without special boot roles.
- Drive that GPIO high before you need the peripheral, with enough settle time after power-up for the peripheral's own regulator and any bulk capacitance to stabilize — check the peripheral's datasheet for a power-on-to-ready delay spec; if none is given, a few milliseconds is a reasonable starting point to verify empirically with a logic analyzer or scope.
- Take your sensor reading or complete your SD write.
- Drive the GPIO low to cut power, then enter deep sleep. Remember that deep sleep resets most GPIO states on some ESP32 variants unless you explicitly hold the pin state with
gpio_hold_en()— check this for your specific board, since an unintended float-high on wake can leave the load switch on the whole time you thought you'd cut it.
What Not to Power-Gate
Not every peripheral is a good candidate for hard power cycling:
- Real-time clocks with onboard crystals that need continuous power to keep time accurate should stay on their own always-on supply path, separate from the gated rail, or use their dedicated battery backup pin instead.
- Devices with slow or unreliable cold-start behavior — some GPS modules take tens of seconds to get a fix from a cold power-up versus a warm start with retained almanac data, which can make full power-gating a net loss versus a lower-power standby mode the device offers natively.
- Flash-based storage mid-write — never cut power to an SD card or external flash chip while a write is in progress; always confirm the write/sync has completed before gating that rail off.
Measuring Whether It Actually Worked
The only way to know a power-gating design is actually saving the current you think it is: measure it. A cheap USB power meter won't have the resolution for microamp-level sleep currents; this is a case for an inline multimeter in µA range, or better, a dedicated low-power current profiler (several open-source and commercial options exist specifically for measuring microcontroller sleep currents across many decades of range). Measure total system current with the peripheral gated off and compare against the same peripheral left powered — the difference tells you whether the added MOSFET and its own leakage current were worth the extra board complexity, which for most cheap sensor breakouts, they emphatically are.