TactivergeLite

Lite / Building Machines That Respond / Week 4

Rearrange the formula, then compute: an LED resistor

An LED needs 20 mA from a 5 V supply. Ohm's law says R = V/I. Which V, and why does the answer come out 1000 times too small?

About 40 min · 3 goals · Checked by automated tests · Full interactive version

Why should I care?

Datasheets give you most quantities; the design gives you the one you need to find. Rearranging the formula, converting units and checking the result is the core loop of engineering calculation, and a program makes it repeatable for every LED on the board.

Predict

A 5 V supply drives an LED that drops 2.0 V, at 20 mA. What resistor is needed?

  1. 0.15 Ω
  2. 150 Ω
  3. 250 Ω
Guess first, then reveal

150 Ω. The resistor sees 5.0 − 2.0 = 3.0 V, and 20 mA = 0.020 A, so R = 3.0 / 0.020 = 150 Ω. Dividing by 20 instead of 0.020 gives 0.15 Ω; using the full 5 V gives 250 Ω.

Discover

Open the Code Lab and type the LED resistor calculator from this lesson. Run it and check you get 150 Ω and 0.060 W. Then change the supply to 3.3 V and the LED to a 3.0 V blue one at 10 mA: what resistor do you need now?

What the interactive shows (text version)

The Code Lab exercise can be done by hand: R = (5.0 − 2.0) / 0.020 = 150 Ω and P = 3.0 × 0.020 = 0.060 W; with 3.3 V, a 3.0 V LED and 10 mA, R = 0.3 / 0.010 = 30 Ω (choose the next standard value up, such as 33 Ω) and P = 0.003 W.

You can also open the interactive on the full site when you have a faster connection.

Understand

The calculator

v_supply = 5.0      # V
v_forward = 2.0     # V, from the LED datasheet
current_ma = 20     # mA, wanted LED current

current_a = current_ma / 1000
r_ohm = (v_supply - v_forward) / current_a
power_w = (v_supply - v_forward) * current_a
print(f"R = {r_ohm:.0f} ohm, P = {power_w:.3f} W")

Output: R = 150 ohm, P = 0.060 W

Convert first, in one place

Datasheets mix units: mA, kΩ, mV. Convert everything to base SI units (A, Ω, V) once, near the top, in a clearly named variable such as current_a. Then every formula below can be written exactly as it appears in a textbook.

Pick a real part and check it

Resistors come in standard values, such as 120, 150 and 180 Ω. If the calculation gives 140 Ω, choose the next value up (150 Ω), so the current is slightly lower, never higher. Then check the power against the resistor's rating. This lesson is calculation only: any real circuit is built in the circuit simulator first.

Explain it another way

Intuitive

The supply pushes with 5 V, the LED takes 2 V of that, and the resistor must 'use up' the other 3 V while letting just the right flow of current through.

Technical

Rearranging keeps an equation balanced: whatever you do to one side, do to the other. Coding the rearranged form, with inputs converted to SI units, makes the program a direct, checkable copy of the derivation.

Mathematical

R = (V_s − V_f)/I. Sensitivity: if V_f is 0.2 V higher than expected, the current with R fixed is I = (V_s − V_f)/R, which drops by 0.2 / 150 ≈ 1.3 mA. That is small, which is why one resistor works across LEDs of the same type.

Applied

Indicator LEDs on every control panel use this calculation. Too small a resistor overheats or burns out the LED; too large and it is too dim to see in daylight.

Derivation: From Ohm's law to the LED resistor formula
  1. Ohm's law for the resistor: V_R = I · R, with V_R in volts, I in amps and R in ohms.

  2. Divide both sides by I to make R the subject: R = V_R / I.

  3. The LED and the resistor are in series across the supply, so their voltages add: V_supply = V_forward + V_R, giving V_R = V_supply − V_forward.

  4. Substitute: R = (V_supply − V_forward) / I.

  5. Example: (5.0 V − 2.0 V) / 0.020 A = 3.0 / 0.020 = 150 Ω. Power in the resistor: P = V_R · I = 3.0 × 0.020 = 0.060 W, well under a common 0.25 W rating.

Worked example 1

A 12 V supply drives a white LED (3.0 V) at 15 mA. Find R and P.

V_R = 12 − 3.0 = 9.0 V. I = 15 / 1000 = 0.015 A. R = 9.0 / 0.015 = 600 Ω, so choose the next standard value up, such as 620 Ω. P = 9.0 × 0.015 = 0.135 W: under 0.25 W, but closer than you might like, so a 0.5 W part gives more margin.

Common mix-ups

Practice

Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.

Ω

Practice 2. Rearrange V = I · R to find I.
Practice 3. A program does r = (5 - 2) / 20 with the current in mA. What goes wrong?

W

Apply it

Turn the calculator into a table: for supplies of 3.3, 5, 9 and 12 V, print the resistor and power for a red LED (2.0 V, 15 mA). Mark any case where the power is above 0.125 W. Then build one case in the circuits lab to confirm the current.

Reflect

Why is it better to convert units once at the top of a program than inside each formula?

Write your answer on paper or in your own notes. Lite never stores what you write.

← Translate a formula into PythonThe math module: roots, angles and radians →