Sub topic 3
Estimating battery runtime realistically
This chapter assumes you know Ohm's law, can read a simple schematic, and have uploaded a sketch to an Arduino board.
A simple runtime estimate divides battery capacity by average current. Real batteries deliver less than their rating, so derate the capacity. A factor of 0.7 is a reasonable starting point for temperature, aging, and regulator losses.
def runtime_hours(capacity_mah, avg_current_ma, derate=0.7):
"""Rough runtime, derating the rated capacity for real-world losses."""
return capacity_mah * derate / avg_current_ma
print(runtime_hours(2000, 50)) # 28.0 hoursUse average current, not peak current. Average current is the time-weighted mean of every load state. A board drawing 120 mA for 1 s out of every 10 s, and 10 mA for the other 9 s, averages (120 × 1 + 10 × 9) / 10 = 21 mA.
Powering the board
Choose the input that matches your supply. Each row below lists a board pin or port and what it expects.
| Input | Typical use | Notes |
|---|---|---|
| VIN | Unregulated 7 to 12 V supply | Passes through the onboard regulator. Wasted heat rises with the voltage gap. |
| 5V | Regulated 5 V supply or output | Feeding a battery here bypasses the regulator. Use only a regulated 5 V source. |
| 3.3V | Regulated 3.3 V output | Limited current. Use it for low-power 3.3 V sensors only. |
| USB | 5 V from a computer | Limited current. Do not power motors from it. |
A linear regulator turns excess voltage into heat. Its loss is (Vin − Vout) × I. A 9 V pack feeding a 5 V regulator at 100 mA wastes 0.4 W, which shortens runtime.
Measuring battery voltage
Two 100 kΩ resistors form a divider that halves the battery voltage, so a 5 V board can measure a pack up to about 10 V.
// Battery+ -> R1 (100k) -> A0 -> R2 (100k) -> GND
const float R1 = 100000.0;
const float R2 = 100000.0;
const float VREF = 5.0;
void setup() {
Serial.begin(9600);
}
void loop() {
int raw = analogRead(A0);
float vPin = raw * VREF / 1023.0;
float vBattery = vPin * (R1 + R2) / R2;
Serial.print("Battery: ");
Serial.print(vBattery, 2);
Serial.println(" V");
delay(1000);
}Battery safety
- Check polarity before you connect anything. Reversed polarity can destroy the board and regulator.
- Never short the terminals. A short can overheat a cell and cause it to rupture.
- Lithium-ion and LiPo cells need protection. Do not discharge a cell below about 3.0 V, and do not charge it outside its rated range.
- Put a fuse in the battery line.
Cutting average current
Put the board into a sleep mode between readings, turn off unused LEDs, and choose regulators with low quiescent current, the idle draw that flows even when the load is off.
Exercise
A 1500 mAh pack powers a board that averages 30 mA. Using a 0.7 derating factor, how many hours will it run?
Show answer
1500 × 0.7 / 30 = 35 hours.