Skip to content
Tutorials Center
My learning

Topics

Lesson 31 of 37 ยท Power and Debugging

Power Supplies and Batteries

Power an Arduino project properly: USB, barrel jack and VIN limits, linear regulators and heat, battery types, voltage dividers for battery monitoring, and runtime math.

A project that works on your desk, tethered to a USB cable, can fail when you try to run it from a battery. Servos reset the board, readings wander, or the battery is flat after a day. Power is the unglamorous half of electronics, and understanding it separates projects that work once from projects that work for months.

Boards and batteries cannot run on this site. The numbers below are standard figures for common parts, but always check the datasheet for your exact board. The C programs are labelled stand-ins that do the arithmetic for you.

Ways to power a board

An Arduino Uno accepts power in three ways:

Source Details
USB 5 V from a computer or charger; the computer port supplies up to 500 mA (a polyfuse limits the board's own draw)
Barrel jack 7 to 12 V recommended (6 to 20 V absolute limits), regulated down to 5 V on the board
VIN pin same regulator input as the jack; 7 to 12 V
5V pin bypasses the regulator: supply exactly 5 V (clean and regulated), or you can damage the board

Different boards differ: a Nano takes 7 to 12 V on VIN, a Pro Mini 3.3 V version wants 3.3 to 12 V depending on the regulator, and an ESP32 or Arduino Nano ESP32 runs at 3.3 V internally. Check the pinout of your board before connecting anything, and never exceed the stated maximums.

The linear regulator and heat

The onboard voltage regulator (often an NCP1117 or similar) is a linear regulator: it takes the input voltage and burns off the difference as heat. The power wasted is (Vin - Vout) x I. With a 12 V adapter powering a 5 V circuit drawing 200 mA, that is (12 - 5) x 0.2 = 1.4 W of heat in a tiny chip, which gets hot, and shuts itself down if the temperature rises too far.

Rules of thumb:

  • Feed the regulator as little above 5 V as practical (7 to 9 V is a good range).
  • If your parts need more than about 500 mA (servos, motors, LED strips, relays), power them from a separate regulated 5 V supply, not from the board's regulator, and join the grounds.
  • A buck (switching) converter wastes far less heat than a linear regulator and is better for battery projects with a big voltage drop.
C Stand-in: regulator heat (C)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Choosing a battery

Battery Voltage Notes
9 V alkaline (PP3) 9 V (drops quickly) small capacity (about 500 mAh); poor choice for motors
4 x AA alkaline 6 V good for an Uno through VIN or the jack; about 2000 mAh
4 x AA NiMH (rechargeable) about 4.8 V do not use on the barrel jack (too low after regulator); can feed 5 V directly
Single Li-ion or LiPo 3.0 to 4.2 V (3.7 V nominal) needs a protection and charging module; ideal for 3.3 V boards
Power bank (USB) 5 V easiest: plug into USB; some switch off at very low current

Lithium batteries store a lot of energy and can burn when abused: never short them, never charge them without a proper charger board (TP4056 modules for single cells), and never discharge them below the cutoff (about 3.0 V) without protection.

Runtime: how long will it last?

Estimate with hours = capacity (mAh) / average current (mA), then be pessimistic: apply a 70 to 80 percent factor for real conditions and aging. A board plus sensors drawing 50 mA from a 2000 mAh pack: 2000 / 50 = 40 hours, about 30 hours in practice.

C Stand-in: battery runtime estimate (C)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

The last line is the lesson: the same battery that lasts hours with the board running at full speed can last months if the circuit sleeps most of the time (sleep modes).

Note that a standard Uno draws roughly 45 to 50 mA with nothing attached because of its USB chip and power LED. A bare ATmega328P at 3.3 V and 8 MHz in a Pro Mini draws about 4 to 5 mA, and far less asleep (microamps). If battery life matters, choose a board with that in mind.

Monitoring battery voltage with a voltage divider

Analog inputs measure at most the reference voltage (5 V on an Uno). To read a 9 V battery you must scale it down with two resistors in a voltage divider: Vout = Vin x R2 / (R1 + R2). With R1 = 10 kilohms and R2 = 10 kilohms, 9 V becomes 4.5 V, safe for the pin. Then, in the sketch, multiply back by the ratio.

C++
const int BATTERY_PIN = A0;
const float DIVIDER_RATIO = 2.0;      // (R1 + R2) / R2 for 10k + 10k
const float VREF = 5.0;

float batteryVolts() {
  int raw = analogRead(BATTERY_PIN);
  return raw * (VREF / 1023.0) * DIVIDER_RATIO;
}

void setup() {
  Serial.begin(9600);
}

void loop() {
  float v = batteryVolts();
  Serial.print("Battery: ");
  Serial.print(v, 2);
  Serial.println(" V");
  if (v < 6.5) {
    Serial.println("Low battery!");
  }
  delay(2000);
}

Use large resistors (100 kilohms and up) when watching a battery that must last: a 10 kilohm divider across a 9 V battery wastes 0.45 mA continuously, and a 20 kilohm total draws that all the time. The next stand-in turns raw readings into volts and a simple percentage estimate. Li-ion cell voltage is not linear with remaining charge, so a rough lookup table is better than a straight line.

C Stand-in: ADC counts to battery volts and percent (C)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Good power habits

  • Common ground for every supply in the project.
  • Decoupling capacitors: 100 nF ceramic close to each chip's power pins, and a 10 to 470 microfarad electrolytic near motors, servos or radios.
  • Separate noisy loads (motors, relays) from sensitive ones or add filtering.
  • Use the right wire: thin jumper wires drop voltage at high current.
  • Brown-outs: low voltage makes boards behave strangely before they stop. If random resets happen when a motor starts, suspect the supply first. The AVR's brown-out detector (a fuse setting) resets cleanly at a threshold instead of running unreliably.
  • Protect against reverse polarity with a diode or a P-channel MOSFET.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A 12 V supply feeds the board's 5 V linear regulator, and the circuit draws 300 mA. How much power is wasted as heat?

    (12 - 5) volts multiplied by 0.3 A gives 2.1 W, all dissipated as heat in the regulator.
  2. 2. Why use a voltage divider before analogRead on a 9 V battery?

    An input pin can only measure up to its reference (5 V on an Uno), and higher voltages can damage it.
  3. 3. A 2000 mAh battery powers a 40 mA load. What is the ideal runtime before derating?

    2000 mAh divided by 40 mA is 50 hours; real life gives less.
  4. 4. What must you do when powering servos from a separate supply?

    A common ground gives all signals a shared reference. Never join the positive rails of different supplies.

Summary

  • Power through USB, the barrel jack or VIN, or feed regulated 5 V (or 3.3 V) directly with care.
  • Linear regulators turn the voltage difference into heat; give them modest input and use separate supplies for heavy loads.
  • Runtime is capacity divided by average current, derated.
  • Measure battery voltage with a high-value voltage divider; keep a common ground and decouple supplies.

Next: Sleep Modes and Low-Power Design