A lot of "flaky" ESP32 projects aren't flaky because of the code. The board resets when Wi-Fi connects, a relay clicks and the log stops, or a battery sensor dies after two weeks instead of two months. Each of these usually comes down to power: a supply that can't deliver the current peaks, a regulator that doesn't fit the input voltage, or a pin that was never meant to be fed from outside.
This guide goes through the options in the order you usually meet them, from a USB cable on the desk to a battery and a mains module in a finished device. The numbers come from Espressif's ESP32 datasheet (v5.3), the ESP32 hardware design guidelines and the datasheets of the parts mentioned.
What the chip actually needs
The ESP32 is a 3.3 V chip. The datasheet gives a recommended supply range of 3.0 to 3.6 V, with 3.3 V typical, and an absolute maximum of 3.6 V on the supply pins. The same document asks for an external supply that can deliver at least 0.5 A.
That 0.5 A figure looks oversized next to the average current, but the average isn't the problem. The datasheet lists typical current while transmitting at around 240 mA for 802.11b at +19.5 dBm and around 180-190 mA for 802.11g and 802.11n. Receiving takes roughly 95-100 mA. Deep sleep is around 10 µA. The chip jumps between these states in milliseconds, and the transmit bursts are what pull the rail down.
Espressif's schematic checklist says it directly: current surges during transmission can make the supply rail collapse, and it highly recommends a 10 µF capacitor on the 3.3 V rail, plus 0.1 µF capacitors close to the digital supply pins. If you build on a bare module rather than a development board, those capacitors are your job.
The I/O pins are 3.3 V too. The datasheet's maximum high-level input voltage is VDD + 0.3 V, so with a 3.3 V supply that's 3.6 V. A 5 V signal from a sensor or an Arduino Uno exceeds it. Use a level shifter or a voltage divider.
Option 1: USB
On a development board, USB is the easiest and safest option. The board's own regulator turns 5 V into 3.3 V, and the USB connector is where you also flash and read logs.
The weak points sit outside the board:
- The cable. Long, thin, cheap cables drop voltage under load. When the ESP32 starts transmitting, the board may see noticeably less than 5 V at the connector, and the regulator has less headroom.
- The port or charger. A computer's USB 2.0 port is only required to supply 500 mA. That's enough for the ESP32 itself, but not for an ESP32 plus a relay module, a servo, an LED strip or a 4G modem powered from the same board.
- Peripherals hanging off the board. Everything you power from the board's 5V or 3V3 pin shares the same cable and the same regulator.
If a project works on a laptop but resets on a phone charger (or the other way round), try another cable first. It's the cheapest test you can do.
Option 2: the 5V pin
The 5V (sometimes labeled VIN) pin lets you feed the board from an external 5 V supply, such as a USB power supply wired directly or a 5 V rail that already powers other parts. The on-board regulator still does the conversion to 3.3 V.
Espressif's ESP32-DevKitC V4 user guide lists three power options: the Micro USB port, the 5V and GND pins, and the 3V3 and GND pins. They are mutually exclusive. The guide says to use one and only one, otherwise the board and/or the power supply may be damaged. In practice this means: don't feed the 5V pin from an external supply while the USB cable is connected to your computer, unless you have checked the schematic of your exact board and it has a diode or switch that separates the two. Many clone boards don't document this at all.
When you need USB for logs while the board runs from an external supply, a common solution is a USB cable or adapter with the power line cut, or a USB-UART adapter connected only with TX, RX and GND.
Option 3: the 3V3 pin
Feeding 3.3 V directly into the 3V3 pin bypasses the board's regulator. That's useful when you already have a good 3.3 V supply, or when the board's regulator is the weak link (more on that below). It's also the riskiest option:
- There's no regulator to absorb mistakes. Anything above 3.6 V is outside the absolute maximum rating.
- Your 3.3 V supply has to handle the transmit peaks by itself, so it needs to be rated for at least the 500 mA that Espressif asks for.
- The same "one and only one" rule applies: don't connect USB while the 3V3 pin is fed from outside.
Regulators: dropout and quiescent current
Most ESP32 boards use a linear regulator (LDO) to make 3.3 V from 5 V. Two parameters decide whether it fits your project.
Dropout voltage is the minimum difference between input and output for the regulator to keep its output in regulation. The AMS1117, found on many cheap boards, has a typical dropout of 1.1 V and a maximum of 1.3 V at its full 800 mA output, decreasing at lower currents. To get a clean 3.3 V at high current, it needs around 4.4-4.6 V at its input. From a 5 V USB supply that's fine. From a single lithium-ion cell, it isn't.
The AP2112, a common low-dropout alternative, has a typical dropout of 250 mV at 600 mA for the 3.3 V version. It can keep 3.3 V from a much lower input voltage.
Quiescent current is what the regulator draws itself. The AMS1117 datasheet gives 5 mA typical and 10 mA maximum. The AP2112 gives 55 µA typical. The ESP32 in deep sleep takes around 10 µA.
Do the arithmetic for a battery sensor: 5 mA continuous from the regulator alone empties a 2000 mAh battery in 400 hours, which is under 17 days, no matter how little the ESP32 itself draws. With an AP2112, the regulator's own share drops by about two orders of magnitude, and the rest of the board (USB-UART chip, power LED, voltage dividers) becomes the next thing to measure.
Batteries
The most common choice is a single lithium-ion or lithium-polymer cell. Battery University gives 4.20 V per cell as the typical full-charge voltage for common cobalt-blended Li-ion chemistries, and 3.60 V as the nominal voltage. A full cell is already above the ESP32's 3.6 V maximum, so it can't go straight to the 3V3 pin. You need a regulator with low dropout, and you should accept that the last part of the battery's capacity sits below the voltage where the regulator can still hold 3.3 V.
LiFePO4 cells look tempting because their nominal voltage is 3.2 V. Battery University gives 3.65 V as their charging voltage, which is just above the ESP32's 3.6 V absolute maximum. Connecting one directly to the 3V3 pin while it's on the charger leaves no margin.
Some practical rules:
- Use a cell with a protection circuit, or a charger board that includes protection, and a charger designed for the chemistry you use.
- Measure the whole board's sleep current with a multimeter, not only the chip's. Development boards are built for the desk, not for batteries.
- Espressif's checklist recommends a supply supervisor (a voltage monitor chip) on the chip enable pin when the supply rises slowly, such as during battery charging, when power is switched on and off often, or when the source is unstable, such as a solar panel. Without it, the chip may start in an undefined state while the voltage is still too low.
Mains-powered modules
For a device that lives behind a wall switch or inside a junction box, the usual choice is a small AC-DC module. The Hi-Link HLK-PM01, for example, is rated for 100-240 V AC input and 5 V at 600 mA output (3 W). Its datasheet recommends an external 1 A/250 V AC slow-blow fuse or a 10 Ω wirewound resistor on the input.
Two practical notes the datasheet doesn't cover. First, 600 mA at 5 V is enough for an ESP32 and a small relay module, but not for LED strips or motors. Second, anything connected to mains needs a proper enclosure, proper spacing between the mains and low-voltage sides of the board, and a qualified electrician for the installation. If you're unsure, use a certified 5 V USB power supply in a socket instead. It's less elegant but much harder to get wrong.
Brownouts: what the reset tells you
The ESP32 has a built-in brownout detector, enabled by default. When the supply voltage drops below a safe level, it resets the chip and prints this to the serial log:
Brownout detector was triggered
ESP-IDF's documentation notes that if the voltage falls fast, only part of the message may appear. The detector can be configured or disabled with the CONFIG_ESP_BROWNOUT_DET and CONFIG_ESP_BROWNOUT_DET_LVL_SEL options.
Disabling it to "fix" resets is a bad trade. The detector didn't cause the problem, it reported it. With it disabled, the chip keeps running on a voltage it wasn't designed for, which can corrupt a flash write or leave peripherals in a strange state. Treat the message as a symptom and find the cause:
- Swap the USB cable and power supply for known-good ones.
- Check whether the reset happens exactly when Wi-Fi connects or when a relay or motor switches. That points to current peaks.
- Disconnect the peripherals one by one. A relay coil, servo or LED strip powered from the board's pins is a frequent culprit; give it its own supply with a shared ground.
- Check the capacitors on a custom board: 10 µF on the 3.3 V rail and 0.1 µF near the supply pins, as Espressif recommends. A larger electrolytic capacitor near the module can help with peaks, but it won't save a supply that is simply too weak.
- Measure the voltage at the 3V3 pin under load, not at the power supply output.
Common mistakes
- USB and an external supply at the same time. The DevKitC guide explicitly warns that this can damage the board or the supply.
- A 5 V sensor output on a GPIO. The input limit is 3.6 V at a 3.3 V supply. Use a divider or level shifter.
- A Li-ion cell straight into the 3V3 pin. 4.2 V is above the absolute maximum.
- An AMS1117 board for a battery sensor. The regulator alone draws milliamps and needs over 4 V at its input to regulate at high current.
- Powering relays, servos and LED strips from the board. They need their own supply. Connect only the grounds together.
- Disabling the brownout detector. It hides the problem instead of fixing it.