How to calculate voltage?
You have two problems here:


How to take 24 readings on an Arduino with only 6 analog inputs.
How to get the voltage in the range of 0 to 5 volts.


To take 24 readings you can use an analog multiplexer or two. For example the 74HC4051 (8 channels) or the 74HC4067 (16 channels). With both of those you could handle 24 channels.



To read the voltages you could successively read each cell, relative to ground (eg. the first one should be 2 V, the second should be 4 V, and so on up to 48 V).

Cells 1 and 2 are fine, they are lower than 5 V. Cells 3 to 24 are not. You need to set up a voltage divider to divide down the voltage into the range 0 to 5.

The formula for a voltage divider is:

Vout = Vin * R2/(R1+R2)


Let's make R1 to be 10k ohms, and solve for R2 (given that we want Vout to be 5).

R2 = Vout * R1/(Vin - Vout)
R2 = 5 * 10000 / (Vin - 5)


Plugging that into a spreadsheet we get:

Vin    R
6  50000
8  16667
10 10000
12  7143
14  5556
16  4545
18  3846
20  3333
22  2941
24  2632
26  2381
28  2174
30  2000
32  1852
34  1724
36  1613
38  1515
40  1429
42  1351
44  1282
46  1220
48  1163




These aren't particularly easy resistor values to work with, so we'll use standard values and calculate what the output voltage should be (with the spreadsheet):

Vin   R   volts   Scale
2     
4     
6   47000 4.9474  1.2128    &lt;--- R2 is 47 k
8   16000 4.9231  1.6250    &lt;--- R4 is 16 k
10  10000 5.0000  2.0000
12   6800 4.8571  2.4706
14   5100 4.7285  2.9608
16   4300 4.8112  3.3256
18   3600 4.7647  3.7778
20   3300 4.9624  4.0303
22   2700 4.6772  4.7037
24   2400 4.6452  5.1667
26   2200 4.6885  5.5455
28   2000 4.6667  6.0000
30   2000 5.0000  6.0000
32   1800 4.8814  6.5556
34   1600 4.6897  7.2500
36   1600 4.9655  7.2500
38   1500 4.9565  7.6667
40   1300 4.6018  8.6923
42   1300 4.8319  8.6923
44   1200 4.7143  9.3333
46   1200 4.9286  9.3333
48   1100 4.7568 10.0909


The "Scale" column will be explained in a moment.



Now we are ready to make up a circuit along these lines:



I haven't shown all the battery cells here - I don't have that much energy! But the principle is the same.



The 2V and 4V inputs we can read directly. From 6V upwards we need to apply the scaling factor from the voltage divider network.

That is shown in the "Scale" column above.

The formula for the voltage on the pin is:

float voltage = ((float) rawADC  + 0.5 ) / 1024.0 * Vref;


So assuming Vref is 5V, and you have a reading of 512, then you apply it like this:

 ( 512  + 0.5 ) / 1024.0 * 5 = 2.502 volts


Now you multiply by the scale factor above, so if this was the 34 V input, the scale factor would be 7.25, and the voltage from the battery would be:

2.502 * 7.25 = 18.14  volts




The stage is now set to work out each voltage:


Use the multiplexer "select" pins to choose one of the battery inputs
Take an analog reading
Scale it by the appropriate amount from the table
Work out what the charge in the cell is (by comparing it to the previous one)


For example, if the first cell read 1.9V and the second cell read 3.85V then you know that the difference is 3.85 - 1.9 which is 1.95 volts.