Project tutorial
CoolMOS Power Battery Charger

CoolMOS Power Battery Charger

Electric vehicles are new enough to wonder, how long will they last? This is not a simple question, because it depends on a lot of things.

  • 1 respect

Components and supplies

Apps and online services

About this project

Most electric vehicle batteries are lithium based. When a lithium battery is charged and discharged once, it is called a cycle. Lithium battery capacity degrades as the cycle number increases. Battery cycle life is measured in cycles, with an industry standard of cycles to 80% capacity often used as a benchmark. What makes lithium batteries last a long time? Let’s turn that upside down. What shortens lithium battery life?

When a lithium battery is charged, its voltage goes up slowly. When it reaches full charge, battery voltage is highest, and will not go up much more. The max voltage (V) varies with lithium cell chemistry. Chemistries ranging from laptop batteries to power tools using lithium-cobalt blends and blends containing manganese, nickel, and aluminum have terminal voltages around 3.9 to 4.2V. Lithium-titanate batteries charge to 2.85V. Lithium-iron-phosphate batteries charge to about 3.65V.

Lithium battery voltage must be prevented from exceeding this voltage because it not only ruins battery life; it can lead to battery destruction or overheating and fire in some lithium batteries.

In this project I'll be demonstrating how to regulate the battery charging cycle to help prevent any damage to the battery.

The following project demonstration depicts a simple yet efficient way of charging a battery, we will be using a small 1.2V rechargeable battery but with a few modifications and calculations we can create a similar system for a much larger battery like that for an electric car.

Step 1:

First we collect all the components needed for this project.

  • Arduino Microcontroller
  • AA Battery Holder
  • NiMH AA Battery
  • 10 ohm Power Resistor (rated for at least 5 watts)
  • 1 Mohm resistor
  • 1 µF Capacitor
  • Infineon CoolMOS POWER MOSFET
  • 5V Regulated Power Supply
  • Prototyping Breadboard
  • Jumper Wires

Step 2:

The next step is to connect our components on the breadboard. The fritzing diagram I've provided shows us how.

Step 3:

This step involves uploading our code. The coded I've provided enables the user to see in real time the battery being charged and automatically cuts off charging when in reaches a certain threshold to prevent any damage to the battery. The output should be the following.

The picture below depicts the project wiring and setup in real life.


Arduino battery charging code Arduino
int batteryCapacity = 2500;     //capacity rating of battery in mAh
float resistance = 10.0;     //measured resistance of the power resistor
int cutoffVoltage = 1600;     //maximum battery voltage (in mV) that should not be exceeded
long cutoffTime = 46800000;     //maximum charge time of 13 hours that should not be exceeded

int outputPin = 9;     // Output signal wire connected to digital pin 9
int outputValue = 150;     //value of PWM output signal 

int analogPinOne = 0;     //first voltage probe connected to analog pin 1
float valueProbeOne = 0;     //variable to store the value of analogPinOne
float voltageProbeOne = 0;     //calculated voltage at analogPinOne

int analogPinTwo = 1;     //second voltage probe connected to analog pin 2
float valueProbeTwo = 0;     //variable to store the value of analogPinTwo
float voltageProbeTwo = 0;     //calculated voltage at analogPinTwo

float voltageDifference = 0;     //difference in voltage between analogPinOne and analogPinTwo
float batteryVoltage = 0;     //calculated voltage of battery
float current = 0;     //calculated current through the load (in mA)
float targetCurrent = batteryCapacity / 10;     //target output current (in mA) set at C/10 or 1/10 of the battery capacity per hour
float currentError = 0;     //difference between target current and actual current (in mA)

void setup()
  Serial.begin(9600);     //  setup serial
  pinMode(outputPin, OUTPUT);     // sets the pin as output

void loop()
  analogWrite(outputPin, outputValue);  //Write output value to output pin

  Serial.print("Output: ");     //display output values for monitoring with a computer

  valueProbeOne = analogRead(analogPinOne);    // read the input value at probe one
  voltageProbeOne = (valueProbeOne*5000)/1023;     //calculate voltage at probe one in milliVolts
  Serial.print("Voltage Probe One (mV): ");     //display voltage at probe one
  valueProbeTwo = analogRead(analogPinTwo);    // read the input value at probe two
  voltageProbeTwo = (valueProbeTwo*5000)/1023;     //calculate voltage at probe two in milliVolts
  Serial.print("Voltage Probe Two (mV): ");     //display voltage at probe two
  batteryVoltage = 5000 - voltageProbeTwo;     //calculate battery voltage
  Serial.print("Battery Voltage (mV): ");     //display battery voltage

  current = (voltageProbeTwo - voltageProbeOne) / resistance;     //calculate charge current
  Serial.print("Target Current (mA): ");     //display target current 
  Serial.print("Battery Current (mA): ");     //display actual current
  currentError = targetCurrent - current;     //difference between target current and measured current
  Serial.print("Current Error  (mA): ");     //display current error 

  Serial.println();     //extra spaces to make debugging data easier to read

  if(abs(currentError) > 10)     //if output error is large enough, adjust output
    outputValue = outputValue + currentError / 10;

    if(outputValue < 1)    //output can never go below 0
      outputValue = 0;

    if(outputValue > 254)     //output can never go above 255
      outputValue = 255;
    analogWrite(outputPin, outputValue);     //write the new output value
   if(batteryVoltage > cutoffVoltage)     //stop charging if the battery voltage exceeds the safety threshold
    outputValue = 0;
    Serial.print("Max Voltage Exceeded");
   if(millis() > cutoffTime)     //stop charging if the charge time threshold
    outputValue = 0;
    Serial.print("Max Charge Time Exceeded");

   delay(10000);     //delay 10 seconds before next iteration


Battery Charging Schematic
Schematic hnkdzpv29k


Similar projects you might like

Battery Charger Monitor

Project tutorial by David Kanceruk

  • 1 comment
  • 18 respects

Auto Battery Charger Switch

Project showcase by John Wood

  • 20 respects

Arduino Addons: Battery Level Indicator

Project showcase by Arduino World

  • 69 respects

Programmable Pocket Power Supply with OLED Display

Project tutorial by Shahariar

  • 33 respects

Low Power RF Beacon for Remote Sensing & Communication

Project tutorial by Shahariar

  • 1 comment
  • 16 respects

Take Control Over Lego Power Functions

Project tutorial by Patrick Müller

  • 62 respects
Add projectSign up / Login