<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Basic Electronics - Category - Abhis Lab Blog</title><link>https://abhislab.in/categories/basic-electronics/</link><description>Basic Electronics - Category - Abhis Lab Blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Sat, 08 Aug 2026 18:00:00 +0530</lastBuildDate><atom:link href="https://abhislab.in/categories/basic-electronics/" rel="self" type="application/rss+xml"/><item><title>Microstrip Line Calculator</title><link>https://abhislab.in/posts/microstripline_calculator/</link><pubDate>Sat, 08 Aug 2026 18:00:00 +0530</pubDate><author>Abhi</author><guid>https://abhislab.in/posts/microstripline_calculator/</guid><description><![CDATA[<div class="mx-auto max-w-4xl">
  <p class="text-4xl text-center font-bold !m-6">Microstrip Line Calculator</p>
  <p class="!text-xl">Adjust parameters to calculate line width, length, and effective dielectric constant in real-time.</p>
  <hr class="h-px !my-10 bg-blue-600 border-0">
  <div>
    <div class="grid grid-cols-1 md:grid-cols-2 gap-x-[60px] gap-y-6">
      <div class="flex flex-col">
        <label class="my-label" for="targetImpedance">Target Impedance Z<sub>0</sub> (Ω)</label>
        <input class="my-input" type="number" id="targetImpedance" value="50" step="1">
      </div>
      <div class="flex flex-col">
        <label class="my-label" for="dielectricConstant">Dielectric Constant E<sub>r</sub></label>
        <input class="my-input" type="number" id="dielectricConstant" value="4.4" step="0.1">
      </div>
      <div class="flex flex-col">
        <label class="my-label" for="substrateHeight">Substrate Height h (mm)</label>
        <input class="my-input" type="number" id="substrateHeight" value="1.6" step="0.1">
      </div>
      <div class="flex flex-col">
        <label class="my-label" for="electricalLength">Electrical Length (degrees)</label>
        <input class="my-input" type="number" id="electricalLength" value="45" step="5">
      </div>
      <div class="flex flex-col">
        <label class="my-label" for="frequency">Frequency (GHz)</label>
        <input class="my-input" type="number" id="frequency" value="2.0" step="0.1">
      </div>
      <div class="flex flex-col">
        <label class="my-label" for="initialStepFraction">Initial Step Fraction</label>
        <input class="my-input" type="number" id="initialStepFraction" value="0.5" step="0.05">
      </div>
      <div class="flex flex-col">
        <label class="my-label" for="tolerance">Tolerance (%)</label>
        <input class="my-input" type="number" id="tolerance" value="0.01" step="0.01">
      </div>
    </div>
    <hr class="h-px !my-8 bg-blue-600 border-0">
    <div id="results" class="text-xl">
      Calculating results...
    </div>
    <hr class="h-px !my-8 bg-blue-600 border-0">
  </div>
</div>
<script>
function calculateMicrostrip() {
    const Z0 = parseFloat(document.getElementById("targetImpedance").value);
    const h = parseFloat(document.getElementById("substrateHeight").value) / 1000;
    const er = parseFloat(document.getElementById("dielectricConstant").value);

    let stepFraction = parseFloat(document.getElementById("initialStepFraction").value);
    stepFraction = Math.max(stepFraction || 0.001, 0.001);

    let tolerance = parseFloat(document.getElementById("tolerance").value);
    tolerance = Math.max(tolerance || 0.0000001, 0.0000001);

    const electricalLength = parseFloat(document.getElementById("electricalLength").value);
    const frequency = parseFloat(document.getElementById("frequency").value) * 1e9;

    const SPEED_OF_LIGHT = 299792458;

    if (isNaN(Z0) || isNaN(h) || isNaN(er) || isNaN(electricalLength) || isNaN(frequency)) {
        document.getElementById("results").innerHTML = "Please provide valid numeric inputs.";
        return;
    }

    function calc_effective_dielectric_constant(er, h, w) {
        if (w / h > 1) {
            return ((er + 1) / 2) + (((er - 1) / 2) * (1 / Math.sqrt(1 + (12 * (h / w)))));
        } else {
            return ((er + 1) / 2) + (((er - 1) / 2) * ((1 / Math.sqrt(1 + (12 * (h / w)))) + (0.04 * Math.pow(1 - (w / h), 2))));
        }
    }

    function calc_characteristic_impedance(er_eff, h, w) {
        if (w / h <= 1) {
            return (60 / Math.sqrt(er_eff)) * Math.log((8 * h / w) + (w / (4 * h)));
        } else {
            return (120 * Math.PI) / (Math.sqrt(er_eff) * ((w / h) + 1.393 + (0.667 * Math.log((w / h) + 1.444))));
        }
    }

    let width = 0.1;
    let maxIter = 10000;
    let count = 0;

    while (count < maxIter) {
        count++;
        const er_eff = calc_effective_dielectric_constant(er, h, width);
        const z0 = calc_characteristic_impedance(er_eff, h, width);

        if (Math.abs(z0 - Z0) < tolerance) {
            const lambda_eff = SPEED_OF_LIGHT / (frequency * Math.sqrt(er_eff));
            const physical_length = lambda_eff * (electricalLength / 360);

            document.getElementById("results").innerHTML = `
                <h3 class="text-2xl font-bold mb-3">Results:</h3>
                <b>Line Width (w)</b>: ${(width * 1000).toFixed(4)} mm<br>
                <b>Physical Length (l)</b>: ${(physical_length * 1000).toFixed(4)} mm<br>
                <b>Effective Dielectric Constant (&epsilon;<sub>eff</sub>)</b>: ${er_eff.toFixed(4)}<br>
                <b>Calculated Z<sub>0</sub></b>: ${z0.toFixed(2)} &Omega;<br>
                <b>Accuracy</b>: ${(100 - (Math.abs(z0 - Z0) * 100) / Z0).toFixed(2)}%
            `;
            return;
        }

        const step_size = stepFraction * width;

        if (z0 > Z0) {
            width += step_size;
        } else {
            width -= step_size;
        }

        if (width < 0.00001) {
            document.getElementById("results").innerHTML = "<span class='text-red-600 font-bold'>Warning: Width boundary exceeded (Very Low Width).</span>";
            return;
        }
    }
}

document.querySelectorAll('.my-input').forEach(input => {
    input.addEventListener('input', calculateMicrostrip);
});

calculateMicrostrip();
</script>
<hr>
<h2 id="microstrip-line-layout-and-calculations">Microstrip Line Layout and Calculations</h2>
<p><figure><a class="lightgallery" href="/posts/microstripline_calculator/microstrip_layout.png" title="Microstrip Line Layout" data-thumbnail="/posts/microstripline_calculator/microstrip_layout.png" data-sub-html="<h2>Microstrip Line Layout</h2><p>Microstrip Line Layout</p>]]></description></item><item><title>LED Resistor Calculator</title><link>https://abhislab.in/posts/ledcalc/</link><pubDate>Wed, 22 Jul 2026 10:07:39 +0530</pubDate><author>Abhi</author><guid>https://abhislab.in/posts/ledcalc/</guid><description><![CDATA[<div class="mx-auto max-w-4xl">
  <p class="text-4xl text-center font-bold !m-6">LED Resistor Calculator</p>
  <p class="!text-xl text-center">Calculate the exact current-limiting resistor needed to safely run an LED.</p>
  <hr class="h-px !my-10 bg-blue-600 border-0">
  <div for="form">
    <div class="grid grid-cols-1 md:grid-cols-3 gap-5">
      <div class="flex flex-col">
        <label class="my-label" for="sourceVoltage">Source Voltage ($V_s$)</label>
        <input class="my-input" type="number" id="sourceVoltage" value="9" step="any" oninput="calculateLed()">
        <span class="text-xs text-gray-500 mt-1">Power supply or battery voltage</span>
      </div>
      <div class="flex flex-col">
        <label class="my-label" for="ledVoltage">LED Forward Voltage ($V_f$)</label>
        <input class="my-input" type="number" id="ledVoltage" value="2" step="any" oninput="calculateLed()">
        <span class="text-xs text-gray-500 mt-1">Red/Yellow ~2V, Blue/White ~3.2V</span>
      </div>
      <div class="flex flex-col">
        <label class="my-label" for="ledCurrent">LED Current ($I_f$ in mA)</label>
        <input class="my-input" type="number" id="ledCurrent" value="20" step="any" oninput="calculateLed()">
        <span class="text-xs text-gray-500 mt-1">Standard 5mm LED is typically 20mA</span>
      </div>
    </div>
    <div class="flex flex-col sm:flex-row gap-4 mt-6">
      <button class="my-button-secondary" type="button" onclick="clearLed()">
        Reset Defaults
      </button>
    </div>
    <hr class="h-px !my-6 bg-blue-600 border-0">
    <div id="result" class="text-xl">
      <!-- Calculated live via JavaScript -->
    </div>
    <hr class="h-px !my-6 bg-blue-600 border-0">
  </div>
</div>
<script>
const E24 = [
  10, 11, 12, 13, 15, 16, 18, 20, 22, 24, 27, 30, 
  33, 36, 39, 43, 47, 51, 56, 62, 68, 75, 82, 91
];

function getStandardResistor(calculatedR) {
  if (calculatedR <= 0) return 0;
  let scale = Math.pow(10, Math.floor(Math.log10(calculatedR)) - 1);
  let normalized = calculatedR / scale;
  
  for (let val of E24) {
    if (val >= normalized) {
      return val * scale;
    }
  }
  return 100 * scale;
}

function valOrDefault(id, defaultValue) {
  let x = document.getElementById(id).value;
  return x === "" || isNaN(parseFloat(x)) ? defaultValue : parseFloat(x);
}

function calculateLed() {
  let Vs = valOrDefault("sourceVoltage", 9.0);
  let Vf = valOrDefault("ledVoltage", 2.0);
  let If_mA = valOrDefault("ledCurrent", 20.0);
  let If_A = If_mA / 1000.0;

  let resultDiv = document.getElementById("result");

  if (Vf >= Vs) {
    resultDiv.innerHTML = `
      <div class="text-red-600 font-semibold">
        ⚠️ Source voltage (${Vs}V) must be greater than LED forward voltage (${Vf}V).
      </div>`;
    return;
  }

  if (If_A <= 0) {
    resultDiv.innerHTML = `
      <div class="text-red-600 font-semibold">
        ⚠️ LED current must be greater than 0 mA.
      </div>`;
    return;
  }

  let R_exact = (Vs - Vf) / If_A;
  let R_standard = getStandardResistor(R_exact);

  let P_resistor = Math.pow(If_A, 2) * R_exact;
  let recommendedWattage = P_resistor < 0.125 ? "1/8W (0.125W)" : P_resistor < 0.25 ? "1/4W (0.25W)" : "1/2W (0.50W)";

  resultDiv.innerHTML = `
    <div class="flex flex-col gap-2">
      <h3 class="text-2xl font-bold text-gray-900 mb-2">Results</h3>
      <div><span class="font-semibold">Exact Calculated Resistance:</b> <span class="text-blue-600 font-bold">${R_exact.toFixed(2)} Ω</span></div>
      <div><span class="font-semibold">Nearest Standard Resistor (E24):</b> <span class="text-green-600 font-bold">${R_standard >= 1000 ? (R_standard/1000).toFixed(2) + ' kΩ' : R_standard.toFixed(1) + ' Ω'}</span></div>
      <div><span class="font-semibold">Resistor Power Dissipation:</b> <span class="text-red-600 font-bold">${P_resistor.toFixed(3)} W </span>(Recommended minimum: ${recommendedWattage})</div>
    </div>`;
}

function clearLed() {
  document.getElementById("sourceVoltage").value = "9";
  document.getElementById("ledVoltage").value = "2";
  document.getElementById("ledCurrent").value = "20";
  calculateLed();
}

document.addEventListener("DOMContentLoaded", calculateLed);
calculateLed();
</script>]]></description></item><item><title>Ohms Law Calculator</title><link>https://abhislab.in/posts/ohmslawcalculator/</link><pubDate>Wed, 22 Jul 2026 10:07:39 +0530</pubDate><author>Abhi</author><guid>https://abhislab.in/posts/ohmslawcalculator/</guid><description><![CDATA[<div class="mx-auto max-w-4xl">
  <p class="text-4xl text-center font-bold !m-6">Ohm's Law Calculator</p>
  <p class="!text-xl ">Enter two known parameters to calculate the remaining values instantly.</p>
  <hr class="h-px !my-10 bg-blue-600 border-0">
  <div class=" " for="form">
    <div class="grid grid-cols-1 md:grid-cols-2 gap-x-[60px] gap-y-6">
      <div class="flex flex-col">
        <label class="my-label" for="voltage">Voltage (V)</label>
        <input class="my-input" type="number" id="voltage" step="any">
      </div>
      <div class="flex flex-col">
        <label class="my-label" for="current">Current (A)</label>
        <input class="my-input" type="number" id="current" step="any">
      </div>
      <div class="flex flex-col">
        <label class="my-label" for="resistance">Resistance (Ω)</label>
        <input class="my-input" type="number" id="resistance" step="any">
      </div>
      <div class="flex flex-col">
        <label class="my-label" for="power">Power (W)</label>
        <input class="my-input" type="number" id="power" step="any">
      </div>
    </div>
    <div class="flex flex-col  sm:flex-row gap-6 mt-8">
      <button class="my-button-primary" type="button" onclick="calculateOhms()">
        Calculate
      </button>
      <button class="my-button-secondary" type="button" onclick="clearOhms()">
        Clear
      </button>
    </div>
    <hr class="h-px !my-5 bg-blue-600 border-0">
    <div id="result" class=" text-xl">
      Enter any two known values.
    </div>
    <hr class="h-px !my-5 bg-blue-600 border-0">
  </div>
</div>
<script>
function val(id){
    let x=document.getElementById(id).value;
    return x==="" ? NaN : parseFloat(x);
}
function set(id,value){
    document.getElementById(id).value=value.toFixed(6).replace(/\.?0+$/,"");
}
function calculateOhms(){
let V=val("voltage");
let I=val("current");
let R=val("resistance");
let P=val("power");
const count=[V,I,R,P].filter(x=>!isNaN(x)).length;
if(count<2){
    document.getElementById("result").innerHTML=
    '<span >Please enter at least two values.</span>';
    return;
}try{
// V & I
if(!isNaN(V) && !isNaN(I)){
    R=V/I;
    P=V*I;
}
// V & R
else if(!isNaN(V) && !isNaN(R)){
    I=V/R;
    P=V*I;
}
// I & R
else if(!isNaN(I) && !isNaN(R)){
    V=I*R;
    P=V*I;
}
// V & P
else if(!isNaN(V) && !isNaN(P)){
    I=P/V;
    R=V/I;
}
// I & P
else if(!isNaN(I) && !isNaN(P)){
    V=P/I;
    R=V/I;
}
// R & P
else if(!isNaN(R) && !isNaN(P)){
    I=Math.sqrt(P/R);
    V=I*R;
}
if(!isFinite(V)||!isFinite(I)||!isFinite(R)||!isFinite(P))
throw "Invalid";
set("voltage",V);
set("current",I);
set("resistance",R);
set("power",P);
document.getElementById("result").innerHTML=`
<h3>Results</h3>
<b>Voltage    (V)</b> : ${V.toFixed(2)} V<br>
<b>Current    (I)</b> : ${I.toFixed(2)} A<br>
<b>Resistance (R)</b> : ${R.toFixed(2)} Ω<br>
<b>Power      (P)</b> : ${P.toFixed(2)} W`}
catch{
document.getElementById("result").innerHTML=
'<span>The entered values are not physically valid.</span>';}
}
function clearOhms(){
["voltage","current","resistance","power"].forEach(id=>{
document.getElementById(id).value="";
});
document.getElementById("result").innerHTML=
"Enter any two known values.";
}
</script>]]></description></item></channel></rss>