Click here to Skip to main content
15,392,679 members
Articles / Internet of Things / Arduino
Posted 20 Oct 2014


56 bookmarked

Smart Monitor for Automotive Battery

Rate me:
Please Sign up or sign in to vote.
4.85/5 (46 votes)
20 Oct 2014Ms-PL16 min read
Demonstrates battmon tool for automotive battery live status, smart monitoring and stand-alone logging

Image 1


This article demonstrates a combination of hardware and software to create a practical mobile engineering tool to monitor and check health along with many other parameters of Lead acid battery, automotive battery was chosen as an easy example. Many modern types of batteries (such as lithium batteries) are designed with a smart battery chip built in, which provides a great deal of information about their state of charge and so on. Lead acid batteries are commonly made simple and lack any kind of smart battery chip in them, leaving the automotive shop with the task to test battery.

Yet there is enough room in any motor vehicle to have a tiny sensor which can monitor lead acid battery at real time, so a small project was created to get proper hardware and software to work together to provide smart battery like features for automotive battery.

A simple and non-intrusive approach was used so that no cables or wires are to be cut or disconnected in the automobile, only probes are attached to battery terminals, and one non-contact current sensor on battery cable.


Smart battery chip as it commonly is seen in modern batteries such as lithium batteries continuously collects three run time parameters: battery voltage, battery current, and battery temperature. Depending on the capabilities of smart battery chip, it may send out raw data or perform computation to present more advanced data, based on raw input data, for example count number of battery charge-discharge cycles.

To provide the equivalent of smart battery chip functionality for lead acid battery, the same three sensors are need: voltage, current and temperature. Arduino microcontroller platform appeared to be a good start for these sensors. It combines hardware and software relatively well and can communicate with software running on Windows PC with ease over serial connection.

A diagram below illustrates how automotive battery parameters are measured by microcontroller, processed, logged and optionally sent to Windows PC ruining .NET application battmon.

Image 2

Described below automotive battery smart monitor (battmon) has significant capabilities to obtain, display and record several key battery parameters, and figure out several other battery properties based on several charge or engine starting cycles to notify user about battery health and life expectancy. The following raw automotive battery parameters are displayed and recorded

  • Battery current
  • Battery voltage
  • Battery temperature

Based on them, the above data from automotive battery, the following battery parameters are computed, displayed live at run time and logged to SD card as well

  • State of Charge SoC (0 to 100%), separately, while
    • Charging
    • At rest
    • Discharging
  • Engine Starting: Current draw and Duration
  • Battery Internal Resistance
  • Battery cranking amperes (CA), and if temperature is low enough, then cold cranking amperes (CCA)
  • Number of charge-discharge cycles
  • Estimated battery capacity (A*Hrs) based on coulombic charge accepted and charge released
  • Charging time

Battmon can provide important battery health information:

  • within seconds
  • without the need to remove battery from automobile
  • on motor vehicle while driving, when parked, and when engine is off

Visually on screen and, such as whether battery is accepting charge and how well. The illustration below highlights these points on battmon screenshot taken from automotive battery in good health starting car engine (10 seconds chart recorder scroll window).

Image 3

In the long run, given the opportunity for battmon to be mounted on automobile in operation for a while, it allows battmon to collect sufficient data for statistical analysis of automotive battery data and derive battery trends over time or temperature.

Further, by inspecting battmon logged data, it is possible to isolate and investigate any suspected voltage or current spikes, troughs or unusual events on battery line.

Battmon - Microcontroller Part

The purpose of microcontroller component of battmon is to perform three tasks:

  • Collect raw battery data on millisecond time scale
  • Perform limited processing of raw battery data
  • Save to data to SD card and/or send live data to PC

Battery charge in coulombs (Q) is computed continuously by integrating battery current over time, separately for positive and negative currents, therefore charge and charge out are computed separately to monitor how battery is releasing and accepting charge separately.

The diagram below illustrates the design of battmon microcontroller part. Arduino Uno R3 compatible microcontroller was used.

Image 4


Battery Voltage Sensor

Voltage sensor is based on built-in 5 volt 10-bit ADC channel 0 of Arduino microcontroller with 1:3 divider, therefore providing 0 to 15 Volts range to cover most of automotive battery voltage measurements needs. Built in voltage sensor seems to be temperature compensated in hardware but was tested for calibration.

Battery Current Sensor

A split loop DC Hall current sensor was used, which provides linear voltage output proportional to battery current. Several models were tried, with YHDC +-100 A current sensor as most practical for this project. Negative current of –100A produces 0 Volts output on senor, no current makes 2.4 Volts, and +100A positive current makes 5.0 Volts. DC current sensor was connected to 5 Volt 10-bit ADC channel 1 of Arduino microcontroller.

Battery current sensor was calibrated on microcontroller. Battery current sensor provides signal which needs temperature compensation, which is done by software in microcontroller part of battmon.

An optional high current range split loop DC Hall sensor is supported on ADC 2 channel for heavy duty engine equipped vehicles, which covers battery current range of +-500A.

Temperature Sensor

Temperature sensor is built in into Arduino microcontroller as internal ADC channel and was used with individual calibration from -20°C to +70°C. Microcontroller board was mounted on or near automotive battery therefore temperature reported by microcontroller was assumed to be close to automotive battery temperature.

Calibration data used for this project and conversion formulas are available for your review in the attached document.

Schematics drawing is in the following file.

Photographs of assembled microcontroller setup are shown below as ready assembled setup and as installed on automotive battery (microcontroller board is seen wrapped in plastic bag).

Image 5

Image 6

Microcontroller Software

Collecting automotive battery data is the first task of battmon part on microcontroller. Its software consists of two parts: one time initialization step and measurement loop function being called continuously.

During initialization, microcontroller date and time are initialized from RTC clock, and SD card is checked to probe if a log file can be created. In addition, microcontroller serial port is initialized at maximum speed of 11520 baud.

Default settings for ADC analog inputs on Arduino microcontroller were used for A/D conversion resulting in maximum data rate about 1 complete set of data every 4 milliseconds. Faster rates are possible by setting microcontroller ADC clock to as high as 1 MHz, which can provide higher sampling rate, but turned to produce quite noisy voltage data. Still high ADC rate option in microcontroller source code is left as conditionally compiled in volt_amp_temp.ino file.

// with default ADC clock set, i.e. the default prescale function returns in 111 microseconds per call.
// faster option : set ADC clock to the max high speed, i.e. to 1 MHz. Then analogRead(portNo) returns in 16 microseconds
//#define FASTADC 1
// The recommended maximum ADC clock frequency is limited by the internal DAC in the conversion circuitry. 
// For optimum performance, the ADC clock should not exceed 200 kHz. 
// However, frequencies up to 1 MHz do not reduce the ADC resolution significantly. 
// Operating the ADC with frequencies greater than 1 MHz is not characterized.

// battery current probe runs OK at 1 MHz with re-read
// battery voltage probe runs noisy at 1 MHz
#ifdef FASTADC
// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

Measurement loop function reads raw data from voltage, temperature and current sensors repeatedly. Depending on how much microcontroller has to do in each pass, one loop may take as little as 4 msec.

In addition, measurement loop code uses some smart logic to find out whether any significant changes occurred in any of these battery parameters, and to perform integration of current over time to compute battery coulombic charge separately for coming in or going out.

Monitoring battery coulombic charge over battery life can provide valuable information to be further analyzed by battmon .NET program on Windows PC.

A diagram below shows design of microcontroller software part of battmon:

Image 7

Sending Battery Data to PC Serial Port

There is no need to send battery data every time measurement loop completes each pass. Rather, measurement function uses some smart logic to find out whether any significant changes occurred in any of these battery parameters. If so, data are sent in the following text format with comma as delimiter:

Field 1 2 3 4 5 6 7 8
meaning Date-time stamp battery voltage battery current battery temperature Battery state Charge out Charge in Reason for send
Unit of measure ISO 8601 format with milliseconds volts amperes degrees Celsius C,D,I coded states coulombs coulombs C,V,T,B coded reasons
Range Current or past in time 0 to 15 V -100 A to +100 A -20°C to +70°C Charging, discharging, no load (at idle) >0 Q >0 Q C for change in current, V for Voltage, B for both, T for temperature

Example of one string from battmon serial data output:

2014-01-30T20:48:28.321, 14.3, 0.6, 16.1,C, 118481, 94206, C

In C# code, each such line of data would match battmon C# data structure (except reason for sensing field, which is not mapped).

[Serializable] public struct strctBattMonData
    public DateTime dtBattDateTime;
    public double dblBatVolts;
    public double dblBatAmperes;
    public double dblBattTemp;
    public char chBattState;
    public long liQIn;
    public long liQOut;

Sample battmon serial data output files are included with this article.

Thus, microcontroller sends battery data at constant baud rate 115200 baud but at variable data rate. Since Windows PC can handle a lot more data throughput than microcontroller produces from reading battery data, measurement loop sends one line of battery data even when no change was detected in battery parameters, as heart beat signal, every second.

However, if no significant change was observed in any of these battery parameters, no data is logged to SD card. If either of: voltage, temperature or current did change, data are logged to SD card immediately. Since recording data to SD card is slow, some transient data may be skipped.

Battmon - .NET Application Part

On Windows platform, Microsoft .Net Framework 4.5 was used to develop Battmon part, which performs live battery data processing and displays it in several forms:

  • Automotive style analog gauges (V, A, °C)
  • Digital displays (V, A, °C)
  • Software Chart recorder (V, A over time)

When analyzing previously recorded battmon data, live gauges are not active, rather battmon chart recorder gets data from file and then allows to scroll to desired point for inspection. Also, all previously recorded files are summarized in property sheet via drop down menu by time stamp when it was recorded for quick review (no chart recorder data).

The screen shot below demonstrates all the features in one picture:

Image 8

NexGen .NET controls were used in battmon user interface part for both analog automotive style gauges and for digital displays.

Digital displays of battmon as well as software chart recorder display instant values, exactly as they are received from battmon microcontroller. Both current and voltage contain some jitter when automotive accessories are operating, as seen on screen shot. This would result in jerky operation of analog gauges. To smooth the gauge needle movement simple ripple filter is applied to analog gauge values only. As a consequence, instantaneous screen shots of battmon may show different values for analog and digital current, since analog gauge displays smoothed value while digital display shows instantaneous one.

Charge level of automotive battery is displayed as State of charge (SoC) value ranging from 0% to 100% for three(3) modes: charging, at rest, and discharging at actual battery temperature displayed just above charge level indicator group.

Image 9   Image 10

Battery's open-circuit voltage measurements to determine SoC at rest can be used to estimate the state of charge when all car accessories are turned off and engine is not running – battmon will detect this condition when battery current is not more than +-0.1 A (middle bar indicator).

Since SoC is computed using table function for lead-acid battery measured at 20°C from C value:

SoC -C/3 -C/5 -C/10 -C/20 -C/100 at rest +C/40 +C/20 +C/10 +C/5
0 9.5 10.2 10.99 11.46 11.5 11.6      
10 9.95 10.6 11.27 11.6 11.68 11.7 11.7 12.08 12.38 12.6
20 10.38 10.91 11.5 11.85 11.89 11.9 11.9 12.25 12.6 12.75
30 10.72 11.12 11.68 12.06 12.08 12.1 12.55 12.55 12.8 12.95
40 10.88 11.33 11.88 12.21 12.24 12.25 12.7 12.85 12.85 13.2
50 11.15 11.55 12 12.33 12.28 12.3 12.8 13.05 13.2 13.35
60 11.35 11.65 12.11 12.45 12.39 12.4 12.9 13.15 13.3 13.52
70 11.5 11.8 12.25 12.5 12.49 12.5 12.95 13.2 13.4 13.7
80 11.6 11.9 12.35 12.55 12.57 12.58 13 13.3 13.65 14
90 11.65 12.45 12.5 12.58 12.59 12.6 13.15 13.6 14.1 15.2
100 11.7 12.08 12.5 12.6 12.62 12.63 13.5 14.2 15.2 15.9

battmon performs battery voltage adjustment by -0.0235 V/°C for temperature changes to bring voltage to 20C to determine SoC.

Structure of Battmon C# Code

Class names for battmon .NET application are shown in the picture below:

Image 11

Super class Generic12Vbattery contains just enough members and methods to represent generic Lead-Acid 6-cell 12 Volt battery.

Generic12Vbattery class also contains static tables for C-factor to determine state of charge (SoC) at run time during discharging, charging and at no load (at idle).

//        protected static double[] cdblSOCVALS=new double[NUMSOCTBLCOLS]
// -------------- discharging ------------ | ~ no load ~ | ++++++++ charging ++++++++++++++++++ 
//-C/3    -C/5    -C/10    -C/20    -C/100     at rest     +C/40    +C/20    +C/10    +C/5
{-0.333,  -0.20,  -0.10,   -0.05,   -0.01,      0.0,       +0.025,  +0.05,   +0.1,    +0.2};

For specific battery, another class AutomotiveBattery is derived from Generic12Vbattery super class. It is here where user can set values for known CA, CCA and capacity, along with make, model and serial number. When battmon will collect data from actual automotive battery, it will then compare what user has provided for new battery as supplied by manufacturer’s data sheet with actual measurements, thus giving an idea how far has given battery degraded from new.

Dedicated class batt_data_parser serves just one purpose: validate battery data from battmon microcontroller, either sent live via serial port or read from SD card.

Ser_Port_Listener class has descriptive name and handles live battery data received via serial port, validating each field against range of acceptable numbers.

Two settings classes are responsible for persistent storage: BattMonSettings class holds battmon .NET program settings, whereas Settings class keeps all known to date key automotive battery parameters. The drop down list in battmon main screen is built from the data retrieved from persistent Settings class instance.

Form1 contains a single concurrent queue for data exchange between incoming flow form microcontroller and C# user interface.

// battery data packets queue
   public ConcurrentQueue<Generic12Vbattery.strctBattMonData> cnquBattDataQueue=null;

as illustrated by diagram below:

Image 12

Smart logic in C# code of battmon is capable of detecting engine starting event, which is counted and logged separately from ongoing battery data logging. Quick analysis of battery operation during engine starting event is performed at run time and displayed immediately.

Image 13

Photograph of battmon running live on Windows 8 tablet while a car engine is running at idle is shown below. USB type A connector can be seen on the upper left corner of tablet with the black cable coming from engine compartment carrying live battery data sent by battmon Arduino based microcontroller.

Image 14

Video recorded with live operation of battmon during car starting is also available. Battmon .NET project can be downloaded separately from the link in the beginning of the article. It can be built for any Windows 7 or 8 platforms (ARM, Win32 or X64).

Analyzing Past Automotive Battery Data with Battmon

Once battmon became aware of any engine starting cycle data, either it was running live with microcontroller connected to PC during engine start, or data were imported to battmon on PC from SD card recorded by microcontroller running stand alone, a quick overview is immediately available of any past engine starting data.

Drop down list contains all known to battmon engine starting events in a short format, which includes time stamp and key parameters, such as duration of starter motor run, battery temperature, internal resistance, computed CA, maximum discharge current, coulombs released and further if battery was given enough time to recharge how long it took. Screen shot of part of battmon display demonstrates it.

Image 15

There are several automotive battery parameters computed and shown on this part of battmon screen, which are explained below.

Engine Starting Cycle

Dropdown box shows one engine starting cycle date and time, which is highlighted. How long started motor was running in seconds and its maximum draw current battery supplied, in amperes.

Charge Out and Charge In

Columbic charge, in Coulombs, separately for charge going out when starter ran, and for charge going back into battery when generator charges battery. These values are expected to be of the same order. If they are drastically different then battery is not being recharged enough after engine runs after starting cycle.

Fully Recharged Checkbox and Recharging Duration

Time taken to recharge automotive battery is computed using a criteria when battery charging current decreases over time and finally nears zero. Recharging duration gives an idea how long car needs to be operated for battery to restore its charged state after engine starting.

Battery Internal Resistance and CA

Battery internal resistance is shown in ohms and cranking amperes (CA) are computed for each engine starting cycle.

Previous engine start events can be processed to display and analyze automotive battery internal resistance as a function of time on months scale to detect whether battery internal resistance undergoes deterioration, or as function battery temperature. Example of such diagram is shown below:

Image 16

Battmon Functionality as Enhancement for Car Dashboard Battery Icon

Battmon functionality could become part of automotive on-board embedded computer firmware. That way, key battmon data could be represented by a smart battery icon on vehicle dashboard, with a lot more battery information stored in on-board computer to be retrieved for review when needed.

Thus a primitive two state car dash board battery warning icon (not lit for healthy battery and lit when battery voltage is too low)

Image 17

could be replaced with a more informative smart battery icon available to motor vehicle operator/driver with live battery data, such as shown on prototype below for two cases: a healthy automotive battery and a sulfated battery, which poorly accepts charge:

Image 18   Image 19

For digital automotive dashboard with a touch screen capability tapping on smart battery icon would open up a dialog with a lot more information, similar to what battmon C# .NET application provides.

Points of Interest

This battmon project demonstrated a how to collect and analyze automotive lead-acid battery live data to display them at run time as well as to record to microSD card using a combination of Arduino based microcontroller and C# .NET Framework application on Windows PC. State of Charge(SoC) and other key battery parameters are derived from live battery data.

Revision History

Originally developed for Windows 8, and later for Windows 8.1. Should work for Windows RT 8.1 as well.


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

United States United States
No Biography provided

Comments and Discussions

QuestionSource code - Next UI Pin
Member 426218213-Dec-20 3:00
MemberMember 426218213-Dec-20 3:00 
QuestionHST21 Current Sensor Pin
Member 129754955-Feb-17 20:51
MemberMember 129754955-Feb-17 20:51 
Questionhi what type of sensors you used on this project Pin
Member 1296750125-Jan-17 4:38
MemberMember 1296750125-Jan-17 4:38 
Questiondumb question Pin
Member 121734744-May-16 21:15
MemberMember 121734744-May-16 21:15 
QuestionHall current sensor HST21 Pin
Member 1152272913-Mar-15 4:53
MemberMember 1152272913-Mar-15 4:53 
QuestionDumb question Pin
Member 113567017-Jan-15 21:38
MemberMember 113567017-Jan-15 21:38 
QuestionRe: Dumb question Pin
Member 127847437-Nov-16 18:00
MemberMember 127847437-Nov-16 18:00 
GeneralMy vote of 5 Pin
Djibril24-Nov-14 15:02
professionalDjibril24-Nov-14 15:02 
GeneralMy vote of 5 Pin
Agent__00713-Nov-14 17:07
professionalAgent__00713-Nov-14 17:07 
GeneralMy vote of 5 Pin
iRakeshJha10-Nov-14 22:32
professionaliRakeshJha10-Nov-14 22:32 
QuestionCode format Pin
Nelek3-Nov-14 0:20
protectorNelek3-Nov-14 0:20 
AnswerRe: Code format Pin
SergeiR[MCTS]3-Nov-14 15:30
MemberSergeiR[MCTS]3-Nov-14 15:30 
AnswerRe: Code format Pin
Nelek4-Nov-14 5:20
protectorNelek4-Nov-14 5:20 
GeneralRe: Code format Pin
SergeiR[MCTS]4-Nov-14 15:47
MemberSergeiR[MCTS]4-Nov-14 15:47 
GeneralRe: Code format Pin
Nelek4-Nov-14 21:57
protectorNelek4-Nov-14 21:57 
GeneralRe: Code format Pin
SergeiR[MCTS]7-Nov-14 17:10
MemberSergeiR[MCTS]7-Nov-14 17:10 
QuestionInteresting article Pin
Mike Hankey28-Oct-14 6:23
professionalMike Hankey28-Oct-14 6:23 
QuestionNexGen .NET controls alternative source Pin
Member 1101595328-Oct-14 6:16
MemberMember 1101595328-Oct-14 6:16 
QuestionThanks for the research - just what I needed. Pin
Member 1101595328-Oct-14 3:36
MemberMember 1101595328-Oct-14 3:36 
QuestionCircuit Diagram Pin
garygblake23-Oct-14 9:11
Membergarygblake23-Oct-14 9:11 
AnswerRe: Circuit Diagram Pin
SergeiR[MCTS]24-Oct-14 18:53
MemberSergeiR[MCTS]24-Oct-14 18:53 
QuestionNexGen .NET controls Pin
John Ayuya21-Oct-14 6:43
professionalJohn Ayuya21-Oct-14 6:43 
AnswerRe: NexGen .NET controls Pin
SergeiR[MCTS]21-Oct-14 7:56
MemberSergeiR[MCTS]21-Oct-14 7:56 
GeneralRe: NexGen .NET controls Pin
Emmanuel Manzanilla13-May-19 5:30
MemberEmmanuel Manzanilla13-May-19 5:30 
QuestionGood work! Pin
Zac Papac20-Oct-14 20:36
MemberZac Papac20-Oct-14 20:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.