Theo Rossouw
Published

10 way Battery Condition Monitor

This is a unit that can monitor 10 single cells or 10 battery packs and print data in graphs on excel

IntermediateFull instructions provided5 hours477
10 way Battery Condition Monitor

Things used in this project

Hardware components

Adafruit adalogger 32u4 feather
×1
Adafruit ina219 Current sensor
×10
Adafruit DS3231 precision RTC
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×2
LED (generic)
LED (generic)
×11
Resistor 100 ohm
Resistor 100 ohm
×11
ds18b20 temperature sensor
×1
4k7 resistor
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematic diagram for data logger connections

You will need Express PCB & SCH to view this file

Code

Single cell data logger for 10 units

C/C++
Edded the code as you see fit to work for your needed requirements
/*************************************************************************** LIBRIARY FUNCTIONS *****************************************************************************/

#include <Wire.h>
#include <DS3231.h>
#include <Adafruit_INA219.h>
#include <OneWire.h>
#include <DallasTemperature.h>

/********************************************************************* CONTROL FUNCTION SETUP *******************************************************************************/

DS3231 clock;
RTCDateTime dt;

Adafruit_INA219 ina219_A(0x40);
Adafruit_INA219 ina219_B(0x41);
Adafruit_INA219 ina219_C(0x44);
Adafruit_INA219 ina219_D(0x45);
Adafruit_INA219 ina219_E(0x42);
Adafruit_INA219 ina219_F(0x43);
Adafruit_INA219 ina219_G(0x46);
Adafruit_INA219 ina219_H(0x47);
Adafruit_INA219 ina219_I(0x48);
Adafruit_INA219 ina219_J(0x49);

int ledState = LOW;

const int ledPin = 13;

void myLoop(void);

int wasItPressed1 = 0;
int buttonPin1 = 6;
int buttonState1 = 0; 

#define ONE_WIRE_BUS A0
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

/************************************************************************ VOID FUNCTION SETUP *******************************************************************************/

void setup()
{
  uint32_t currentFrequency;
  Serial.begin(9600);
  while(!Serial)
  {;}
  clock.begin();
  clock.setDateTime(__DATE__, __TIME__);
  clock.forceConversion();
  {
  Serial.print("Battery/Cell data logging & Management"); 
  Serial.println("");
  Serial.print("Ambient Temperature: ");Serial.print(clock.readTemperature()); Serial.print(" C");
  Serial.println("");
  dt = clock.getDateTime();
  Serial.print("Date & Time: ");
  Serial.print(dt.year);   Serial.print("-");
  Serial.print(dt.month);  Serial.print("-");
  Serial.print(dt.day);    Serial.print(" ");
  Serial.print(dt.hour);   Serial.print(":");
  Serial.print(dt.minute); Serial.print(":");
  Serial.print(dt.second); Serial.println("");
  Serial.println("");
  delay(100);
  {
  digitalWrite(LED_BUILTIN, HIGH); 
  delay(1000);   
  digitalWrite(LED_BUILTIN, LOW);  
  delay(1000); 
  {
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(buttonPin1, INPUT);
  {
  sensors.begin();
  ina219_A.begin();
  ina219_B.begin();
  ina219_C.begin();
  ina219_D.begin();
  ina219_E.begin();
  ina219_F.begin();
  ina219_G.begin();
  ina219_H.begin();
  ina219_I.begin();
  ina219_J.begin();
  // Serial.print("Bus Voltage");Serial.print("                                           ");Serial.print("Load Voltage");Serial.print("                                          ");Serial.print("Current");Serial.println("");
  }}}}}
  
void loop()
  {
   if(wasItPressed1 == 0) { 
      buttonState1 = digitalRead(buttonPin1);
   if (buttonState1 == HIGH) {
        wasItPressed1 = 1;
               myLoop();
               }
        } else { 
        myLoop();
          }
          }
          
/********************************************************************** VOID LOOP SETUP *************************************************************************************/
  
  void myLoop()
  {
 // Serial.print("************************** STARTING SESSION *****************************");
 // Serial.println("");
  clock.forceConversion();
 // Serial.print("Ambient Temperature: ");Serial.print(clock.readTemperature()); Serial.print(" C");
  //Serial.println("");
  delay(100);
  {
  dt = clock.getDateTime();
 // Serial.print("Time: ");
//  Serial.print(dt.hour);   Serial.print(":");
//  Serial.print(dt.minute); Serial.print(":");
 // Serial.print(dt.second); Serial.println("");
  delay(100);
  sensors.requestTemperatures();
//  Serial.print("Test Temperature :  ");
 // Serial.print(sensors.getTempCByIndex(0));Serial.print(" C");}
 // Serial.println("");
 // Serial.print("****************************************************************************");
 // Serial.println("");
  {
  digitalWrite(LED_BUILTIN, HIGH); 
  delay(1000);   
  digitalWrite(LED_BUILTIN, LOW);  
  delay(1000); 
  {

/**************************************************************** CURRENT SENSOR CH1 0X40 ************************************************************************************/    
  float shuntvoltage_A = 0;
  float busvoltage_A = 0;
  float current_mA_A = 0;
  float loadvoltage_A = 0;

  shuntvoltage_A = ina219_A.getShuntVoltage_mV();
  busvoltage_A = ina219_A.getBusVoltage_V();
  current_mA_A = ina219_A.getCurrent_mA();
  loadvoltage_A = busvoltage_A + (shuntvoltage_A / 1000);

/*
 Serial.print("Ch1");
 Serial.println("");
 Serial.print("BV:   "); Serial.print(busvoltage_A); Serial.println(" V");
 
 Serial.print("SV: "); Serial.print(shuntvoltage_A); Serial.println(" mV");
 Serial.print("LV:  "); Serial.print(loadvoltage_A); Serial.println(" V");
 Serial.print("Cr:       "); Serial.print(current_mA_A); Serial.println(" mA");
 Serial.println("");
 Serial.print("****************************************************************************");
 Serial.println("");
 delay(500);
 digitalWrite(LED_BUILTIN, HIGH);
 delay(500);
 digitalWrite(LED_BUILTIN, LOW);
 delay(500); 
*/
/**************************************************************** CURRENT SENSOR CH2 0X41 **********************************************************************************/
  float shuntvoltage_B = 0;
  float busvoltage_B = 0;
  float current_mA_B = 0;
  float loadvoltage_B = 0;

  shuntvoltage_B = ina219_B.getShuntVoltage_mV();
  busvoltage_B = ina219_B.getBusVoltage_V();
  current_mA_B = ina219_B.getCurrent_mA();
  loadvoltage_B = busvoltage_B + (shuntvoltage_B / 1000);
/*
  Serial.print("Channel 2");
  Serial.println("");
  Serial.print("Bus Voltage:   "); Serial.print(busvoltage_B); Serial.println(" V");
  Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage_B); Serial.println(" mV");
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage_B); Serial.println(" V");
  Serial.print("Current:       "); Serial.print(current_mA_B); Serial.println(" mA");
  Serial.println("");
  Serial.print("****************************************************************************");
  Serial.println("");
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500); 
*/
  
/**************************************************************** CURRENT SENSOR CH3 0X44 **********************************************************************************/
  float shuntvoltage_C = 0;
  float busvoltage_C = 0;
  float current_mA_C = 0;
  float loadvoltage_C = 0;

  shuntvoltage_C = ina219_C.getShuntVoltage_mV();
  busvoltage_C = ina219_C.getBusVoltage_V();
  current_mA_C = ina219_C.getCurrent_mA();
  loadvoltage_C = busvoltage_C + (shuntvoltage_C / 1000);
/*
  Serial.print("Channel 3");
  Serial.println("");
  Serial.print("Bus Voltage:   "); Serial.print(busvoltage_C); Serial.println(" V");
  Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage_C); Serial.println(" mV");
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage_C); Serial.println(" V");
  Serial.print("Current:       "); Serial.print(current_mA_C); Serial.println(" mA");
  Serial.println("");
  Serial.print("****************************************************************************");
  Serial.println("");
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);

  */
/**************************************************************** CURRENT SENSOR CH4 0X45 ***********************************************************************************/
  float shuntvoltage_D = 0;
  float busvoltage_D = 0;
  float current_mA_D = 0;
  float loadvoltage_D = 0;

  shuntvoltage_D = ina219_D.getShuntVoltage_mV();
  busvoltage_D = ina219_D.getBusVoltage_V();
  current_mA_D = ina219_D.getCurrent_mA();
  loadvoltage_D = busvoltage_D + (shuntvoltage_D / 1000);
/*
  Serial.print("Channel 4");
  Serial.println("");
  Serial.print("Bus Voltage:   "); Serial.print(busvoltage_D); Serial.println(" V");
  Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage_D); Serial.println(" mV");
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage_D); Serial.println(" V");
  Serial.print("Current:       "); Serial.print(current_mA_D); Serial.println(" mA");
  Serial.println("");
  Serial.print("****************************************************************************");
  Serial.println(""); 
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500); 

  */
/**************************************************************** CURRENT SENSOR CH5 0X42 ***********************************************************************************/
  float shuntvoltage_E = 0;
  float busvoltage_E = 0;
  float current_mA_E = 0;
  float loadvoltage_E = 0;

  shuntvoltage_E = ina219_E.getShuntVoltage_mV();
  busvoltage_E = ina219_E.getBusVoltage_V();
  current_mA_E = ina219_E.getCurrent_mA();
  loadvoltage_E = busvoltage_E + (shuntvoltage_E / 1000);
/*
  Serial.print("Channel 5");
  Serial.println("");  
  Serial.print("Bus Voltage:   "); Serial.print(busvoltage_E); Serial.println(" V");
  Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage_E); Serial.println(" mV");
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage_E); Serial.println(" V");
  Serial.print("Current:       "); Serial.print(current_mA_E); Serial.println(" mA");
  Serial.println("");
  Serial.print("****************************************************************************");
  Serial.println("");  
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);

  */
/**************************************************************** CURRENT SENSOR CH6 0X43 ***********************************************************************************/
  float shuntvoltage_F = 0;
  float busvoltage_F = 0;
  float current_mA_F = 0;
  float loadvoltage_F = 0;

  shuntvoltage_F = ina219_F.getShuntVoltage_mV();
  busvoltage_F = ina219_F.getBusVoltage_V();
  current_mA_F = ina219_F.getCurrent_mA();
  loadvoltage_F = busvoltage_F + (shuntvoltage_F / 1000);
/*
  Serial.print("Channel 6");
  Serial.println("");  
  Serial.print("Bus Voltage:   "); Serial.print(busvoltage_F); Serial.println(" V");
  Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage_F); Serial.println(" mV");
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage_F); Serial.println(" V");
  Serial.print("Current:       "); Serial.print(current_mA_F); Serial.println(" mA");
  Serial.println("");
  Serial.print("****************************************************************************");
  Serial.println("");  
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);

  */
/**************************************************************** CURRENT SENSOR CH7 0X46 ***********************************************************************************/
  float shuntvoltage_G = 0;
  float busvoltage_G = 0;
  float current_mA_G = 0;
  float loadvoltage_G = 0;

  shuntvoltage_G = ina219_G.getShuntVoltage_mV();
  busvoltage_G = ina219_G.getBusVoltage_V();
  current_mA_G = ina219_G.getCurrent_mA();
  loadvoltage_G = busvoltage_G + (shuntvoltage_G / 1000);
/*
  Serial.print("Channel 7");
  Serial.println("");  
  Serial.print("Bus Voltage:   "); Serial.print(busvoltage_G); Serial.println(" V");
  Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage_G); Serial.println(" mV");
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage_G); Serial.println(" V");
  Serial.print("Current:       "); Serial.print(current_mA_G); Serial.println(" mA");
  Serial.println("");
  Serial.print("****************************************************************************");
  Serial.println("");
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);

  */
/**************************************************************** CURRENT SENSOR CH8 0X47 ***********************************************************************************/
  float shuntvoltage_H = 0;
  float busvoltage_H = 0;
  float current_mA_H = 0;
  float loadvoltage_H = 0;

  shuntvoltage_H = ina219_H.getShuntVoltage_mV();
  busvoltage_H = ina219_H.getBusVoltage_V();
  current_mA_H = ina219_H.getCurrent_mA();
  loadvoltage_H = busvoltage_H + (shuntvoltage_H / 1000);
/*
  Serial.print("Channel 8");
  Serial.println("");  
  Serial.print("Bus Voltage:   "); Serial.print(busvoltage_H); Serial.println(" V");
  Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage_H); Serial.println(" mV");
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage_H); Serial.println(" V");
  Serial.print("Current:       "); Serial.print(current_mA_H); Serial.println(" mA");
  Serial.println("");
  Serial.print("****************************************************************************");
  Serial.println("");  
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
*/
  
/**************************************************************** CURRENT SENSOR CH9 0X48 ***********************************************************************************/
  float shuntvoltage_I = 0;
  float busvoltage_I = 0;
  float current_mA_I = 0;
  float loadvoltage_I = 0;

  shuntvoltage_I = ina219_I.getShuntVoltage_mV();
  busvoltage_I = ina219_I.getBusVoltage_V();
  current_mA_I = ina219_I.getCurrent_mA();
  loadvoltage_I = busvoltage_I + (shuntvoltage_I / 1000);
/*
  Serial.print("Channel 9");
  Serial.println(""); 
  Serial.print("Bus Voltage:   "); Serial.print(busvoltage_I); Serial.println(" V");
  Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage_I); Serial.println(" mV");
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage_I); Serial.println(" V");
  Serial.print("Current:       "); Serial.print(current_mA_I); Serial.println(" mA");
  Serial.println("");
  Serial.print("****************************************************************************");
  Serial.println("");
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500); 
  */
/**************************************************************** CURRENT SENSOR CH10 0X49 **********************************************************************************/
  float shuntvoltage_J = 0;
  float busvoltage_J = 0;
  float current_mA_J = 0;
  float loadvoltage_J = 0;

  shuntvoltage_J = ina219_J.getShuntVoltage_mV();
  busvoltage_J = ina219_J.getBusVoltage_V();
  current_mA_J = ina219_J.getCurrent_mA();
  loadvoltage_J = busvoltage_J + (shuntvoltage_J / 1000);
/*
  Serial.print("Channel 10");
  Serial.println(""); 
  Serial.print("Bus Voltage:   "); Serial.print(busvoltage_J); Serial.println(" V");
  Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage_J); Serial.println(" mV");
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage_J); Serial.println(" V");
  Serial.print("Current:       "); Serial.print(current_mA_J); Serial.println(" mA");
  Serial.println("");
  Serial.print("************************ END OF SESSION **********************************");
  Serial.println("");
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  {
  */
/**************************************************************** Excel layout graph  ************************************************************************************/ 

 Serial.print(busvoltage_A);
 Serial.print("   ");
 Serial.print(busvoltage_B);
 Serial.print("   ");
 Serial.print(busvoltage_C);
 Serial.print("   ");
 Serial.print(busvoltage_D);
 Serial.print("   ");
 Serial.print(busvoltage_E);
 Serial.print("   ");
 Serial.print(busvoltage_F);
 Serial.print("   ");
 Serial.print(busvoltage_G);
 Serial.print("   ");
 Serial.print(busvoltage_H);
 Serial.print("   ");
 Serial.print(busvoltage_I);
 Serial.print("   ");
 Serial.print(busvoltage_J);
 Serial.print("          ");
 Serial.print(loadvoltage_A);
 Serial.print("   ");
 Serial.print(loadvoltage_B);
 Serial.print("   ");
 Serial.print(loadvoltage_C);
 Serial.print("   ");
 Serial.print(loadvoltage_D);
 Serial.print("   ");
 Serial.print(loadvoltage_E);
 Serial.print("   ");
 Serial.print(loadvoltage_F);
 Serial.print("   ");
 Serial.print(loadvoltage_G);
 Serial.print("   ");
 Serial.print(loadvoltage_H);
 Serial.print("   ");
 Serial.print(loadvoltage_I);
 Serial.print("   ");
 Serial.print(loadvoltage_J);
 Serial.print("          ");
 Serial.print(current_mA_A,2);
 Serial.print("   ");
 Serial.print(current_mA_B,2);
 Serial.print("   ");
 Serial.print(current_mA_C,2);
 Serial.print("   ");
 Serial.print(current_mA_D,2);
 Serial.print("   ");
 Serial.print(current_mA_E,2);
 Serial.print("   ");
 Serial.print(current_mA_F,2);
 Serial.print("   ");
 Serial.print(current_mA_G,2);
 Serial.print("   ");
 Serial.print(current_mA_H,2);
 Serial.print("   ");
 Serial.print(current_mA_I,2);
 Serial.print("     ");
 Serial.print(current_mA_J,2);
 Serial.print("        ");
 Serial.print(sensors.getTempCByIndex(0));
 Serial.print("     ");
 Serial.print(dt.hour);   Serial.print(":");
 Serial.print(dt.minute); Serial.print(":");
 Serial.print(dt.second);
 Serial.println("");

/****************************************************************************************************************************************************************************/
  digitalWrite(ledPin, HIGH);
  delay(1000);
  digitalWrite(ledPin, LOW);
  delay(1000);
}}}}

/****************************************************************************************************************************************************************************/

Credits

Theo Rossouw

Theo Rossouw

0 projects • 7 followers
Hi i am an junior Electronics and Software engineer that works in Benoni South Africa for a company that develop long term battery solutions

Comments