Battery Voltage Monitor is a runnable microcontroller simulation example on SensBench — open the wired circuit, inspect the code, and compile real firmware in your browser, no install needed. Last updated Aug 14, 2026.

FREE SIMULATOR EXAMPLE · BEGINNER

Battery Voltage Monitor

This example monitors a 9 V battery on the Arduino Uno — a 20k/10k divider scales it into the ADC’s range, the sketch multiplies back to the true voltage, and below 7.0 V it prints a low-battery warning. The divider-scaled voltmeter pattern behind every battery gauge.

Board Arduino Uno (ATmega328P) + logic / power circuit
Difficulty beginner
Category circuits
Libraries None — just the Arduino core
Runs in Sensbench browser simulator — free, no account
Arduino Uno monitoring a 9V battery through a 20k/10k voltage divider with low-battery warning in the Sensbench simulator

The exact circuit you get when you open this example — already wired, ready to run.

The sketch

// Battery voltage monitor
// R1=20k + R2=10k divider: V_adc = V_bat * 10k / 30k
// V_bat = V_adc * 3
void setup() { Serial.begin(9600); }
void loop() {
  float vAdc = analogRead(A0) * 5.0 / 1023.0;
  float vBat = vAdc * 3.0;
  Serial.print("Battery: "); Serial.print(vBat,1); Serial.println(" V");
  if(vBat < 7.0) Serial.println("WARNING: Battery low!");
  delay(1000);
}

How it works

The divider — 20 kOhm on the battery side, 10 kOhm to ground — feeds A0 with one-third of the battery voltage. The sketch reads it, computes vAdc, multiplies by 3 to recover the true battery voltage, and prints it once per second. Below 7.0 V it adds the “WARNING: Battery low!” line.

The divide-by-3 is both the measurement trick and the accuracy tax: the multiplier amplifies the ADC’s quantization error threefold, so each ADC count (about 5 mV) becomes 15 mV of battery uncertainty — acceptable for a monitor, too coarse for a precision gauge.

The 1-second cadence is right for a slow-changing quantity like battery voltage, and the warning line makes the sketch a functional low-battery alarm, not just a meter.

Before you build it for real

The divider drains the battery continuously: 30 kOhm across 9 V is 0.3 mA, enough to noticeably shorten a 9 V battery’s shelf life over months — real monitors switch the divider on only during measurement. The ×3 multiplier triples every error: resistor tolerance, ADC quantization, and reference drift all land threefold on the reading. And the divider’s impedance is 6.7 kOhm (20k parallel 10k) — right at the edge of the ADC’s comfort; much higher resistor values would sag during sampling. The 7 V warning threshold is also battery-chemistry-dependent: lithium packs need different curves than alkaline 9 V blocks.

Get the parts

Related examples

FAQ

Why can't the ADC read the 9V battery directly?

The ADC's range is 0-5 V — 9 V would damage it. The 20k/10k divider scales the battery to a third: V_adc = V_bat × 10k/30k, so 9 V reads as 3 V. The sketch multiplies back by 3 to reconstruct the battery voltage — measure safely, then un-scale in software.

Why is the warning threshold 7.0 V?

A 9 V alkaline is "dead" for most circuits around 7 V — below that it sags under load and can no longer sustain regulation. The threshold is the practical floor the circuit can tolerate; the specific number depends on the load and regulator. The sketch's if (vBat < 7.0) line is that floor, stated plainly.