Skip to content
gunkslab

Primers

Batteries

The first of the power primers. A robot’s battery decides how fast its motors can turn, how long it runs, and how much care it needs. Most small robots run on lithium-ion cells, joined together into a pack.

Pick your level at the top of the page.

High school

Stored energy

A battery stores energy as chemistry and gives it back as electricity. Three words describe what it gives:

  • Voltage, in volts (V), is how hard it pushes, like water pressure in a pipe.
  • Current, in amps (A) or milliamps (mA, thousandths of an amp), is how much flows, like litres a second.
  • Capacity, in milliamp-hours (mAh), is how much it holds, like the size of the tank. A 2,000 mAh battery can give 2,000 mA for an hour, or 200 mA for ten hours.

Cells and packs

A cell is one battery: one can or one flat pouch. Its voltage comes from its chemistry, not its size. A lithium-ion cell gives about 3.7 V. A cell’s name often gives its size: an 18650 is 18 mm across and 65 mm long.

Most robots need more than 3.7 V, so cells are joined into a pack:

  • End to end, in series, the voltages add: two cells make 7.4 V.
  • Side by side, in parallel, the capacities add: two 2,000 mAh cells make 4,000 mAh, still at 3.7 V.

The voltage falls as it empties

A full lithium-ion cell reads 4.2 V and an empty one about 3.0 V. Most of the way between, the voltage falls only slowly, then it drops fast near the end. So a robot slows a little as its battery runs down, and a voltmeter can tell you roughly how full a battery is.

Handle with care

Lithium cells hold a lot of energy in a small space. One that’s short-circuited, overcharged, crushed or pierced can get very hot and catch fire. Charge them only with a charger made for them, somewhere you can see them, and never use one that’s swollen or damaged.

Check yourself

  1. Two 3.7 V cells in series: what voltage?
  2. A robot draws 250 mA from a 2,000 mAh battery. Roughly how long does it run?
  3. You need more run time but the same voltage. Series or parallel?

<details><summary>Answers</summary>

  1. 7.4 V.
  2. 2,000 ÷ 250 = 8 hours. (Less in practice: the motors draw more when they start, and a battery is never emptied completely.)
  3. Parallel: it adds capacity at the same voltage.

</details>

College

Chemistries

Chemistry Nominal Full Empty Notes
Lithium-ion (Li-ion), round cans 3.7 V 4.2 V about 3.0 V Light for the energy it holds
Lithium polymer (LiPo), flat pouches 3.7 V 4.2 V about 3.0 V The same family, any shape; swells when abused
Lithium iron phosphate (LiFePO4) 3.2 V 3.65 V about 2.5 V Heavier, longer-lived, much harder to set alight
Nickel-metal hydride (NiMH) 1.2 V about 1.4 V about 1.0 V The rechargeable AA

Naming a pack

A pack’s name says how its cells are joined: 2S1P is two cells in series, 2S2P two parallel pairs in series, four cells in all.

Pack Cells Voltage, nominal (full to empty) Capacity, with 2,000 mAh cells
1S1P 1 3.7 V (4.2 to 3.0) 2,000 mAh
2S1P 2 7.4 V (8.4 to 6.0) 2,000 mAh
1S2P 2 3.7 V (4.2 to 3.0) 4,000 mAh
2S2P 4 7.4 V (8.4 to 6.0) 4,000 mAh
3S1P 3 11.1 V (12.6 to 9.0) 2,000 mAh

Capacity and energy

Capacity alone doesn’t compare packs of different voltages. Energy, in watt-hours (Wh), does: capacity times voltage. A 2S1P pack of 2,000 mAh cells holds 7.4 V × 2 Ah = 14.8 Wh. A 1S2P pack of the same cells holds the same 14.8 Wh, as 3.7 V × 4 Ah.

The C rating

How much current a cell can give safely, as a multiple of its capacity: 1C from a 2,000 mAh cell is 2 A, 5C is 10 A. Motors starting, or stalled, draw far more than they do running, and the pack has to supply that too.

Sag

Every cell has a little internal resistance, tens of milliohms when new, more as it ages or gets cold. Under a current I, a pack’s voltage drops by I × R below its resting voltage, and recovers when the load stops. A 2S pack of 60 mΩ cells sags 3 A × 0.12 Ω = 0.36 V while a motor starts. Reading a pack at rest makes it look healthier than it is under load.

Balancing, matching and protection

  • Balancing. In a series pack the cells drift apart over many charges. A balance charger charges each cell to the same voltage through the pack’s balance lead, so no cell is overcharged while another is still short.
  • Matching. Cells joined in parallel must be at the same voltage when they’re joined, or the full one dumps current into the empty one.
  • Protection. A protection board on the pack disconnects it if a cell goes over its full voltage, under its empty voltage, or gives too much current. It’s a last line of defence, not a fuel gauge: stop well before it trips. A cell run below its empty voltage can be damaged, and is risky to charge again.

Check yourself

  1. A 3S1P pack of 2,500 mAh cells: its voltage full, nominal and empty, its capacity and its energy?
  2. A 1,500 mAh pack is rated 20C. What’s the most current it can give?
  3. A 2S pack reads 7.6 V at rest. A motor drawing 2 A starts. Each cell has 50 mΩ. What does it read now?
  4. Why does a 2S1P pack and a 1S2P pack of the same cells hold the same energy?

<details><summary>Answers</summary>

  1. 12.6 V full, 11.1 V nominal, 9.0 V empty; 2,500 mAh; 11.1 V × 2.5 Ah ≈ 27.8 Wh.
  2. 20 × 1.5 A = 30 A.
  3. 2 A × (2 × 0.05 Ω) = 0.2 V less: 7.4 V.
  4. Both hold two cells’ energy. One gives it at twice the voltage, the other for twice as long.

</details>

University

A model of a cell

A cell behaves roughly like a voltage source whose voltage depends on how full it is, the open-circuit voltage curve, with a resistance in series and a resistor-capacitor pair after it. The series resistance makes the instant sag when a load starts. The resistor-capacitor pair makes the slower part: under a steady load the voltage keeps creeping down for seconds to minutes, and after the load stops it creeps back up. A cell has to rest a while before its voltage says how full it is.

How full is it?

  • By voltage, at rest. Look the resting voltage up on the curve. Easy, but a lithium-ion curve is flat through the middle: across most of the charge, the voltage moves only a few tenths of a volt per cell, so small errors in the reading become large errors in charge. And under load, sag hides it.
  • By counting charge. Add up the current over time, coulomb counting. Accurate over a short while, but a small offset in the current sensor adds up for ever, so it drifts, and the starting point has to be known.
  • Both. Fuel-gauge chips count charge and correct the count from the voltage whenever the cell has rested, often with a Kalman filter and a model like the one above.

Capacity isn’t fixed either: a cell gives less at high current and when cold, and less every year.

Charging: constant current, then constant voltage

A lithium-ion charger pushes a constant current (often 0.5C to 1C) until the cell reaches 4.2 V, then holds 4.2 V while the current tapers off, and stops when it has fallen to a small fraction, around C/10 to C/20. Charging below about 0 °C plates lithium metal on the anode, which permanently harms the cell and can short it.

Ageing

Cells lose capacity and gain resistance with every cycle and with time. Heat, sitting full at 4.2 V, deep discharges and high currents all speed it up. A cell kept between about 20 % and 80 % lasts many more cycles than one run full to empty. Stored for months, a cell keeps best about half full and cool.

Designing around the pack

  • Regulators. Electronics want a steady 5 V or 3.3 V from a pack whose voltage falls from full to empty. A linear regulator burns the difference as heat: from 7.4 V down to 3.3 V it wastes more than half the power. A buck converter switches instead, often 85 to 95 % efficient. Either needs some headroom above its output: a sag that takes the input below it starves the output, and the microcontroller resets.
  • A cut-off. The robot should stop before the protection board does, at a voltage per cell chosen with margin. But a cut-off that trips the instant the voltage dips is tripped by every motor start. The usual fix is to require the voltage to stay low for a while, a second or so, and to add hysteresis: once stopped, stay stopped until the pack reads clearly higher, which means it was charged.

Check yourself

  1. A microcontroller draws 200 mA at 3.3 V from a 7.4 V pack. How much current does the pack supply through a linear regulator, and through a 90 % efficient buck?
  2. A fuel gauge’s current sensor reads 2 mA high. After a 10 hour run on a 2,000 mAh pack, how far off is its count?
  3. A pack reads 7.3 V a minute after driving, and 7.5 V an hour later. Which says more about how full it is, and why?
  4. Why add hysteresis to a low-battery cut-off, as well as a delay?

<details><summary>Answers</summary>

  1. A linear regulator passes the same current: 200 mA, 1.48 W from the pack for 0.66 W used. The buck needs 0.66 W ÷ 0.9 ≈ 0.73 W, which at 7.4 V is about 99 mA.
  2. 2 mA × 10 h = 20 mAh, 1 % of the pack. It keeps growing until a resting voltage corrects it.
  3. The 7.5 V an hour later. A minute after a load, the cell is still recovering, and reads low.
  4. When the motors stop, the sag goes and the voltage recovers above the cut-off. Without hysteresis the robot would start again, sag, stop, and keep cycling on a nearly empty pack.

</details>

Try it

No pack needed: a toy 2S lithium-ion pack in Python, about 55 lines. It drives a small robot that cruises at 0.5 A and starts a motor every 10 seconds, drawing 3 A for a moment, and shows the pack’s voltage at rest, while driving, and during a motor start. The curve and the resistance are typical round numbers, not any one cell’s. You need only a container runtime. Start a shell with Python in it:

container

container run --rm -it docker.io/library/python:3.14-alpine sh

docker

docker run --rm -it python:3.14-alpine sh

podman

podman run --rm -it docker.io/library/python:3.14-alpine sh

Inside it, save the toy pack and run it:

cat > pack.py <<'EOF'
"""A toy 2S1P lithium-ion pack running a small robot: how its voltage falls, sags and recovers.

The curve and the resistance are typical round numbers, not any one cell's. Change them and run it again.
"""

# A cell's voltage at rest against how full it is: a typical lithium-ion curve, roughly.
CURVE = [(0, 3.00), (5, 3.55), (10, 3.68), (20, 3.73), (30, 3.77), (40, 3.79), (50, 3.82),
         (60, 3.87), (70, 3.92), (80, 3.98), (90, 4.06), (100, 4.20)]
SERIES = 2           # cells in series
CAPACITY = 2.0       # Ah
R_CELL = 0.06        # ohms of internal resistance in each cell
CRUISE = 0.5         # A while driving
START = 3.0          # A for the moment a motor starts
CUTOFF = 3.3         # V a cell: stop here, before the cells are harmed
STEP = 0.1           # s


def rest_voltage(full_pct):
    for (p0, v0), (p1, v1) in zip(CURVE, CURVE[1:]):
        if full_pct <= p1:
            return SERIES * (v0 + (v1 - v0) * (full_pct - p0) / (p1 - p0))
    return SERIES * CURVE[-1][1]


def current(n):
    return START if n % 100 < 2 else CRUISE      # a motor start every 10 s, 0.2 s long


def run(wait):
    """Drive until the pack reads under the cut-off for `wait` seconds in a row.

    Returns (minutes driven, percent left, log)."""
    charge, n, low = CAPACITY, 0, 0                # n: steps so far; low: steps in a row under the cut-off
    log = []
    while charge > 0:
        i = current(n)
        full = 100 * charge / CAPACITY
        rest = rest_voltage(full)
        v = rest - i * SERIES * R_CELL               # what a meter on the pack reads now
        if n % 6000 == 0:                            # every 10 minutes
            log.append((n * STEP / 60, full, rest, rest - CRUISE * SERIES * R_CELL, rest - START * SERIES * R_CELL))
        low = low + 1 if v < CUTOFF * SERIES else 0
        if low and low * STEP >= wait:
            return n * STEP / 60, full, log
        charge -= i * STEP / 3600
        n += 1
    return n * STEP / 60, 0.0, log


minutes, left, log = run(wait=1.0)
print(" time   full   at rest   driving   motor start")
for m, full, rest, drive, start in log:
    print(f"{m:4.0f} min {full:4.0f} %  {rest:6.2f} V  {drive:6.2f} V  {start:7.2f} V")
print()
print(f"Cut-off at {CUTOFF * SERIES:.1f} V, held for a second: stops at {minutes:.0f} min, {left:.0f} % left")
minutes, left, _ = run(wait=0.0)
print(f"Cut-off at {CUTOFF * SERIES:.1f} V, at once:              stops at {minutes:.0f} min, {left:.0f} % left")
EOF
python pack.py
 time   full   at rest   driving   motor start
   0 min  100 %    8.40 V    8.34 V     8.04 V
  10 min   95 %    8.27 V    8.21 V     7.91 V
  20 min   91 %    8.14 V    8.08 V     7.78 V
  30 min   86 %    8.06 V    8.00 V     7.70 V
  40 min   82 %    7.99 V    7.93 V     7.63 V
  50 min   77 %    7.92 V    7.86 V     7.56 V
  60 min   72 %    7.87 V    7.81 V     7.51 V
  70 min   68 %    7.82 V    7.76 V     7.46 V
  80 min   63 %    7.77 V    7.71 V     7.41 V
  90 min   59 %    7.73 V    7.67 V     7.37 V
 100 min   54 %    7.68 V    7.62 V     7.32 V
 110 min   50 %    7.64 V    7.58 V     7.28 V
 120 min   45 %    7.61 V    7.55 V     7.25 V
 130 min   40 %    7.58 V    7.52 V     7.22 V
 140 min   36 %    7.56 V    7.50 V     7.20 V
 150 min   31 %    7.54 V    7.48 V     7.18 V
 160 min   27 %    7.51 V    7.45 V     7.15 V
 170 min   22 %    7.48 V    7.42 V     7.12 V
 180 min   17 %    7.43 V    7.37 V     7.07 V
 190 min   13 %    7.39 V    7.33 V     7.03 V
 200 min    8 %    7.27 V    7.21 V     6.91 V
 210 min    4 %    6.82 V    6.76 V     6.46 V

Cut-off at 6.6 V, held for a second: stops at 212 min, 3 % left
Cut-off at 6.6 V, at once:              stops at 209 min, 4 % left

From 40 minutes to 190, the pack goes from 82 % to 13 % full while its resting voltage falls only 0.6 V: the flat middle of the curve. Then it drops fast. Each motor start pulls it 0.36 V lower for a moment. Both cut-offs stop near the end, a few minutes apart.

Now make the cells older. With vi pack.py, set R_CELL = 0.15 and run it again:

Cut-off at 6.6 V, held for a second: stops at 211 min, 3 % left
Cut-off at 6.6 V, at once:              stops at 164 min, 25 % left

The sag at each motor start is now 0.9 V, and a cut-off that acts at once is tripped by a motor start with a quarter of the pack still left. Waiting a second, longer than a start lasts, ignores the starts and runs to the end.

Things to try next: R_CELL = 0.25, or SERIES = 3 for a 3S pack (and a higher START for bigger motors). Type exit to leave.

With a multimeter and a real pack: set the meter to DC volts and touch its probes to the pack’s main leads. A 2S pack reads between about 8.4 V, full, and 6 V, empty. On the balance lead, the pins next to each other read one cell each: they should be within a few hundredths of a volt of each other. Don’t let the probes touch each other across the pack’s leads.

Learn more