← How-Tos
electronics 5 days ago ◑ 6 views ◯ 6 min read

Choosing and Wiring Load-Switch Power-Gating MOSFETs for Battery-Powered ESP32 Projects

load switchpower gatingmosfetesp32deep sleepbatterylow powerp-channelhigh-side switch

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.

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.

Wiring It to the ESP32

  1. 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.
  2. 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.
  3. Take your sensor reading or complete your SD write.
  4. 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:

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.