Power supplies: an important part of each project

In physical computing, many “my code does not work” problems are power problems. For example, the board resets when a motor starts, a servo jitters, LEDs flicker, or a regulator becomes too hot to touch. This page tells you where an ESP32 gets its power and how much current each part needs. It also tells you how to choose a supply or a battery. Last, it gives the few rules that keep everything stable. The most important rule is common ground.

Power budget calculator

DeviceRailQtyTypicalPeak

The current values are typical values for common modules. Read the datasheets of your parts. “Peak” is the short burst of current when Wi-Fi transmits, a servo starts, or a motor stalls. Choose a supply that can give the peak current.

How an ESP32 DevKit gets power

The ESP32 chip operates on 3.3 V. A DevKit board receives 5 V from USB or from the 5V/VIN pin. A small linear regulator changes the 5 V to 3.3 V. This regulator is frequently an AMS1117-3.3. All current from the 3V3 pin goes through that regulator.

ESP32 DevKit USB 5 V diode* 5V / VIN pin AMS1117 3.3 V LDO 3V3 pin ESP32 chip (3.3 V) GND pin heat = (5 − 3.3) V × I
*Many DevKits have a diode between USB and the 5V pin. The diode stops current from a supply on the 5V pin to your laptop. Some boards do not have this diode. Before you connect USB and an external 5 V supply at the same time, examine the schematic of your board.

DevKit power pins

PinWhat it isUse it for
5V / VINUSB 5 V (after the diode), or an input for an external ~5 V supplySupply power to the board without USB. Supply power to small 5 V modules (PIR, a few LEDs).
3V3The output of the on-board regulatorSensors and displays: OLED, IMU, small modules. The total budget is approximately a few hundred mA.
GNDThe 0 V reference for all partsConnect to the GND of all other supplies in the project.
ENEnable / reset (pulled high)Pull LOW to reset the chip. This is not a power pin.
Do not apply 5 V or more to the 3V3 pin. Do not supply motors, servos or LED strips from the 3V3 pin. The AMS1117 has a maximum rating of approximately 1 A. In real use, heat decreases this limit much more.

Where the power comes from

USB ports & chargers

  • USB 2.0 port: 500 mA at 5 V.
  • USB 3.x port: 900 mA.
  • USB-C: 1.5 A or 3 A at 5 V if the port signals this capability. If not, it gives the same 500/900 mA as USB 2.0/3.x.
  • Phone chargers usually give 1–3 A. Low-cost chargers have much noise, and their voltage decreases under load.
  • USB hubs and long, thin cables decrease the voltage. If the board resets, use a short cable of good quality.

Wall adapters & bench supplies

  • Barrel-jack adapters (5 V, 9 V, 12 V) have a maximum current rating. Choose an adapter with a rating more than your peak current.
  • A 12 V adapter can supply motors directly. A buck converter can then decrease the 12 V to 5 V for the ESP32.
  • A bench supply with a current limit is the safest method to test a new circuit. Set the limit low at the start.

Batteries

TypeVoltageNotes
4 × AA alkaline6.0→4 VEasy and safe. The voltage decreases as they discharge.
4 × AA NiMH4.8 VRechargeable. Good for servos.
18650 Li-ion4.2→3.0 VNeeds a protection board and a charger.
LiPo 1S/2S/3S3.7/7.4/11.1 VHigh current (C-rating). Be careful.
USB power bank5 VCan stop automatically at low current.

Battery capacity & C-rating

mAh tells you how long the battery operates. In theory, 2000 mAh ≈ 2 A for 1 hour or 200 mA for 10 hours. C-rating tells you how fast a LiPo can safely supply this charge. The maximum current ≈ C × capacity, so a 1000 mAh 20C pack can give approximately 20 A. Motors and ESCs need high-C packs. A sensor project operates correctly on a low-C pack.

Power banks that stop automatically

Many power banks stop when the current decreases to less than approximately 50–100 mA. At this current, the power bank thinks that the phone is full. An ESP32 in light sleep uses less current than that, so the power bank stops. To prevent this problem, choose a power bank with an “always on” / low-current mode. Alternatively, make the project use a short burst of current at regular intervals.

Linear regulator and buck converter

A linear regulator (LDO), for example the AMS1117, changes the extra voltage into heat: P = (Vin − Vout) × I. A buck converter (LM2596, MP1584, and many small modules) switches very quickly. It loses only approximately 10–20% of the power, for all voltage drops. Move the sliders to compare the two.

A typical multi-rail project

Battery 2S LiPo 7.4 V fuse switch Motor driver VM = 7.4 V M Buck → 5 V MP1584 / LM2596 servos ESP32 5V/VIN · GND PWM / DIR one common ground for all parts
One battery supplies three rails. The battery voltage supplies the motors. A buck converter supplies the 5 V loads and the ESP32. The regulator of the ESP32 supplies the 3.3 V sensors. All grounds connect together.

How to build it, step by step

  1. List all loadsUse the calculator above. Write down the typical current and the peak current of each rail.
  2. Choose the supplyIts voltage must be correct for the highest-voltage rail (frequently the motors). Its current must be equal to the sum of the peaks plus ~25%.
  3. Add a fuse and a switchPut them immediately at the + terminal of the battery. Then, if a short circuit occurs, the fuse blows before the wires become too hot.
  4. Adjust the buck converter before you connect a loadAdjustable modules come from the factory at random voltages. Measure the output with a multimeter. Turn the trim pot until the multimeter shows 5.0 V.
  5. Connect all groundsConnect battery −, driver GND, buck GND and ESP32 GND together. If possible, connect them at one point.
  6. Add capacitorsPut 100–1000 µF bulk caps near motor drivers and servos. Keep the 0.1 µF ceramic caps that are already adjacent to each chip.
  7. Test in stagesDisconnect the motors and energize the circuit. Measure the voltages. Then add one load at a time.

The rules that prevent most problems

1 · Common ground

A signal voltage has a meaning only when you measure it from a ground. Make sure that the ground of the servo supply connects to the ground of the ESP32. If not, the servo cannot read the pulse correctly. The servo then jitters or does not move. Connect the grounds of all supplies together. Keep only the + sides separate.

2 · Decoupling capacitors and bulk capacitors

0.1 µF ceramic caps are installed immediately at the power pins of each chip. They filter fast, high-frequency noise. 100–2200 µF electrolytic caps are installed where large loads connect (servos, motors, LED strips). They supply short current surges. Electrolytic caps are polarized. Connect the stripe to GND. Use a cap with a voltage rating more than the rail voltage (for example, 10 V or more for 5 V).

3 · Brownouts

If the supply voltage decreases for a short time, the brownout detector of the ESP32 resets the chip. A motor start or a Wi-Fi transmission can cause this. The Serial Monitor then shows Brownout detector was triggered. To correct the problem, make the supply stronger. Use a stronger source, shorter and thicker wires, bulk caps, and a separate motor supply. Do not disable the detector. It tells you about a real problem.

4 · Wire size

WireApproximate limit (short wires)
Breadboard jumper (26–28 AWG)≲ 1 A
Breadboard power rail≲ 1 A
22 AWG hookup wire≈ 1–2 A
18 AWG≈ 3–5 A
14–16 AWG (silicone)≈ 10–20 A (ESCs)

These values are only general rules. Longer wires and wires in bundles need a thicker gauge. If a wire becomes warm, use a thicker wire.

5 · Fuses & reverse polarity

  • Install a fuse on each battery. A LiPo can supply tens of amps into a short circuit.
  • Do not connect a battery with the wrong polarity. This can immediately damage all chips. Use keyed connectors (JST, XT30/XT60).
  • For protection, use a series Schottky diode (simple, loses ~0.3–0.5 V). Alternatively, use a P-MOSFET “ideal diode” (almost no loss; refer to MOSFETs).

6 · One source per rail

Do not connect two supplies to the same rail at the same time, unless diodes keep them apart. An example is USB plus a bench supply on the 5V pin. The supply with the higher voltage pushes current into the other supply. This can damage a laptop port or a battery. Sometimes you need USB for programming while the project operates on its own supply. In this condition, keep the supplies separate and connect only the grounds.

Code: find power problems with software

Find the cause of a board reset

reset_reason.ino


              #include <esp_system.h>

              void setup() {
                Serial.begin(115200);
                delay(500);
                esp_reset_reason_t r = esp_reset_reason();
                Serial.printf("Reset reason: %d\n", r);
                if (r == ESP_RST_BROWNOUT) {
                  Serial.println("Brownout. The supply voltage decreased. Examine the power supply.");
                } else if (r == ESP_RST_POWERON) {
                  Serial.println("Normal power-on.");
                } else if (r == ESP_RST_PANIC) {
                  Serial.println("Crash (software panic).");
                }
              }

              void loop() {}
            

Measure a battery with a voltage divider

The voltage of a 2S LiPo (up to 8.4 V) is too high for the ADC (maximum usable input ~3.1 V). Divide the voltage by 3 with 20 kΩ (top) + 10 kΩ (bottom). Connect the divider output to GPIO 34.

battery_voltage.ino


              const int BATT_PIN = 34;            // ADC1 pin, operates when Wi-Fi is on
              const float DIVIDER = (20.0 + 10.0) / 10.0;   // = 3.0

              void setup() {
                Serial.begin(115200);
                analogSetPinAttenuation(BATT_PIN, ADC_11db);  // full ~0–3.1 V range
              }

              void loop() {
                uint32_t mv = 0;
                for (int i = 0; i < 16; i++) mv += analogReadMilliVolts(BATT_PIN);
                float vBatt = (mv / 16.0) * DIVIDER / 1000.0;
                Serial.printf("Battery: %.2f V\n", vBatt);
                if (vBatt < 6.6) Serial.println("Low. Charge the battery now (2S LiPo minimum ~6.6 V, 3.3 V/cell)");
                delay(1000);
              }
            

Troubleshooting

The board resets when a motor or servo starts

This is a brownout. Give the motors their own supply. Add bulk capacitors. Connect only the grounds. Make the power wires shorter.

The board operates on USB, but not on a battery

The battery voltage is possibly too low for the regulator. An AMS1117 needs an input of approximately 4.4 V or more to make a stable 3.3 V. Alternatively, a power bank stops automatically. Measure the voltage at the board when the problem occurs.

The regulator is very hot

The current from 3V3 is too high, or the voltage on VIN is too high. Move the large loads to their own 5 V buck converter. Keep VIN at approximately 5 V.

LiPo safety: Charge the battery only with a correct balance charger. Do not leave a battery unattended while it charges. Do not use swollen or damaged packs. Do not short the leads. Keep and charge the battery in a fire-resistant bag. Stop the discharge at approximately 3.3 V per cell. Use a low-voltage alarm, or monitor the voltage in code as in the battery sketch above.

Resources