Multi Cell Voltmeter

The big order of Arduino related products has started to arrive, the key components, the Arduino mega 2560 clone and the TFT LCD screen arrived two days ago, along with some of the voltage sensors, and most of the jumper leads I ordered. Still to come are the protoboard for the Mega, a breadboard, some more jumper leads.

The good news is, Arduino is the most fun I have ever had programming. I did the hello world thing (made an LED blink), swiftly modified it so that it didn’t use crappy code (the “delay (1000);”), added some serial output and generally proved it all worked. The next step was to plug in the TFT LCD screen, and using the examples in the UTFT ibraries, had the display working in seconds! These libraries appear to be customised versions of the RinkyDink Electronics versions, and work out of the box for the purchased screen.

Caught in the excitement of the moment, I wrote a program (sketch in Arduino parlance) that read the A0 through A15 pins in a loop, and output the voltages on them to the Serial output (the computer screen). Two bits of cleverness here, firstly, while explicitly named A0, A1, A2, A3… A15 the analog pins can also be addressed as 0,1,2,3…15 when using the analogRead function and hence can be used within a loop as follows. This piece of code determines the last non zero pin, giving me the number of cells.

  //find the last none zero pin between A0 and A15 
  //to determine the number of cells in the battery
  noOfCells = 0;
  for (int thisPin = 0; thisPin < 16; thisPin++) {
    //read the next pin
    sensorValue = analogRead(thisPin);
    if (sensorValue > 0) {
      noOfCells = thisPin + 1;

Second bit of cleverness: while nothing is connected to these pins they actually have random values, so while not meaningful the numbers are not zero and change each time through the loop so giving good test data. Of course the code above will always return 16 as the number of cells, so this was not used during testing!

So having output voltages from 16 analog pins, I have the basis of a digital multi cell voltmeter.

The next step is to put the LCD back on, and start work on the graphical interface. This sounds quite daunting, but if you read the excellent UTFT manual, and check out the example code provided for the demonstration programs, it quickly becomes obvious that it is not a big deal at all! Bear in mind that this stage was reached within an hour or so of the postie delivering the parcel. Creating a graphical interface took another hour or so for the basics, and the fine tuning and tweaking has been going on ever since.

The TFT LCD comes with an SD card slot, and the libraries for the screen come with example programs for reading and writing from and to SD cards. A data logger was one of the programs, and this was the basis of the data logger I wrote to write the time and the voltages out to the SD card. Data logger written in 10 minutes.

So within a day I had written the software for a multi cell voltmeter, with a graphical user interface, that logs the voltages on each cell onto an SD card. While I have been programming for 43 years so far, C is a relatively new language to me, but in this case, taking chunks of code out of the examples given, and using code from some of the excellent Arduino support forums, it was a bit of a doddle really.

Graphical Interface

Graphical Interface

Since taking the picture above, the graphical interface has moved on a little. It now shows the same details for any number of cells up to 16, and shows a bar graph for the total voltage too. The bar graphs change colour, green if the cells are with the acceptable range, red if over charged or under charged. Number of cells and high and low thresholds are constants, but eventually number of cells will be detected when the battery is plugged in and the display adjusted accordingly.

Next step is the hardware side of it. The microprocessor and LCD are sorted, all I have to do is get the cell voltages from the battery into the analogue pins. Given that the cells are always in the range 2.9v to 3.7v, and the Arduino analog pins will handle 0-5v, it sounds easy. Unfortunately, the 12 cells are permanently bolted together into a battery of 12 cells in series, giving between 33 and 42v. So there is no common ground for each of the cells. I thought the voltage sensors mentioned in the previous post would do the job of isolating the Arduino from the battery, but these sensors also use a common ground, so would not work! Anybody need 16 Arduino voltage sensors?

So now comes the real learning! I have two ideas for the voltage sensor issue to try at this stage. The first and least favourite, is to get the voltage at each of the cells, based on the battery negative, so the voltages would be 3,6,9,12… to 36 or 48 depending on the number of cells, and individual voltages will have to be determined by subtracting the previous voltage. In order to achieve this, each voltage will have to go through a voltage divider to reduce it to less than +5v the Arduino expects. This will mean building an array of 12 or 16 voltage dividers, and adjusting the voltages in the Arduino code. This sounds like a great solution, very cheap, just 24 resistors and a bit of circuit board. Unfortunately, reducing the voltage by a factor of 10 or 12, means that the 10 bit value representing the voltage (i.e. 1024 discret voltages between 0 and 5 volts) has to cover effectively 50 or 60 volts rather than 5 volts. This means each bit now represents .0488 volts or so rather than .00488 volts. This may not sound a lot, but when you are looking at maximum voltages of 3.65 while charging a cell, discrete steps of 0.05 volts does not give a very clear indication of charging progress.

The second idea involves opto-couplers or opto-isolators. I read about these for the first time yesterday, and they are definitely my sort of technology! In effect they completely electrically isolate two circuits, but allow them to interact (one way only) optically! One circuit (in this case the battery side) is connected to a light emitting device – an LCD or similar, and the other side is an optical receiver of some sort (photo diode or photo transistor). All this is encased in a very small (1/3 of an inch) Integrated Circuit package and costs a matter of cents (or $1.40 NZ prices!). I have a few of these on order, along with a selection of resistors, and I look forward to seeing how accurate these devices are! There will be no loss of accuracy at the Arduino end, but if the opto-couplers are a bit crude it may be a problem. I would certainly feel safer with no electrical connection between the batteries and the micro processor in the Arduino. Of course I will need an array of 16 of these with associated resistors on both sides, but we are still looking at less than $2 per cell!
Update 18/10/2015 – it appears there are two types of opto couplers, those which are effectively just switches, and “linear opto couplers” which can handle voltage sensing among othef things. Unfortunately this type are quite expensive, maybe $15 each, multiply that by 16 and it’s quite a cost!

Full code to date can be seen here : multicell voltmeter 11 Nov 2015

Posted in Arduino, Computer Stuff, Electric Bikes, Programming
8 comments on “Multi Cell Voltmeter
  1. Dave says:

    Sorry Eduard, I never got anywhere with this, my knowledge of electronics failed me when it came to the common earth issue!

  2. eduardo says:

    Can anyone help to do this project? i am planning to create 14series of 18650 battery as a powerbank and i want a multi cell voltmeter in one display screen. please help what is the materials and also the program on how to do this.


  3. Dave says:

    I haven’t seen one yet, hence my desire to build one. There are 6 cell voltmeters around, which cycle through the 6 cells showing voltages. I connect two of these to each group of 6 cells, but it sends me crosseyed trying to watch the cell numbers and voltages on two devices and check for anomalies.
    I am about to start work again on mine, and if it works I will publish the schematics and programming of the final product.

  4. brett says:

    a simple compact voltage display for multicells in graphical form, which allows rapid comparison of cell
    voltage with one glance, is very much needed for electric bikes and other evs.
    Is this device available commercially? I’ve been looking for something like this for years.

  5. Dave says:

    Hi Paul,

    I have two 16 channel mux/demux breakout boards waiting to be connected to the arduino and the battery. However I have not made much progress lately, firstly I have been very busy with other projects and my shop, and just can’t face that much fine soldering, and secondly I have fixed the major problem with my batteries, which was poor connections through 45amp Anderson connectors, which were overheating and disconnecting until they cooled down. I hope to get back into it soon, and I will post an update when I do.


  6. Paul says:


    How did you end this project ?
    I’m in the same situation , monitoring upto 40+ cells.
    Used differential opams with high voltage common ground and a mux.


  7. Dave says:

    I have been thinking through what I wrote above, and am changing my mind to just use one MUX to switch the relevant negative connection to ground, doing away for the need for a MUX to switch the positive through to Pin A0. This means I will go back to using all 16 analog pins on the Arduino, but will have a spare MUX IC for when I build the second unit!

  8. Dave says:

    An update to the above.
    So I thought through all the options for connecting the battery to the Arduino, and other than the linear opto-isolators, everything was just a short circuit waiting to happen.
    While writing the above, I toyed with the idea of switching on and off each cell of the battery as required. Arduino is perfect for this sort of process, but the idea of creating a 32 switch circuit board was a bit horrendous, even with Shift registers etc. However I didn’t give up the idea, and have added knowledge of multiplexers (mux) and demultiplexers (demux) to my available techniques.
    A multiplexer is simply put a number of switched circuits controlled by a binary signal. There is plenty of stuff out there about them. The nice thing is that you don’t need a signal for each switch, for a two circuit mux you need one signal (0 or 1, low or high to choose which circuit is on), for a four circuit mux, you need just two signals (00, 01, 10,11 for each of the four switches), for an eight switch just three wires (000, 001, 010 … 111). For those who know binary when they see it, the binary signal input represents which circuit is switched on. In addition there is a ‘latch’ signal, which switches the whole thing on or off (off – all circuits are switched off). I looked at a few mux chips that are readily available in NZ, but most are just 8 channel e.g. 54HC151 or CD4051, or dual 4 channel (CD4052). These look perfectly usable, but would mean having two or more connected or programmed together to do the switching for 16 cells. From overseas, I can get some 16 channel MUX ICs which seem to fit the bill perfectly, the 74HC4067. These use a 4 bit signal to select which circuit is switched, and have a latch signal as above. This blog here or here has a really good description of what they are and how they work. Sparkfun have a really nice breakout board version. Another blog here.
    So these are on order, the code has been fixed – only one analog input pin is required now, but a clever bit of code is required to set the right pins high to switch each cell through to the analog pin as required. In addition to switching the positives through to pin a0, I will also be attempting to switch the negatives of each cell through to ground, completely isolating each cell at the time I wish to take its voltage.
    It all looks pretty straight forward to me, but then so did the 16 channel voltage splitter I built then tested with a single battery, before realising that it would just not do the job with a 16 cell battery.
    The nice thing about this plan, we lose the voltage splitters, in fact each cell will be measured directly through the 10 bit analog pin, so I get the full 10 bit precision (down to .004 of a volt). Shame its probably not going to be that accurate!
    See main post for latest version of code.

Leave a Reply

Your email address will not be published. Required fields are marked *