Configuring an NI USB-9215 Battery Tester in LabVIEW

Brian Holt10 min read
Data AcquisitionOther ManufacturerTechnical Reference
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

A USB-9215 voltage input module, a breadboard, a single battery holder, and the resistors and switches from an Arduino kit are enough to build a battery tester that does real measurement work: open-circuit voltage, loaded voltage, internal resistance, and integrated discharge capacity. No Arduino is needed in the signal path. The breadboard wires go straight to the DAQ terminals. Build it in the order below and pass each check before moving on.

Wire one cell to the DAQ and match a handheld meter

Start with one AA cell in the holder, with the battery + lead going to an analog input AI+ terminal and the - lead to that channel's reference terminal. Take the pin-out from the module manual, not from memory. Create the channel in the DAQ Assistant or with DAQmx Create Virtual Channel (AI Voltage), and use the terminal configuration the hardware supports.

Two quick fixes that fail:

  • Routing the cell through the Arduino. It adds nothing. The Arduino is not needed for this build.
  • Splitting one cell across two channels. A single cell has one voltage. Two channels measure the same thing twice.

Check: the LabVIEW indicator agrees with a handheld meter on the same cell. Pull the cell out. A floating input reads a meaningless value that wanders, and that confirms the DAQ reads what it is connected to and nothing else. Never trust a reading with the cell disconnected.

Average the DC reading and measure your own noise

A noise filter tip written for AC signals does not transfer directly to a battery, but a DC signal still carries noise from the DAQ, the breadboard contacts, and pickup on the leads. Handle it in software:

  1. Configure a finite hardware-timed acquisition (DAQmx Timing, sample clock) with a block of N samples. Read the allowed rates from the module datasheet.
  2. Feed the block to Mean and to Standard Deviation and Variance. Use the mean as the voltage and the standard deviation as the noise figure.
  3. Repeat with the same cell 20 or more times. Record the spread of the block means. That spread is the uncertainty of your tester.

Characterizing the tester before characterizing batteries is the step that separates a measurement from a guess. It also gives the presentation a defensible statement: the tester resolves voltage differences larger than the spread you measured.

Check: the standard deviation is small compared to the voltage difference you expect between a fresh and a used cell. If it is not, fix the breadboard contacts and lead length before going on. Do not hide a noisy signal behind a larger N.

Add the load switch without floating the DAQ input

Keep the DAQ across the cell at all times. Put the switch in series with a load resistor that is also across the cell:

cell(+) ----+---------- AI+
            |
         [switch]
            |
        [R_load]
            |
cell(-) ----+---------- AI- (reference)

Switch open reads open-circuit voltage. Switch closed reads loaded voltage. A momentary button from the kit works well for the good/bad pulse because it limits heating. A latching switch covers the long discharge mode.

Do not switch the DAQ lead itself. The input floats during the transition and the reading is garbage. Select the mode (good/bad or discharge log) with a front-panel enum in LabVIEW, not with hardware. The mechanical switch only applies the load.

Size the load before closing the switch:

I_load = V_load / R_load
P_load = V_load^2 / R_load     (must be below the resistor's power rating)

Measure R_load with a meter and use the measured value in the program. Coin cells have high internal resistance and low current capability, so use a larger load resistor for them than for AA or AAA cells. A load that is too small collapses a coin cell's voltage and tells you nothing. Stop if a cell or resistor gets warm to the touch and increase R_load.

Check: the voltage drops when the switch closes and recovers when it opens. If it does not recover, the cell is depleted or the contact is bad.

Calculate internal resistance for the good/bad call

Open-circuit voltage alone is a weak health indicator. A weak cell can read acceptable with no load and sag hard once current flows. Internal resistance separates them. Take one open-circuit reading, one loaded reading, and compute:

I_load = V_load / R_load
R_int  = (V_oc - V_load) / I_load
       = R_load * (V_oc - V_load) / V_load

Repeat the load pulse a few times and average, using the same statistics as before. The good/bad threshold is not a number to copy from anywhere. Measure a known-fresh cell and a known-depleted cell of the same type with your tester, then set the threshold between the two clusters. Keep separate thresholds per cell type (AA, AAA, coin) because their internal resistance differs by design.

Check: the fresh and depleted cells give R_int values that are clearly separated compared to your measured spread. If they overlap, increase the load current (smaller R_load, within the power rating) or average more samples.

A state machine fits this test naturally: Idle → Measure OCV → Prompt: press button → Measure loaded → Compute R_int → Verdict. A prompt on the front panel replaces the automation you do not have hardware for.

Log the discharge and integrate amp-hours

Hold the switch closed and log voltage against time. Current comes from the known load: I = V / R_load. Accumulate capacity per sample:

Ah += I * dt / 3600          (I in A, dt in s)
Wh += V * I * dt / 3600

if dt is in ms:  Ah += I * dt_ms / 3 600 000

Summing amps times milliseconds without the 3,600,000 divisor gives a number that is not amp-hours. In a hardware-timed acquisition, dt = 1 / sample rate. In a software-timed loop, use the measured elapsed time per iteration, not the wait value you typed in. Use a shift register for the running total and write time, voltage, current, and Ah to a file each iteration.

Stop the run at a cutoff voltage taken from the cell manufacturer's datasheet for that chemistry, not a guess.

Plan the run length first. Run time is roughly t = C / I, where C is the rated capacity from the datasheet. A small load resistor shortens the run but raises heat and current. For a short show-and-tell, log a partial discharge at a controlled load and show the curve and the accumulated Ah so far. A full multi-hour run can be recorded ahead of time and shown as data.

Check: Ah rises monotonically and the integral matches a hand calculation from two logged points. Cell voltage declines smoothly. Steps or spikes point to contact problems.

Scale a 9 V cell into the input range before connecting it

A 9 V battery exceeds the input range you described (roughly ±5 V). Read the actual input range, the input impedance, and the maximum overvoltage in the module datasheet. Connecting a 9 V cell directly can damage the input. Do not connect it until the divider is built and its output has been checked with a meter.

Use one resistor divider and one channel:

V_out = V_in * R2 / (R1 + R2)
V_in  = V_out * (R1 + R2) / R2      (software multiplies back)

Worked example, with assumed values: a fresh 9 V cell measures 9.6 V on a meter. A ratio of 1/3 gives 3.2 V at the input, inside a ±5 V range with margin. If your kit has three resistors of the same value, two in series for R1 and one for R2 gives that ratio regardless of the resistance value. Divider current is V_in / (R1 + R2), so higher resistance draws less from the cell.

Keep R2 well below the DAQ input impedance, because R2 in parallel with the input impedance shifts the ratio. Measure the real divider ratio with a meter on the built divider and store it in the program as a constant. The divider multiplies the measurement uncertainty by the ratio, so re-run the noise characterization on this channel.

Check: with the meter, the divider output at the 9 V cell is below the input range with margin, and the LabVIEW reading after rescaling matches the meter across the cell.

Add depth that does real work

Extra features earn credit only if they produce data. Choose from these, ordered by cost:

Addition What it produces What it needs
Brand comparison Capacity and R_int across several AA brands Same load, same cutoff, same procedure for each cell
Tester uncertainty statement Voltage uncertainty from repeat readings Already built in the averaging step
Different loads Sag and capacity versus current Two or more load resistors
Temperature test Performance in a refrigerator and a freezer Temperature sensor and a spare input channel
Multiple cells at once More data in less time Additional input channels, or a multiplexer for more than the module provides
Servo dial for state of charge Analog-style indicator An output device; the Arduino from the kit can drive it if LabVIEW sends commands over a serial link
Relay-automated load switching Hands-off tests A DAQ with digital outputs, such as the USB-6001 for relay control

The USB-9215 is a voltage input module, so confirm on its datasheet whether it has any outputs before planning automation. Without digital outputs, keep the mechanical switch and the front-panel prompts. The brand comparison and load sweep cost nothing extra and add the most technical content.

Check: pick two additions and run them with the same procedure on every cell so the comparison is valid.

Run the end-to-end check and trace bad readings

  1. Meter-check every input before connecting: cell voltage, divider output, and load resistor value.
  2. Read open-circuit voltage on a fresh AA and compare it to the meter.
  3. Press the load button, read the loaded voltage, and confirm R_int is plausible and repeatable within the noise spread.
  4. Test a known-depleted cell of the same type and confirm the verdict flips.
  5. Run a short discharge log and confirm the Ah integral matches a hand calculation.
  6. Run one AAA and one coin cell with its own load and threshold.
  7. Run the 9 V cell through the divider, if included, and confirm the rescaled value matches the meter.
Symptom Likely cause Action
Reading wanders or reads near zero with no cell Floating input Keep the DAQ connected across the cell in every switch position
Reading pinned at the range limit Input overrange, usually the 9 V cell Disconnect and fit the divider; check the datasheet overvoltage limit
Noisy voltage that averaging does not fix Loose breadboard contact or long leads Reseat contacts, shorten leads, re-measure standard deviation
Voltage collapses under load and does not recover Depleted cell, or load too heavy for a coin cell Test with a fresh cell; raise R_load
Ah total is off by orders of magnitude Unit conversion error on dt Divide A·s by 3600, or A·ms by 3,600,000
9 V reading disagrees with the meter Divider ratio assumed instead of measured, or divider loaded by the input Measure the real ratio and reduce R2 relative to the input impedance

FAQ

How do I measure a 9 V battery with a DAQ that only reads about ±5 V?

Build a resistor divider with a known ratio (for example 1/3), confirm its output with a meter before connecting the DAQ, and multiply the reading back by the measured ratio in LabVIEW. Read the module's actual input range and maximum overvoltage from the datasheet first.

How do I reduce noise on a DC battery voltage in LabVIEW?

Acquire a block of N samples with hardware timing and take the mean with the Mean VI. Report the standard deviation with Standard Deviation and Variance as your noise figure. Fix loose contacts before increasing N.

How do I calculate a battery's internal resistance with a load resistor?

Measure open-circuit voltage V_oc, close the switch to the load, and measure V_load. Then R_int = R_load * (V_oc - V_load) / V_load. Use the measured value of R_load.

How do I calculate amp-hours from logged voltage in LabVIEW?

Compute I = V / R_load each sample and accumulate Ah += I * dt / 3600 in a shift register, with dt in seconds. Use 3 600 000 if dt is in milliseconds. Take dt from the sample clock or measured elapsed time.

When do I stop and contact official support?

Stop and call National Instruments support if the USB-9215 does not appear in NI MAX, if readings stay wrong after the wiring and meter checks pass, or if an input may have seen an overvoltage. Use the module manual and datasheet for input limits and pin-out, and stop immediately if any cell, resistor, or divider gets warm.

Back to blog