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.
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).
- On paper: 2,500 ÷ 50 = 50 hours
- 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.
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.
One pack = one type, one brand, same age. Never mix cells.
Type the mAh printed on your own cells. Series does not add capacity.
Enter a capacity between 50 and 20 000 mAh.
From the datasheets added up, or measured with your multimeter. A rough figure is fine.
Enter a current between 0.1 and 3000 mA.
Estimatetime (h) = capacity (mAh) ÷ current (mA)
Pack voltage
4.8 V
Hourstyp.
—
Daystyp.
—
Type your cells' capacity to see an estimate.
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 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:
5Vpin. 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.)3V3pin. 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
5Vpin: 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.
Check yourself
Three short questions. Nothing is saved, take your time.
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
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.
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
Sources
Show the 12 sources
- 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
- 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/
- 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/
- 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/
- 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/
- 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
- 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
- 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
- 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
- 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
- SparkFun, “Logic Levels” (most systems use 3.3 V or 5 V logic levels) — https://learn.sparkfun.com/tutorials/logic-levels
- 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