← all lessons
Components · #6 of 20

Diodes + LEDs

Current Limiting, Polarity, Brightness

Why it matters

LEDs are diodes that emit light. They have polarity (direction matters) and need current limiting (resistors) to prevent destruction.

The idea

What Is a Diode?

A diode is a one-way valve for electricity:
        <h3>LEDs (Light Emitting Diodes)</h3>
        LEDs are diodes that emit light when current flows:
        <ul>
          <li><strong>Anode</strong> (+): Longer leg, connects to positive</li>
          <li><strong>Cathode</strong> (-): Shorter leg, connects to ground</li>
          <li><strong>Voltage drop</strong>: ~2V (red) to ~3.5V (blue/white)</li>
          <li><strong>Current</strong>: Typically 20mA max (check datasheet)</li>
        </ul>

        <h3>Current Limiting</h3>
        LEDs <strong>must</strong> have a current-limiting resistor:
        <ul>
          <li>Without a resistor, LED draws too much current → <strong>destroys itself</strong></li>
          <li>Formula: R = (V_supply - V_LED) / I_desired</li>
          <li>Example: 3.3V supply, 2V LED, 15mA desired → R = (3.3 - 2) / 0.015 = 87Ω (use 100Ω)</li>
        </ul>

        <h3>Brightness Myths</h3>
        <ul>
          <li><strong>Higher voltage ≠ brighter</strong> — current determines brightness</li>
          <li><strong>PWM dimming</strong> — change duty cycle, not voltage</li>
          <li><strong>Color affects voltage drop</strong> — blue/white need more voltage than red</li>
        </ul>

Demo

LEDs are simple but critical. Review polarity and current limiting before connecting.

Key takeaways

Going deeper

LEDs have a forward voltage (V_f) that varies by color. Red: ~1.8V, Green: ~2.1V, Blue/White: ~3.0-3.5V. For PWM dimming, use frequencies >100Hz to avoid visible flicker. For battery-powered devices, use lower current (5-10mA) to save power.

Math details

Current-limiting resistor:
  R = (V_supply - V_LED) / I_desired

Example calculations:
  V_supply = 3.3V
  V_LED = 2V (red LED)
  I_desired = 15mA = 0.015A

  R = (3.3V - 2V) / 0.015A = 1.3V / 0.015A = 87Ω

  Use standard value: 100Ω (slightly safer, I = 13mA)

Power in resistor:
  P = I² × R = (0.013A)² × 100Ω = 0.017W (safe, <0.25W)

Power in LED:
  P = V_LED × I = 2V × 0.013A = 0.026W

Implementation

LLM Prompt: LED Resistor Calculator