Battery Life Calculator

Estimate the runtime of a battery based on capacity, current, and Depth of Discharge (DoD).

Li-ion
NiMH
Lead Acid
Alkaline
Other

mAh
Ah

mA
A


%

function calculateBatteryLife() {
let capacity = parseFloat(document.getElementById(“capacity”).value);
let current = parseFloat(document.getElementById(“current”).value);
let dod = parseFloat(document.getElementById(“dod”).value);
let capacityUnit = document.getElementById(“capacityUnit”).value;
let currentUnit = document.getElementById(“currentUnit”).value;
let resultDiv = document.getElementById(“batteryResult”);

if (isNaN(capacity) || isNaN(current) || isNaN(dod)) {
resultDiv.innerHTML = “⚠️ Please fill in all the input fields.”;
return;
}

if (dod 100) {
resultDiv.innerHTML = “⚠️ DoD should be between 0 and 100.”;
return;
}

if (capacityUnit === “Ah”) capacity *= 1000;
if (currentUnit === “A”) current *= 1000;

let usableCapacity = capacity * (dod / 100);
let batteryLife = usableCapacity / current;

let hr = Math.floor(batteryLife);
let min = Math.floor((batteryLife – hr) * 60);
let sec = Math.round((((batteryLife – hr) * 60) – min) * 60);

resultDiv.innerHTML = `🔋 Estimated Battery Life:
${hr} hr ${min} min ${sec} sec`;
}

function resetBatteryForm() {
document.getElementById(“capacity”).value = “”;
document.getElementById(“current”).value = “”;
document.getElementById(“dod”).value = “”;
document.getElementById(“batteryResult”).innerHTML = “”;
}

(adsbygoogle = window.adsbygoogle || []).push({});