Voltage Divider Calculator

Voltage Divider Calculator

Enter any three values in Vin, Vout, R1, R2 and leave one field blank to calculate the missing value.

body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f8f9fa;
}
.calculator-box {
max-width: 450px;
margin: auto;
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0,0,0,0.2);
}
h2 {
text-align: center;
}
label {
display: inline-block;
width: 150px;
font-weight: bold;
}
input, select {
padding: 5px;
margin-bottom: 10px;
}
button {
width: 48%;
padding: 10px;
background-color: #007bff;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
margin: 2px;
}
button:hover {
background-color: #0056b3;
}
#output {
margin-top: 15px;
font-weight: bold;
text-align: center;
}

Voltage Divider Calculator

V
mV

V
mV

Ω


Ω



function calculate() {
let Vin = parseFloat(document.getElementById(“Vin”).value) * parseFloat(document.getElementById(“VinUnit”).value) || null;
let Vout = parseFloat(document.getElementById(“Vout”).value) * parseFloat(document.getElementById(“VoutUnit”).value) || null;
let R1 = parseFloat(document.getElementById(“R1”).value) * parseFloat(document.getElementById(“R1Unit”).value) || null;
let R2 = parseFloat(document.getElementById(“R2”).value) * parseFloat(document.getElementById(“R2Unit”).value) || null;

let result = “”;

// Check how many are missing
let missing = [Vin, Vout, R1, R2].filter(v => v === null).length;
if (missing !== 1) {
alert(“Please leave exactly one field empty for calculation.”);
return;
}

if (Vout === null && Vin !== null && R1 !== null && R2 !== null) {
Vout = Vin * (R2 / (R1 + R2));
result = `Output Voltage (Vout) = ${Vout.toFixed(2)} V`;
}
else if (Vin === null && Vout !== null && R1 !== null && R2 !== null) {
Vin = Vout * (R1 + R2) / R2;
result = `Input Voltage (Vin) = ${Vin.toFixed(2)} V`;
}
else if (R1 === null && Vin !== null && Vout !== null && R2 !== null) {
R1 = R2 * ((Vin / Vout) – 1);
result = `Upper Resistor (R1) = ${R1.toFixed(2)} Ω`;
}
else if (R2 === null && Vin !== null && Vout !== null && R1 !== null) {
R2 = (R1 * Vout) / (Vin – Vout);
result = `Lower Resistor (R2) = ${R2.toFixed(2)} Ω`;
}
else {
result = “Invalid input. Please check values.”;
}

document.getElementById(“output”).innerHTML = result;
}

function resetForm() {
document.getElementById(“Vin”).value = “”;
document.getElementById(“Vout”).value = “”;
document.getElementById(“R1”).value = “”;
document.getElementById(“R2”).value = “”;
document.getElementById(“output”).innerHTML = “”;
}


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