Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Arduino Battery Capacity Tester: Build & Use Guide

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide shows you how to build a battery capacity tester using an Arduino. It measures the actual milliampere-hours (mAh) a rechargeable battery can deliver before its voltage drops to a cutoff point. This is useful for testing old AA/AAA NiMH batteries, 18650 lithium cells, or 9V batteries to see their real condition. You'll need basic soldering skills and a multimeter. The tester works by discharging the battery through a constant current load while logging voltage over time, then calculating capacity.

What You'll Need

  • Arduino board (Uno, Nano, or similar)
  • 16x2 LCD with I2C module (or use serial monitor)
  • MOSFET (e.g., IRF540N or IRLZ44N) for load control
  • Power resistor (e.g., 10Ω 10W) for the discharge load
  • Current sense resistor (0.1Ω, 1% tolerance, 2W)
  • 1kΩ and 10kΩ resistors for voltage divider
  • 10kΩ potentiometer (optional, for calibration)
  • Breadboard and jumper wires
  • 12V DC adapter or USB power for Arduino (separate from battery under test)
  • Battery holder or wires with alligator clips
  • Multimeter for calibration
  • Soldering iron (optional, for permanent build)

Step-by-Step

  1. Understand the circuit: The battery connects to a power resistor and MOSFET in series. The Arduino controls the MOSFET gate with PWM to regulate discharge current. A current sense resistor in series lets you measure current via analog input. A voltage divider scales battery voltage down to 5V for the Arduino's ADC.
  2. Build the voltage divider: Connect a 10kΩ resistor from battery positive to an analog pin (A0). Connect a 1kΩ resistor from that same pin to ground. This gives a 1/11 ratio, so a 12V battery reads as ~1.09V. For a 4.2V lithium, it reads ~0.38V. Use precision resistors or calibrate later.
  3. Connect the current sense: Place the 0.1Ω resistor in series with the battery's negative terminal. Connect the side that goes to the load to analog pin A1. The other side goes to ground. The voltage across this resistor is proportional to current (V = I * R).
  4. Wire the MOSFET and load: Connect the battery positive to one end of the power resistor. The other end of the resistor goes to the MOSFET drain. MOSFET source goes to the current sense resistor (the load side). MOSFET gate connects to Arduino digital pin 9 through a 100Ω resistor (to reduce ringing). Add a 10kΩ pull-down resistor from gate to ground to keep it off during startup.
  5. Connect the LCD (optional): If using I2C LCD, connect SDA to A4, SCL to A5 on Uno (or dedicated pins on other boards). VCC to 5V, GND to ground. If using serial monitor, skip this.
  6. Power the Arduino separately: Use USB or a 9V adapter. Never power the Arduino from the battery under test because the load will drain it and affect readings.
  7. Write the firmware: The code should: read voltage and current every second, calculate mAh by integrating current over time (mAh += current_A * (time_seconds/3600) * 1000), control PWM to maintain a target current (e.g., 500mA), and stop when voltage drops below a cutoff (e.g., 1.0V for NiMH, 3.0V for Li-ion). Use a simple PID or just set PWM to a fixed value and measure actual current.
  8. Calibrate the current: Before testing, measure the actual current with a multimeter in series. Adjust the PWM value or apply a calibration factor in code to match the target. For example, if you want 500mA but read 480mA, increase PWM by 5%.
  9. Test with a known battery: Connect a fully charged AA NiMH battery. Start the tester. The LCD or serial monitor should show voltage, current, and mAh. Run until cutoff. The final mAh is the capacity.
  10. Record results: Note the capacity and compare to the battery's rated capacity. A battery below 70% of rated is considered worn.

Common Mistakes

  • Using a power resistor with too low wattage – it will overheat and possibly burn. Use at least 10W for 1A discharge.
  • Connecting the battery backwards – can damage the MOSFET or Arduino. Always double-check polarity.
  • Not using a pull-down resistor on the MOSFET gate – the gate may float and turn on unexpectedly.
  • Measuring voltage at the battery terminals instead of after the load – you need the battery's open-circuit voltage, but during discharge it's okay to measure at the battery, just note the drop.
  • Forgetting to calibrate the ADC – Arduino's 5V reference may not be exact. Use the internal 1.1V reference for better accuracy.
  • Discharging too fast – high current heats the battery and reduces measured capacity. Use a rate around 0.5C (e.g., 500mA for a 1000mAh battery).

Tips

  • Use a heat sink on the MOSFET and power resistor – they get hot during discharge.
  • Add a small fan or keep the setup in a well-ventilated area.
  • For accurate results, use a precision current sense resistor (1% or better).
  • Store the calibration factor in EEPROM so you don't have to recalibrate every time.
  • Implement a safety timeout (e.g., 12 hours) to prevent endless discharge if the cutoff fails.
  • Use the Arduino's internal analog reference (1.1V) for the current sense to get better resolution.
  • Test with a dummy load (resistor) first to verify the code works before using a real battery.

Troubleshooting

  • No current flows: Check MOSFET connections – gate must be driven, source and drain correct. Verify the battery is charged and connected properly.
  • LCD shows nothing: Adjust the contrast potentiometer on the I2C module. Check I2C address (common: 0x27 or 0x3F). Run an I2C scanner sketch.
  • Readings are unstable: Add a 100nF capacitor between the analog pin and ground to filter noise. Use twisted wires for analog signals.
  • Battery voltage reads too high/low: Recalculate the voltage divider ratio. Measure the actual resistor values with a multimeter and update the code accordingly.
  • MOSFET gets very hot: It may not be fully on. Use a logic-level MOSFET (like IRLZ44N) that can be fully driven at 5V. Or increase the PWM duty cycle.
  • Capacity seems too high: The current measurement might be too low. Check the current sense resistor value and calibration.
  • Arduino resets when load turns on: The load may be causing a voltage drop on the same power supply. Use a separate power supply for the load circuit.

Frequently Asked Questions

Q: Can I test lithium-ion batteries with this?
A: Yes, but set the cutoff voltage to 3.0V or higher (3.2V recommended) to avoid over-discharging. Use a discharge current around 0.5C.

Q: How accurate is this tester?
A: With calibration and a good current sense resistor, you can achieve ±5% accuracy. The main error comes from the ADC resolution and resistor tolerances.

Q: What is the maximum voltage I can test?
A: The voltage divider limits it. With a 10k/1k divider, you can safely measure up to about 12V. For higher voltages, adjust the divider ratio.

Q: How long does a test take?
A: Depends on capacity and discharge current. A 2000mAh battery at 500mA takes about 4 hours. At 1A, it takes 2 hours.

Q: Can I test non-rechargeable batteries?
A: Yes, but they have higher internal resistance and may not deliver stable current. The tester will still work, but the capacity will be lower than expected.

Q: Do I need a separate power supply for the Arduino?
A: Yes, because the battery under test is being discharged and its voltage changes. Using it to power the Arduino would affect readings and could cause the Arduino to reset.