Projects / Battery voltage checker

Battery voltage checker

Beginner1.3 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. NANO18.9 mASSD1306

    Install the libraries

    SSD1306 and GFX.

  2. NANO

    Wire the module

    S to A0, minus to GND, plus not used.

  3. NANO

    Wire the display

    A4 and A5 with power.

  4. NANO

    Add the button

    D2 to GND.

  5. NANOVOLTAGE5.02 V

    Upload the sketch

    A voltage and a percentage appear.

  6. NANO

    Connect a 9 V battery

    Check the polarity first.

  7. NANO

    Compare with a meter

    Adjust FACTOR if it is a little out.

  8. NANO

    Press the button

    Try the other battery types.

In short

How do you build a battery voltage checker?

A divider module lets a board read small dry batteries up to 25 V and show percent remaining for common cells. You need Arduino Nano, Voltage sensor module (0 to 25 V), SSD1306 OLED Display, Tactile push button 6 mm and Breadboard 830 Tie Points. It takes 8 steps and about 75 minutes.

Level
Beginner
Time
About 75 min
Parts
5

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Module S (signal)Nano A0Divided voltage, never above 5 V
Module minusNano GNDCommon ground with the battery
Module plusNot connectedThis pin is not used on most modules
Battery side screw terminalsBattery plus and minusObserve polarity, 25 V maximum
OLED VCC and GNDNano 5V and GNDCheck the label on your module
OLED SDA and SCLNano A4 and A5I2C bus
ButtonNano D2 to GNDChooses the battery type

Code

This voltage sensor module is simply two resistors in a divider that divide the input by five. A battery of up to 25 volts then gives at most 5 volts at the signal pin, which a Nano can read. It is the easy way to measure a battery without risking the analogue input. The sketch reads the voltage, converts it to a percentage using a table for the chosen battery type, and shows both on the display. The button changes the type: a 9 volt alkaline, four AA alkaline cells in a holder, or two AA cells. The percentages are only rough because alkaline cells keep a fairly flat voltage and then fall quickly at the end, and the result also depends on the load. Check the module with a multimeter and adjust the factor if the reading is a little out. Use it only with small dry batteries and low-voltage supplies up to 25 volts, always with the correct polarity. Never connect it to the mains, a car battery that is being charged or any supply above 25 volts, and the negative side of the battery must be joined to the Nano ground.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 oled(128, 64, &Wire, -1);

// The module divides the input by 5, so 25 V in gives 5 V out.
// Check against a multimeter and adjust the factor if needed.
float FACTOR = 5.0;

struct Chem { const char* name; float full; float empty; };
// Rough values for small dry batteries with a light load
Chem CHEMS[3] = {
  {"9V alkaline", 9.4, 6.5},
  {"4xAA alkaline", 6.4, 4.4},
  {"2xAA alkaline", 3.2, 2.2}
};
int chem = 0;
bool wasDown = false;

float readVolts() {
  long s = 0;
  for (int i = 0; i < 32; i++) { s += analogRead(A0); delay(2); }
  return (s / 32.0) * 5.0 / 1023.0 * FACTOR;
}

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT_PULLUP);
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println("OLED not found"); while (1) { } }
  oled.setTextColor(SSD1306_WHITE);
}

void loop() {
  bool down = (digitalRead(2) == LOW);
  if (down && !wasDown) chem = (chem + 1) % 3;
  wasDown = down;

  float v = readVolts();
  float pct = (v - CHEMS[chem].empty) / (CHEMS[chem].full - CHEMS[chem].empty) * 100.0;
  pct = constrain(pct, 0, 100);

  oled.clearDisplay();
  oled.setTextSize(2);
  oled.setCursor(0, 0);
  oled.print(v, 2); oled.println(" V");
  oled.print((int)pct); oled.println(" %");
  oled.setTextSize(1);
  oled.setCursor(0, 44);
  oled.println(CHEMS[chem].name);
  if (pct < 15) oled.println("Low");
  oled.display();

  Serial.println(v, 3);
  delay(500);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

12.509
12.514
12.510
12.508
12.512
12.513

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Fresh 9 V batteryAbout 9.4 V, near 100 percent
Half-used 9 V batteryAbout 8 V
Four AA cellsAbout 6 V
No battery connectedNear zero
Reversed batteryWrong or zero reading, disconnect and check

If it does not work

Reads zero

Check the S wire on A0 and the ground link.

Reading half the real voltage

Your module divides differently, check the factor.

Reading jumps

Poor connection at the screw terminals.

Percentage looks wrong

Choose the right battery type with the button.

Nano resets

A battery of more than 25 V or reversed polarity, disconnect it at once.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the battery voltage checker?

Arduino Nano, Voltage sensor module (0 to 25 V), SSD1306 OLED Display, Tactile push button 6 mm and Breadboard 830 Tie Points.

How long does the battery voltage checker take to build?

About 75 minutes for a beginner maker, in 8 steps.

How do I know the battery voltage checker works?

Fresh 9 V battery: About 9.4 V, near 100 percent. Half-used 9 V battery: About 8 V. Four AA cells: About 6 V.

Reads zero: what should I check?

Check the S wire on A0 and the ground link.

Reading half the real voltage: what should I check?

Your module divides differently, check the factor.

Reading jumps: what should I check?

Poor connection at the screw terminals.

Percentage looks wrong: what should I check?

Choose the right battery type with the button.