{"id":1626,"date":"2015-10-17T10:58:37","date_gmt":"2015-10-16T21:58:37","guid":{"rendered":"http:\/\/www.signsofsuccess.co.nz\/?p=1626"},"modified":"2023-02-22T19:49:09","modified_gmt":"2023-02-22T19:49:09","slug":"multi-cell-voltmeter","status":"publish","type":"post","link":"https:\/\/glover.gen.nz\/wordpress\/multi-cell-voltmeter\/","title":{"rendered":"Multi Cell Voltmeter"},"content":{"rendered":"<p>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.<\/p>\n<p>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&#8217;t use crappy code (the &#8220;delay (1000);&#8221;), 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 <a href=\"http:\/\/rinkydinkelectronics.com\/\">RinkyDink Electronics<\/a> versions, and work out of the box for the purchased screen.<\/p>\n<p>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&#8230; A15 the analog pins can also be addressed as 0,1,2,3&#8230;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.<\/p>\n<pre>  \/\/find the last none zero pin between A0 and A15 \r\n  \/\/to determine the number of cells in the battery\r\n  noOfCells = 0;\r\n  for (int thisPin = 0; thisPin &lt; 16; thisPin++) { \/\/read the next pin sensorValue = analogRead(thisPin); if (sensorValue &gt; 0) {\r\n      noOfCells = thisPin + 1;\r\n    }\r\n  }\r\n<\/pre>\n<p>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!<\/p>\n<p>So having output voltages from 16 analog pins, I have the basis of a digital multi cell voltmeter.<\/p>\n<p>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<a href=\"http:\/\/rinkydinkelectronics.com\/\" target=\"_blank\" rel=\"noopener\"> UTFT<\/a> 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.<\/p>\n<p>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.<\/p>\n<p>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.<\/p>\n<figure id=\"attachment_3931\" aria-describedby=\"caption-attachment-3931\" style=\"width: 225px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/glover.gen.nz\/wordpress\/wp-content\/uploads\/2015\/10\/IMG_1273-e1445034445832-scaled.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-3931\" src=\"https:\/\/glover.gen.nz\/wordpress\/wp-content\/uploads\/2015\/10\/IMG_1273-e1445034445832-225x300.jpg\" alt=\"\" width=\"225\" height=\"300\" srcset=\"https:\/\/glover.gen.nz\/wordpress\/wp-content\/uploads\/2015\/10\/IMG_1273-e1445034445832-225x300.jpg 225w, https:\/\/glover.gen.nz\/wordpress\/wp-content\/uploads\/2015\/10\/IMG_1273-e1445034445832-768x1024.jpg 768w, https:\/\/glover.gen.nz\/wordpress\/wp-content\/uploads\/2015\/10\/IMG_1273-e1445034445832-1152x1536.jpg 1152w, https:\/\/glover.gen.nz\/wordpress\/wp-content\/uploads\/2015\/10\/IMG_1273-e1445034445832-1536x2048.jpg 1536w, https:\/\/glover.gen.nz\/wordpress\/wp-content\/uploads\/2015\/10\/IMG_1273-e1445034445832-100x133.jpg 100w, https:\/\/glover.gen.nz\/wordpress\/wp-content\/uploads\/2015\/10\/IMG_1273-e1445034445832-150x200.jpg 150w, https:\/\/glover.gen.nz\/wordpress\/wp-content\/uploads\/2015\/10\/IMG_1273-e1445034445832-200x267.jpg 200w, https:\/\/glover.gen.nz\/wordpress\/wp-content\/uploads\/2015\/10\/IMG_1273-e1445034445832-300x400.jpg 300w, https:\/\/glover.gen.nz\/wordpress\/wp-content\/uploads\/2015\/10\/IMG_1273-e1445034445832-450x600.jpg 450w, https:\/\/glover.gen.nz\/wordpress\/wp-content\/uploads\/2015\/10\/IMG_1273-e1445034445832-600x800.jpg 600w, https:\/\/glover.gen.nz\/wordpress\/wp-content\/uploads\/2015\/10\/IMG_1273-e1445034445832-900x1200.jpg 900w, https:\/\/glover.gen.nz\/wordpress\/wp-content\/uploads\/2015\/10\/IMG_1273-e1445034445832-scaled.jpg 1920w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><figcaption id=\"caption-attachment-3931\" class=\"wp-caption-text\">Graphical Interface<\/figcaption><\/figure>\n<p>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.<\/p>\n<p>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?<\/p>\n<p>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&#8230; 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.<\/p>\n<p>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 &#8211; 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!<br \/>\nUpdate 18\/10\/2015 &#8211; it appears there are two types of opto couplers, those which are effectively just switches, and &#8220;linear opto couplers&#8221; which can handle voltage sensing among othef things. Unfortunately this type are quite expensive, maybe $15 each, multiply that by 16 and it&#8217;s quite a cost!<\/p>\n<p>Full code to date can be seen here : <a href=\"https:\/\/glover.gen.nz\/docs\/multicell-voltmeter-11-Nov-2015.txt\">multicell voltmeter 11 Nov 2015<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/glover.gen.nz\/wordpress\/multi-cell-voltmeter\/\"> <span class=\"screen-reader-text\">Multi Cell Voltmeter<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,4,5,9],"tags":[],"class_list":["post-1626","post","type-post","status-publish","format-standard","hentry","category-arduino","category-technical","category-electric-bikes","category-programming"],"_links":{"self":[{"href":"https:\/\/glover.gen.nz\/wordpress\/wp-json\/wp\/v2\/posts\/1626","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/glover.gen.nz\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/glover.gen.nz\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/glover.gen.nz\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/glover.gen.nz\/wordpress\/wp-json\/wp\/v2\/comments?post=1626"}],"version-history":[{"count":3,"href":"https:\/\/glover.gen.nz\/wordpress\/wp-json\/wp\/v2\/posts\/1626\/revisions"}],"predecessor-version":[{"id":4018,"href":"https:\/\/glover.gen.nz\/wordpress\/wp-json\/wp\/v2\/posts\/1626\/revisions\/4018"}],"wp:attachment":[{"href":"https:\/\/glover.gen.nz\/wordpress\/wp-json\/wp\/v2\/media?parent=1626"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/glover.gen.nz\/wordpress\/wp-json\/wp\/v2\/categories?post=1626"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/glover.gen.nz\/wordpress\/wp-json\/wp\/v2\/tags?post=1626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}