//Cedric Lemle //1-16 - channel Lithium Battery capacity tester. //schematic: battery"+" --- resistor pin1 --- resistor pin2 --- mosfet drain --- mosfet source --- battery"-" //battery"+" to resistor pin1 = measure point "bat(c" // // //Take care if you use the USB input to power the Arduino. If you do so you won´t have a constant 5V for //the internal reference. This will cause wrong measurements. Use the Vin pin instead with an external power supply. The onboard 7805 voltage regulator has a constant //voltage output. Measure if there are actually 5v! If there are for example 4,8V on the "5V Pin" and your Arduino measures //a Cell with 3,7V then your Arduino will measure only 3.552V ! [ (3,7/5)*4,8 ]. You can adjust the //"offsetvoltage" to the value yo need. For example: if you measure 4,92 V on the "5V Pin" //then you have to adjust the offset value to "4920" //I used the internal pull up resistors to have defined levels. Because of this you will see "5000mV" in the Display if no battery is connected. //You can use external pull-down resitors (20-50kohm) if you want to get "0mV" displayed if no battery is connected. In this case you have to //rewrite the code. #include // library for LCD Display --> deactivate if you are using I2C LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // Set the LCD address --> deactivate if you are using I2C // Values to adjust float batnumber = 16; // adjust between 1-16 to set your number of batteries int intervaldisp = 1000; // refresh rate in ms for Display - 1000 is standard int interval = 1000; // refresh rate in ms for Batterys - 1000 is standard int intervalserial = 1500; // refresh rate in ms for Serial output - 2500 is standard int disp = 0; // 0 = 16x2 Display 1 = 20x4 Display int fetoffset[17] = {16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16}; // voltage measured at "SOURCE - DRAIN"--> first number = Fet1 // second number = Fet2 int fet[17] = {22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52}; // output pins for your mosfets 22 = Bat1 // 24 = Bat2 etc. int bat[17] = {A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15}; // input pins for Measuring Bat voltage A0 = Bat1 // A1 = Bat2 etc. float load[17] = {1.6,1.6,1.6,1.6,1.6,1.6,1.6,1.6,1.6,1.6,1,1,1,1,1,1,}; // Values of your Load in "ohm" --- use "." instead of "," for a point number --> first number = Bat1 // second number = Bat2 etc. float offset = 5013; // offset value for 5V onboard --- type in the voltage you measured at the "5v" pin of your arduino float cutoffmin = 3000; // Lithium Voltage to stop discharging --- 3000 = 3,000V float cutoffmax = 4300; // Lithium Voltage to recognize there is no Battery inserted // Values not to change int c = 0; // value for setting Battery Number int x[17] = {0}; // value for correct calculating int dispchange = 0; // data for changing displays boolean done[17] = {false}; // Memory if Battery is done with discharging or not float totalcurrent[17] = {0.00}; // contents the discharged mAh float valbat[17] = {0}; // contents the bat voltage float valshunt[17] = {0}; // contents the shunt voltage unsigned long premillis[17] = {0}; // for calculating mAh unsigned long millispassed[17] = {0}; // for calculating mAh unsigned long currentmillis[18] = {0}; // for refreshing display/batterys unsigned long previousmillis[18] = {0}; // for refreshing display/batterys unsigned long start[17] = {0}; // for passed time since discharge began unsigned long duration[17] = {0}; // for passed time since discharge began String stat[17] = "wait"; // for saving actual status void setup() { Serial.begin(9600); for (int p = 0; p < 15; p++) {pinMode(fet[p], OUTPUT), pinMode(bat[p], INPUT), digitalWrite(bat[p], HIGH);} // declare the inputs/outputs and set all inputs "HIGH" if (disp == 0) // Display = 1602 { lcd.begin(16, 2);// set up the LCD's number of rows and columns: lcd.print(" 1-16 Cell "); // Print a message to the LCD. lcd.setCursor(0, 1);// Second line first char lcd.print(" Capacity Tester"); // Print a message to the LCD. } else if (disp == 1) // Display = 2004 { lcd.begin(24, 4);// set up the LCD's number of rows and columns: lcd.print("********************"); // Print a message to the LCD. lcd.setCursor(0, 1);// Second line first char lcd.print(" 1-16 Cell"); // Print a message to the LCD. lcd.setCursor(0, 2);// Second line first char lcd.print(" Capacity Tester"); // Print a message to the LCD. lcd.setCursor(0, 3);// Second line first char lcd.print("********************"); } Serial.print("16 Channel 18650 Discharger"); delay(2000); lcd.clear(); // clear the Display } void loop() { ///BAT1-16//////////////////////////////////////////////////////////////////////////////// for (c = 0; c != 16; c++) { valbat[c] = analogRead(bat[c]); // read the value from the sensor: valbat[c] = offset / 1024.0 * valbat[c]; // convert 0-1023 to 0-5000 mv currentmillis[c] = millis(); // save actual ms time in "currentmillis[n]" if (currentmillis[c] - previousmillis[c] >= interval) // check what time has passed and compare it with "interval" { previousmillis[c] = currentmillis[c]; // save "currentmillis[n]" in "previousmillis[n]" if (valbat[c] > 4300 && valbat[c] < 6000) // check if a battery is connected. 5000mV will be displayed if nothing is connected { done[c] = false; // reset "done" totalcurrent[c] = 0; // reset the counted mAh digitalWrite(fet[c],LOW); // turn off the mosfet x[c] = 1; // data storage for correct calculating. Without there will be problems with the countet mAh. stat[c] = "wait"; // status which will be displayed start[c] = 0; // data storage for time counting. Reset Data for next Battery duration[c] = 0; // time counting which will be displayed. Reset Data for next battery } else if (valbat[c] > cutoffmin && !done[c]) // check if battery voltage is higher than your cutoff voltage and if its not done { digitalWrite(fet[c], HIGH); // enable FET[n] valbat[c] = analogRead(bat[c]); // read voltage of the Battery valbat[c] = offset / 1024.0 * valbat[c]; // convert 0-1023 to 0-5000 mv premillis[c] = millis(); // save the past time if (x[c] == 1) // save premllis in millispassed in the first round. Otherwise a wrong calculation would be the effect { millispassed[c] = premillis[c]; // save premillis in millispassed } totalcurrent[c] = totalcurrent[c] + (((valbat[c] - fetoffset[c]) * 5000 / offset) / load[c] / 3600 * ((premillis[c] - millispassed[c]) / 1000.0)); // this is the caculating of the current per passed time millispassed[c] = millis(); // save the past time x[c] = 0; // x = 0 --> next round "millispassed[c] = premillis[c]; " willl be ignored if (start[c] == 0) // make sure to subtract passed time till the discharging begins {start[c]= millis();} // save actual time in "start[n]" duration[c] = millis() - start[c]; // save pased time since discharging began stat[c] = "run "; // write actual status } else { done[c] = true; // tell the software above the battery is empty digitalWrite(fet[c],LOW); // turn off the mosfet stat[c] = "done"; // write actual status } } } ///Display output////////////////////////////////////////////////////////////////////// currentmillis[16] = millis(); // save actual time in currentmillis[n] if (currentmillis[16] - previousmillis[16] >= intervaldisp) // check what time has passed and compare it with "intervaldisp" { previousmillis[16] = currentmillis[16]; // save "currentmillis[n]" in "previousmillis[n]" ///1602 Display//////////////////////////////////////////////////////////////////////// if (disp == 0) //0 = 1602 display //1 = 2004 Display { if (dispchange == 0) // first site of the Display if(currentmillis > previousmillis1) { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("01="), lcd.print(totalcurrent[0], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(11, 0), lcd.print(duration[0]/1000), lcd.setCursor(15, 0), lcd.print("s"); lcd.setCursor(0, 1), lcd.print("01="), lcd.print(valbat[0], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(11, 1), lcd.print(stat[0]); } else if (dispchange == 1) // second site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("02="), lcd.print(totalcurrent[1], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(11, 0), lcd.print(duration[1]/1000), lcd.setCursor(15, 0), lcd.print("s"); lcd.setCursor(0, 1), lcd.print("02="), lcd.print(valbat[1], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(11, 1), lcd.print(stat[1]); } else if (dispchange == 2) // third site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("03="), lcd.print(totalcurrent[2], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(11, 0), lcd.print(duration[2]/1000), lcd.setCursor(15, 0), lcd.print("s"); lcd.setCursor(0, 1), lcd.print("03="), lcd.print(valbat[2], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(11, 1), lcd.print(stat[2]); } else if (dispchange == 3) // fourth site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("04="), lcd.print(totalcurrent[3], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(11, 0), lcd.print(duration[3]/1000), lcd.setCursor(15, 0), lcd.print("s"); lcd.setCursor(0, 1), lcd.print("04="), lcd.print(valbat[3], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(11, 1), lcd.print(stat[3]); } else if (dispchange == 4) // fifth site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("05="), lcd.print(totalcurrent[4], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(11, 0), lcd.print(duration[4]/1000), lcd.setCursor(15, 0), lcd.print("s"); lcd.setCursor(0, 1), lcd.print("05="), lcd.print(valbat[4], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(11, 1), lcd.print(stat[4]); } else if (dispchange == 5) // sixth site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("06="), lcd.print(totalcurrent[5], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(11, 0), lcd.print(duration[5]/1000), lcd.setCursor(15, 0), lcd.print("s"); lcd.setCursor(0, 1), lcd.print("06="), lcd.print(valbat[5], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(11, 1), lcd.print(stat[5]); } else if (dispchange == 6) // seventh site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("07="), lcd.print(totalcurrent[6], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(11, 0), lcd.print(duration[6]/1000), lcd.setCursor(15, 0), lcd.print("s"); lcd.setCursor(0, 1), lcd.print("07="), lcd.print(valbat[6], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(11, 1), lcd.print(stat[6]); } else if (dispchange == 7) // eight site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("08="), lcd.print(totalcurrent[7], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(11, 0), lcd.print(duration[7 ]/1000), lcd.setCursor(15, 0), lcd.print("s"); lcd.setCursor(0, 1), lcd.print("08="), lcd.print(valbat[7], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(11, 1), lcd.print(stat[7]); } else if (dispchange == 8) // nineth site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("09="), lcd.print(totalcurrent[8], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(11, 0), lcd.print(duration[8]/1000), lcd.setCursor(15, 0), lcd.print("s"); lcd.setCursor(0, 1), lcd.print("09="), lcd.print(valbat[8], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(11, 1), lcd.print(stat[8]); } else if (dispchange == 9) // tenth site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("10="), lcd.print(totalcurrent[9], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(11, 0), lcd.print(duration[9]/1000), lcd.setCursor(15, 0), lcd.print("s"); lcd.setCursor(0, 1), lcd.print("10="), lcd.print(valbat[9], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(11, 1), lcd.print(stat[9]); } else if (dispchange == 10) // eleventh site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("11="), lcd.print(totalcurrent[10], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(11, 0), lcd.print(duration[10]/1000), lcd.setCursor(15, 0), lcd.print("s"); lcd.setCursor(0, 1), lcd.print("11="), lcd.print(valbat[10], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(11, 1), lcd.print(stat[10]); } else if (dispchange == 11) // twelfth site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("12="), lcd.print(totalcurrent[11], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(11, 0), lcd.print(duration[11]/1000), lcd.setCursor(15, 0), lcd.print("s"); lcd.setCursor(0, 1), lcd.print("12="), lcd.print(valbat[11], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(11, 1), lcd.print(stat[11]); } else if (dispchange == 12) // thirteenth site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("13="), lcd.print(totalcurrent[12], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(11, 0), lcd.print(duration[12]/1000), lcd.setCursor(15, 0), lcd.print("s"); lcd.setCursor(0, 1), lcd.print("13="), lcd.print(valbat[12], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(11, 1), lcd.print(stat[12]); } else if (dispchange == 13) // fourteenth site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("14="), lcd.print(totalcurrent[13], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(11, 0), lcd.print(duration[13]/1000), lcd.setCursor(15, 0), lcd.print("s"); lcd.setCursor(0, 1), lcd.print("14="), lcd.print(valbat[13], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(11, 1), lcd.print(stat[13]); } else if (dispchange == 14) // fifteenth site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("15="), lcd.print(totalcurrent[14], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(11, 0), lcd.print(duration[14]/1000), lcd.setCursor(15, 0), lcd.print("s"); lcd.setCursor(0, 1), lcd.print("15="), lcd.print(valbat[14], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(11, 1), lcd.print(stat[14]); } else if (dispchange == 15) // sixteenth site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("16="), lcd.print(totalcurrent[15], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(11, 0), lcd.print(duration[15]/1000), lcd.setCursor(15, 0), lcd.print("s"); lcd.setCursor(0, 1), lcd.print("16="), lcd.print(valbat[15], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(11, 1), lcd.print(stat[15]); } } ///2004 Display//////////////////////////////////////////////////////////////////////// if (disp == 1) //0 = 1602 display //1 = 2004 Display { if (dispchange == 0) // first site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("01="), lcd.print(totalcurrent[0], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(13, 0), lcd.print(duration[0]/1000), lcd.setCursor(17, 0), lcd.print("sec"); lcd.setCursor(0, 1), lcd.print("01="), lcd.print(valbat[0], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(13, 1), lcd.print(stat[0]); lcd.setCursor(0, 2), lcd.print("02="), lcd.print(totalcurrent[1], 0), lcd.setCursor(7, 2), lcd.print("mAh"), lcd.setCursor(13, 2), lcd.print(duration[1]/1000), lcd.setCursor(17, 2), lcd.print("sec"); lcd.setCursor(0, 3), lcd.print("02="), lcd.print(valbat[1], 0), lcd.setCursor(7, 3), lcd.print("mV"), lcd.setCursor(13, 3), lcd.print(stat[1]); } if (dispchange == 1) // second site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("03="), lcd.print(totalcurrent[2], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(13, 0), lcd.print(duration[2]/1000), lcd.setCursor(17, 0), lcd.print("sec"); lcd.setCursor(0, 1), lcd.print("03="), lcd.print(valbat[2], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(13, 1), lcd.print(stat[2]); lcd.setCursor(0, 2), lcd.print("04="), lcd.print(totalcurrent[3], 0), lcd.setCursor(7, 2), lcd.print("mAh"), lcd.setCursor(13, 2), lcd.print(duration[3]/1000), lcd.setCursor(17, 2), lcd.print("sec"); lcd.setCursor(0, 3), lcd.print("04="), lcd.print(valbat[3], 0), lcd.setCursor(7, 3), lcd.print("mV"), lcd.setCursor(13, 3), lcd.print(stat[3]); } if (dispchange == 2) // third site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("05="), lcd.print(totalcurrent[4], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(13, 0), lcd.print(duration[4]/1000), lcd.setCursor(17, 0), lcd.print("sec"); lcd.setCursor(0, 1), lcd.print("05="), lcd.print(valbat[4], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(13, 1), lcd.print(stat[4]); lcd.setCursor(0, 2), lcd.print("06="), lcd.print(totalcurrent[5], 0), lcd.setCursor(7, 2), lcd.print("mAh"), lcd.setCursor(13, 2), lcd.print(duration[5]/1000), lcd.setCursor(17, 2), lcd.print("sec"); lcd.setCursor(0, 3), lcd.print("06="), lcd.print(valbat[5], 0), lcd.setCursor(7, 3), lcd.print("mV"), lcd.setCursor(13, 3), lcd.print(stat[5]); } if (dispchange == 3) // fourth site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("07="), lcd.print(totalcurrent[6], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(13, 0), lcd.print(duration[6]/1000), lcd.setCursor(17, 0), lcd.print("sec"); lcd.setCursor(0, 1), lcd.print("07="), lcd.print(valbat[6], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(13, 1), lcd.print(stat[6]); lcd.setCursor(0, 2), lcd.print("08="), lcd.print(totalcurrent[7], 0), lcd.setCursor(7, 2), lcd.print("mAh"), lcd.setCursor(13, 2), lcd.print(duration[7]/1000), lcd.setCursor(17, 2), lcd.print("sec"); lcd.setCursor(0, 3), lcd.print("08="), lcd.print(valbat[7], 0), lcd.setCursor(7, 3), lcd.print("mV"), lcd.setCursor(13, 3), lcd.print(stat[7]); } if (dispchange == 4) // fifth site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("09="), lcd.print(totalcurrent[8], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(13, 0), lcd.print(duration[8]/1000), lcd.setCursor(17, 0), lcd.print("sec"); lcd.setCursor(0, 1), lcd.print("09="), lcd.print(valbat[8], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(13, 1), lcd.print(stat[8]); lcd.setCursor(0, 2), lcd.print("10="), lcd.print(totalcurrent[9], 0), lcd.setCursor(7, 2), lcd.print("mAh"), lcd.setCursor(13, 2), lcd.print(duration[9]/1000), lcd.setCursor(17, 2), lcd.print("sec"); lcd.setCursor(0, 3), lcd.print("10="), lcd.print(valbat[9], 0),lcd.setCursor(7, 3), lcd.print("mV"), lcd.setCursor(13, 3), lcd.print(stat[9]); } if (dispchange == 5) // sixth site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("11="), lcd.print(totalcurrent[10], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(13, 0), lcd.print(duration[10]/1000), lcd.setCursor(17, 0), lcd.print("sec"); lcd.setCursor(0, 1), lcd.print("11="), lcd.print(valbat[10], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(13, 1), lcd.print(stat[10]); lcd.setCursor(0, 2), lcd.print("12="), lcd.print(totalcurrent[11], 0), lcd.setCursor(7, 2), lcd.print("mAh"), lcd.setCursor(13, 2), lcd.print(duration[11]/1000), lcd.setCursor(17, 2), lcd.print("sec"); lcd.setCursor(0, 3), lcd.print("12="), lcd.print(valbat[11], 0), lcd.setCursor(7, 3), lcd.print("mV"), lcd.setCursor(13, 3), lcd.print(stat[11]); } if (dispchange == 6) // seventh site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("13="), lcd.print(totalcurrent[12], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(13, 0), lcd.print(duration[12]/1000), lcd.setCursor(17, 0), lcd.print("sec"); lcd.setCursor(0, 1), lcd.print("13="), lcd.print(valbat[12], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(13, 1), lcd.print(stat[12]); lcd.setCursor(0, 2), lcd.print("14="), lcd.print(totalcurrent[13], 0), lcd.setCursor(7, 2), lcd.print("mAh"), lcd.setCursor(13, 2), lcd.print(duration[13]/1000), lcd.setCursor(17, 2), lcd.print("sec"); lcd.setCursor(0, 3), lcd.print("14="), lcd.print(valbat[13], 0), lcd.setCursor(7, 3), lcd.print("mV"), lcd.setCursor(13, 3), lcd.print(stat[13]); } if (dispchange == 7) // eighth site of the Display { lcd.clear(); // print Bat Data to the Display lcd.setCursor(0, 0), lcd.print("15="), lcd.print(totalcurrent[14], 0), lcd.setCursor(7, 0), lcd.print("mAh"), lcd.setCursor(13, 0), lcd.print(duration[14]/1000), lcd.setCursor(17, 0), lcd.print("sec"); lcd.setCursor(0, 1), lcd.print("15="), lcd.print(valbat[14], 0), lcd.setCursor(7, 1), lcd.print("mV"), lcd.setCursor(13, 1), lcd.print(stat[14]); lcd.setCursor(0, 2), lcd.print("16="), lcd.print(totalcurrent[15], 0), lcd.setCursor(7, 2), lcd.print("mAh"), lcd.setCursor(13, 2), lcd.print(duration[15]/1000), lcd.setCursor(17, 2), lcd.print("sec"); lcd.setCursor(0, 3), lcd.print("16="), lcd.print(valbat[15], 0), lcd.setCursor(7, 3), lcd.print("mV"), lcd.setCursor(13, 3), lcd.print(stat[15]); } } if (disp == 0) // this is for display changing and set maximum number of Display. If "batnumber = 5 --> bat 1 - bat 5 will be showed { if (batnumber >= 2) { for (dispchange < 17; dispchange++;) { if (dispchange >= batnumber) { dispchange = 0; } break; } } } else if (disp == 1) // this is for display changing and set maximum number of Display. If "batnumber = 5 --> bat 1 - bat 6 will be showed { for (dispchange < 9; dispchange++;) { if (dispchange >= (batnumber/2)) { dispchange = 0; } break; } if (batnumber <= 1) {dispchange = 0;} } } ///Serial output////////////////////////////////////////////////////////////////////// currentmillis[17] = millis(); // save actual time in currentmillis[n] if (currentmillis[17] - previousmillis[17] >= intervalserial) // check what time has passed and compare it with "intervaldisp" { previousmillis[17] = currentmillis[17]; // save "currentmillis[n]" in "previousmillis[n]" for (int a = 0; a < batnumber; a++) { Serial.print("Bat"), Serial.println(a+1); Serial.print(valbat[a]), Serial.println("mV"); Serial.print(totalcurrent[a]), Serial.println("mAh"); Serial.println(""); } } }