Français

Lessons · Lesson E4 · Electricity basics · 20 min

Power: batteries, 3.3 V and 5 V

Choose a battery pack, estimate how long it lasts, join the grounds, and feed an ESP32 board the right voltage on the right pin. About 20 minutes, with a battery-life calculator.

Cells, packs and voltage

A cell is one battery in the everyday sense: the AA you drop in a remote. A pack is several cells hooked in a row, nose to tail, so that their voltages add up. Electronics people call this connecting cells in series [2].

Two kinds of AA and AAA cells are worth knowing [1]:

Type Voltage per cell (nominal) Rechargeable?
Alkaline 1.5 V No
NiMH 1.2 V Yes

“Nominal” means the typical value printed on the label. The real voltage drifts down as the cell empties [1].

Add them up and you get your pack:

Pack Alkaline NiMH
2 cells 3.0 V 2.4 V
3 cells 4.5 V 3.6 V
4 cells 6.0 V 4.8 V

A 4-cell NiMH pack gives 4.8 V, enough to run most 5 V systems, with the voltage sagging as it empties [1]. The cell’s physical size does not change its voltage. It changes how much current the cell can deliver, because bigger cells have less internal resistance [2].

Never recharge an alkaline cell. Disposable (“primary”) cells cannot be recharged reliably or safely [1]. An alkaline cell connected incorrectly can get hot [1]: if a cell or a holder feels warm, disconnect everything and find out why before you go on.

Never let the pack’s two wires touch. That is a short circuit: the cells push a large current, and wires and cells get hot. Use a holder with an on/off switch, keep it off while you wire, and connect red (+) to 5V and black (−) to GND, never the other way round.

Cells in series: the voltages add up Two battery holders, each with four AA cells in a row, nose to tail: the plus end of one cell touches the minus end of the next. The pack's minus terminal is at the left end, its plus terminal at the right end. Top, alkaline cells of 1.5 volts each: 1.5 + 1.5 + 1.5 + 1.5 = 6.0 volts. Bottom, rechargeable NiMH cells of 1.2 volts each: the same row gives 4.8 volts. In series the voltages add, but the capacity in milliamp-hours stays that of one cell. Values are nominal: the real voltage falls as the cells empty. FIG. 1 — CELLS IN SERIESAlkaline AA · 1.5 V per cell+−AA1.5 V+−AA1.5 V++−AA1.5 V++−AA1.5 V+1.5 + 1.5 + 1.5 + 1.5 =6.0 VNiMH AA (rechargeable) · 1.2 V per cell+−AA1.2 V+−AA1.2 V++−AA1.2 V++−AA1.2 V+1.2 + 1.2 + 1.2 + 1.2 =4.8 VSeries adds the voltages, not the capacity: still one cell's mAh.Nominal values: the real voltage falls as the cells empty.
Tap the diagram to open it full screen.

How long will it last?

Batteries are rated in milliamp-hours (mAh). One cell rated 2,000 mAh could, on paper, deliver 2,000 mA for one hour, or 200 mA for ten hours, or 20 mA for a hundred hours [3]. Hence the formula:

time (h) = capacity (mAh) ÷ current (mA)

Two things to keep in mind:

  • Series adds voltage, not capacity. A pack of four 2,000 mAh cells in series is a 2,000 mAh pack [4]. To get more hours, you need bigger cells, or less current drawn.
  • The formula is an upper estimate. Real batteries do not follow it exactly. The rating is only trustworthy close to the current the maker used to measure it [3]. At very high currents the cell wastes more as heat; at very low currents, ageing and slow leakage can drain it before the formula says so [3].

So we add a margin. Our rule of thumb (not a standard): count on about two thirds of the paper figure. One more reason with alkaline cells: their range goes down to about 0.8 V per cell when dead, and a typical AA is about 3,000 mAh [12], but our board stops working near 1.1 V per cell (4.4 V for 4 cells, screen 5), so part of that charge is never used.

Worked example. Suppose your build draws 50 mA (an ESP32 with Wi-Fi on often draws more: measure yours), and your pack is made of cells rated 2,500 mAh (the rating of one NiMH AA cell in SparkFun’s shop [1]; read the number on your own cells).

  1. On paper: 2,500 ÷ 50 = 50 hours
  2. With our margin: 50 × ⅔ ≈ 33 hours, a bit under a day and a half

What is my build’s current? Two ways: read the datasheet of every part and add the figures up, or measure it with your multimeter’s current range, following its manual. A rough figure typed into the calculator is fine, as long as you treat the answer as typ. (typical), not guaranteed.

Capacity and current: the tank and the tap A water picture of battery life, three panels. 1, the tank is the capacity in milliamp-hours, here 2000 milliamp-hours. 2, the tap is the current your build draws, in milliamps. Panel A: the same tank with a small tap, 20 milliamps, lasts about 100 hours on paper. Panel B: the same tank with a wide tap, 200 milliamps, lasts about 10 hours. Time equals capacity divided by current. Panel C: cells in series are like the same tank placed higher up: 3, the height is the push, the voltage, which adds up cell after cell, but the amount of water, the capacity, is still one tank's worth. Real batteries give less than the paper figure. FIG. 2 — THE TANK (mAh) AND THE TAP (mA)A · Small tap2000 mAh20 mAlong time2000 ÷ 20 = 100 h(on paper)B · Wide tap2000 mAh200 mAshort time2000 ÷ 200 = 10 h(on paper)122C · Seriessame tank,more push (V)2000 mAh1.5 V1.5 V1.5 V1.5 V34 cells: 6.0 Vstill 2000 mAh1tank = capacity (mAh)2tap = current (mA)3height = voltage (V)time (h) = capacity (mAh) ÷ current (mA)An upper estimate: count on about two thirds (our rule of thumb).
Tap the diagram to open it full screen.

Pick a cell type, a number of cells, the capacity printed on your cells and the current of your build. The calculator shows the pack voltage, the paper estimate and the estimate with margin. Every result carries a “typ.” warning.

Battery-life calculator
Capacity and current: the tank and the tap A water picture of battery life, three panels. 1, the tank is the capacity in milliamp-hours, here 2000 milliamp-hours. 2, the tap is the current your build draws, in milliamps. Panel A: the same tank with a small tap, 20 milliamps, lasts about 100 hours on paper. Panel B: the same tank with a wide tap, 200 milliamps, lasts about 10 hours. Time equals capacity divided by current. Panel C: cells in series are like the same tank placed higher up: 3, the height is the push, the voltage, which adds up cell after cell, but the amount of water, the capacity, is still one tank's worth. Real batteries give less than the paper figure. FIG. 2 — THE TANK (mAh) AND THE TAP (mA)A · Small tap2000 mAh20 mAlong time2000 ÷ 20 = 100 h(on paper)B · Wide tap2000 mAh200 mAshort time2000 ÷ 200 = 10 h(on paper)122C · Seriessame tank,more push (V)2000 mAh1.5 V1.5 V1.5 V1.5 V34 cells: 6.0 Vstill 2000 mAh1tank = capacity (mAh)2tap = current (mA)3height = voltage (V)time (h) = capacity (mAh) ÷ current (mA)An upper estimate: count on about two thirds (our rule of thumb).
Tap the diagram to open it full screen.

Rules for packs: never mix, no LiPo

Never mix cells in one pack. Our rule, for three reasons:

  • Old with new. In a series pack, the same current passes through every cell. Cells with different capacities empty at different times, so the weakest one runs out first and spoils the whole pack [4]. Change all the cells at once.
  • Alkaline with NiMH. They start from different voltages (1.5 V against 1.2 V [1]), so they do not drain together.
  • Different brands, sizes or capacities. Same reason as the first one: every cell in a series pack should have the same rating [4].

Keep one type and one brand in each holder, and note the date you put them in.

Why no LiPo here. Rechargeable lithium-polymer cells are compact, but they sit at 3.7 V [1] and overcharging harms them, so they need a proper charger [1]. Adafruit’s own advice for beginners is to start with alkaline AA cells, and to move to NiMH if you want to recharge [10]. We follow it: Tinker Mission builds use AA or AAA cells only.

One power source at a time. If a board has several ways to receive power (USB, a pin), connect one only [8]. We will come back to this with the ESP32 board on screen 5.


Why every ground joins

A voltage is never “at one point”. It is a difference between two points: your 3.3 V is 3.3 V above something [5]. That “something” is the zero, the ground (GND).

Now picture two parts, each with its own battery: a sensor on its pack, and your ESP32 board on another. A signal wire runs from the sensor to the board. The board reads the signal against its own zero. If nothing ties the two zeros together, they float apart, and “3.3 V” on the wire means nothing for the board. Its readings jump around.

The fix is one extra wire: GND of the first side to GND of the second side [6]. Now both measure from the same zero. The wire also gives the signal’s current a way back, which closes the loop (lesson E2).

Rule of thumb, from a guide on powering LED strips from several supplies [6]:

  • Grounds: join them all.
  • Positive wires of different supplies: do not join them. Each supply feeds its own parts. Supplies are never exactly equal, and joining the positives lets one push current into another [6].

This is why, later on, a motor on its own battery and a board on its own battery will share one GND wire.

Why every ground joins Two copies of the same set-up: a sensor powered by its own battery, an ESP32 board powered by another battery, and a signal wire from the sensor's OUT pin to a GPIO pin of the board. A voltage is always measured between two points. Left, panel A: the two grounds are not connected. Each side has its own zero, drawn at a different height, with a question mark between them: the board cannot know what the signal's voltage means, and its readings jump around. Right, panel B: one extra wire joins the GND of the sensor side to the GND of the board side. Both zeros are now at the same level and the signal can be read. The rule: join all the grounds, but never join the plus wires of different supplies. FIG. 3 — WHY EVERY GROUND JOINSA · No shared groundsensorGND+OUTESP32 boardGPIO5VGNDsignal0 V (sensor)0 V (board)??two zeros: readings jumpB · Grounds joinedsensorGND+OUTESP32 boardGPIO5VGNDsignalextra GND wireone shared 0 V: readableGrounds: join them all.+ of different supplies: never join them.A voltage is always measured between two points: the board needs the same zero as the sensor.
Tap the diagram to open it full screen.

Why ESP32 pins are 3.3 V, and the two power pins

The chip is a 3.3 V chip. It is meant to run on 3.3 V, and its supply must never go above 3.6 V [7]. The datasheet limits the voltage allowed on its pins: a signal that is HIGH must stay below the chip’s supply plus 0.3 V, which is 3.6 V when it runs on 3.3 V [7]. So never connect a 5 V signal to an ESP32 pin. This is the one hard limit to remember for signals. (Many modules in the maker world use 3.3 V or 5 V logic [11]: check which one before wiring.)

The board has two power pins that look alike. On the ESP32-DevKitC V4, which we use:

  • 5V pin. It feeds a small regulator chip, the AMS1117-3.3 on the original board, which turns a higher voltage into a steady 3.3 V [9]. It is one of the board’s three power inputs [8], and the one we use for a battery pack. (The USB port is a separate way in: see “One source only” below.)
  • 3V3 pin. This is the board’s 3.3 V line itself. We use it to feed small parts such as a sensor. Do not feed it from a pack: a pack of 4 AA cells (about 6 V) is far above the 3.6 V limit [7].

On the 5V pin, the pack must stay in a window. Our working figures: roughly 4.4 V to 6.5 V (to confirm by measuring your own pack).

  • Below about 4.4 V, the regulator no longer has enough room above 3.3 V and the board misbehaves. Change the cells.
  • Above about 6.5 V, the board’s input capacitor is only rated 10 V [9], and we keep a margin. Fresh alkaline cells read up to about 1.6 V each [12], so 4 give about 6.4 V: fine. Never 5 or 6 cells.
  • Clone boards can differ. Read the small 3-legged chip with a big tab near the 5V pin: if it does not say AMS1117, use 4 NiMH cells only. Measure the pack with a multimeter before connecting it: the voltage, and which wire is + (red).

One source only. The board accepts power from the USB port, or from the 5V and GND pins, or from the 3V3 and GND pins. Pick one and only one: otherwise the board and/or the source can be damaged [8]. In practice: switch the pack off before you plug the USB cable in.

ESP32-DevKitC: the 5V pin, the 3V3 pin and the regulator Top: an ESP32-DevKitC V4 seen from above, USB socket on the left. Two power pins look alike at the two ends of the same header: the 5V pin, next to the USB end, and the 3V3 pin, at the antenna end. Bottom: the power paths. The USB socket's 5 volts and the 5V pin both feed the regulator, an AMS1117-3.3 on the original board, which turns what it receives into a steady 3.3 volts. Out of it comes the 3V3 rail, which feeds the ESP32 chip and the 3V3 pin. A battery pack goes on the 5V pin and must stay between about 4.4 and 6.5 volts, our working figures, to confirm by measuring. The 3V3 pin is for feeding small parts such as a sensor: never put a pack on it, since 4 AA cells give about 6 volts and the limit is 3.6 volts. And only one power source at a time: USB, or the 5V pin, or the 3V3 pin. Switch the pack off before plugging in the USB cable. FIG. 4 — THE TWO POWER PINS OF THE DEVKITCENBOOT5VCLKCMDD0D3D1D215132GND0124141627172652518331932GND352134RXVNTXVP22EN233V3GND5V pin: battery pack in≈ 4.4 V to 6.5 V3V3 pin: 3.3 V out to small partsnever a pack hereregulator (AMS1117-3.3 on the original board)clone boards can differ: read the chip's name, measure the packPOWER PATHSUSB socket5 V from the cable5V pinpack ≈ 4.4–6.5 VregulatorAMS1117-3.3→ steady 3.3 V3V3 railESP32 chipruns on 2.3–3.6 V3V3 pinsmall parts, a sensorpack on the 3V3 pin: never4 × AA ≈ 6 V, limit 3.6 VOne source at a time: USB, or 5V + GND, or 3V3 + GND. Pack off before USB.
Tap the diagram to open it full screen.

Check yourself

Three short questions. Nothing is saved, take your time.

  1. You put 4 AA cells in series. Each is marked 1.5 V and 2,000 mAh. What does the pack give you?

    • 6 V and 2,000 mAh
    • 6 V and 8,000 mAh
    • 1.5 V and 8,000 mAh
    Show the answer

    6 V and 2,000 mAh. Cells in series add their voltages (4 × 1.5 V = 6 V), but the capacity stays that of one cell, 2,000 mAh [2][4].

  2. Your ESP32 board runs from a battery pack wired to its 5V pin. You want to plug in the USB cable to upload a sketch. What do you do first?

    • Nothing, both can be connected at once
    • Switch the pack off, so only one power source is connected
    • Move the pack wire to the 3V3 pin
    Show the answer

    Switch the pack off, so only one power source is connected. The board must get its power from one source only. Two at once can damage the board or the source [8]. Switch the pack off before plugging the cable in.

  3. A sensor is powered by its own battery. Its signal wire goes to your ESP32 pin, but the two grounds are not connected. What is the problem?

    • Nothing, the signal wire is enough
    • The ESP32 has no shared zero to measure the signal against, so its readings cannot be trusted
    • The sensor will run twice as fast
    Show the answer

    The ESP32 has no shared zero to measure the signal against, so its readings cannot be trusted. A voltage is always measured between two points [5]. With no shared ground, the board and the sensor do not measure from the same zero. Join the GND of both sides [6].


Sources

Show the 12 sources
  1. SparkFun, “Battery Technologies” (nominal voltages: alkaline 1.5 V, NiMH 1.2 V; four NiMH = 4.8 V; capacity in mAh; the voltage falls as a cell discharges; primary cells cannot be recharged safely; a wrongly connected alkaline cell may get hot; LiPo 3.7 V nominal, needs a proper charger; 2,500 mAh NiMH AA listing) — https://learn.sparkfun.com/tutorials/battery-technologies
  2. All About Circuits, Volume I (DC), “Battery Construction” (cells in series add their voltages; cell size sets internal resistance, not voltage) — https://www.allaboutcircuits.com/textbook/direct-current/chpt-11/battery-construction/
  3. All About Circuits, Volume I (DC), “Battery Ratings” (amp-hour: current multiplied by time; only an approximation, trusted near the rated current; very low currents and ageing) — https://www.allaboutcircuits.com/textbook/direct-current/chpt-11/battery-ratings/
  4. All About Circuits, Volume I (DC), “Practical Considerations - Batteries” (the same current in every series cell, so cells need the same amp-hour rating or some run out sooner; series does not add amp-hour capacity) — https://www.allaboutcircuits.com/textbook/direct-current/chpt-11/practical-considerations-batteries/
  5. All About Circuits, Volume I (DC), “Voltage and Current” (voltage is always relative between two points) — https://www.allaboutcircuits.com/textbook/direct-current/chpt-1/voltage-current/
  6. Adafruit, “Adafruit NeoPixel Überguide”, page “Powering NeoPixels” (with several supplies, connect the grounds in common; do not join the +5 V of the different supplies) — https://learn.adafruit.com/adafruit-neopixel-uberguide/powering-neopixels
  7. Espressif, ESP32 Series Datasheet v5.3 (Table 5-1: absolute maximum 3.6 V on the supply pins; Table 5-2: recommended supply 3.3 V, maximum 3.6 V; Table 5-3: high-level input voltage up to VDD + 0.3 V) — https://documentation.espressif.com/esp32_datasheet_en.pdf
  8. Espressif, ESP32-DevKitC V4 User Guide, “Power Supply Options” (three mutually exclusive ways: USB, 5V and GND, 3V3 and GND; one and only one, otherwise the board or the source can be damaged) — https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32/esp32-devkitc/user_guide.html
  9. Espressif, ESP32-DevKitC V4 schematic (AMS1117-3.3 regulator and 22 µF / 10 V input capacitor on the 5 V line) — https://dl.espressif.com/dl/schematics/esp32_devkitc_v4_sch.pdf
  10. Adafruit, “Li-Ion & LiPoly Batteries” (for beginners, alkaline AA or 9 V cells; NiMH as the rechargeable step) — https://learn.adafruit.com/li-ion-and-lipoly-batteries
  11. SparkFun, “Logic Levels” (most systems use 3.3 V or 5 V logic levels) — https://learn.sparkfun.com/tutorials/logic-levels
  12. Adafruit, “Alkaline AA batteries (LR6) - 4 pack” (1.6 V fresh to 0.8 V dead; capacity depends on the discharge, typically 3,000 mAh for an AA alkaline) — https://www.adafruit.com/product/3349

Pinch or double-tap to zoom, swipe to change diagram.Scroll with Ctrl or double-click to zoom. Arrow keys change diagram.