PyRaspBeta

Voltage, current and Ohm's law

Every circuit in PyRasp, from a single LED to a relay-switched heater, comes down to three numbers: voltage (how hard the push is), current (how much charge flows) and resistance (how much the parts hold it back). Ohm's law ties the three together, and one calculation built on it — the LED's series resistor — is the one you will do more than any other.

Volts, amps and ohms

  • Voltage, in volts (V), is the push between two points. A GPIO driven high pushes 3.3 V relative to ground.
  • Current, in amps (A) or milliamps (mA), is the flow of charge. 1 A = 1000 mA.
  • Resistance, in ohms (Ω) or kilo-ohms (kΩ), is how strongly a part opposes that flow. 1 kΩ = 1000 Ω.

Ohm's law locks the three together:

V = I × R, so I = V ÷ R and R = V ÷ I.

Every circuit is a loop: current leaves a supply pin, passes through the parts, and returns to ground. Interrupt the loop and nothing flows; add resistance and less flows.

The LED and its series resistor

An LED is a diode. Below its forward voltage (Vf) it passes almost nothing; around Vf it starts to conduct, and because the curve is steep, a small change in voltage means a large change in current. The LED does not limit its own current — the resistor in series with it does:

R = (supply voltage − LED forward voltage) ÷ desired current

Two worked examples, both from a 3.3 V GPIO:

  • Red LED, Vf ≈ 2.0 V, target 10 mA. R = (3.3 − 2.0) ÷ 0.010 = 130 Ω. That is not a value most starter kits carry, so use 150 Ω; or follow the usual advice and use 220–330 Ω, which is dimmer but perfectly safe.
  • Blue or white LED, Vf ≈ 3.0 V, target 10 mA. R = (3.3 − 3.0) ÷ 0.010 = 30 Ω. Only 0.3 V is left across the resistor, which is less than the spread between individual LEDs, so the current is unpredictable and the LED glows faintly, or not at all. Blue and white want a 5 V supply, where the maths is comfortable: (5.0 − 3.0) ÷ 0.010 = 200 Ω.

On the 5 V rail, the series resistor matters even more. A red LED has 3 V across its resistor instead of 1.3 V, so the same resistor passes more than twice the current; and a 5 V pin can supply far more than a GPIO's safe 16 mA. With no resistor at all, nothing except the wires and the LED's own slope limits the current: in the simulator an LED wired straight across 5 V draws hundreds of milliamps, immediately trips the overcurrent warning, and — with the LED's On overcurrent setting switched to burn out — is destroyed for good.

Wire the standard version:

from wiring import *

pi = Pi()
pi.GPIO17 >> Resistor(330) >> LED("red") >> pi.GND
from gpiozero import LED
from time import sleep

led = LED(17)

while True:
    led.on()
    sleep(1)
    led.off()
    sleep(1)

With a 330 Ω resistor and a 2 V LED, the current is (3.3 − 2.0) ÷ 330 ≈ 4 mA — a fifth of the LED's nominal 20 mA, so it is clearly lit but not at full brightness. The LED page lists the typical forward voltage for each colour, the resistor page explains the colour bands, and the night light recipe uses PWM to dim an LED smoothly instead.

Going deeper

  • What the simulator computes. Every wire merges its endpoints into a net. Nets held at a fixed voltage (GND, 3V3, 5V) split the board into independent islands, and each island is solved as an ordinary resistor network. The LED is a piecewise-linear diode: a knee set so the model passes through its rated point (2.0 V at 20 mA for a red one) and a 10 Ω slope above that. After every change the simulator recomputes every net voltage and every part current, then checks them.
  • What it warns about. More than 30 mA through an LED — "N mA through the LED (max 30 mA) — add a series resistor"; more than 16 mA sourced by a GPIO; more than the 3V3 rail's 50 mA budget; a resistor dissipating more than its 1/4 W rating; 5 V and 3V3 wired together ("Short circuit"); and a net nothing defines, which is flagged as floating.
  • Burn-out is a setting. Each LED has an On overcurrent setting: warn (the default) leaves the LED working so you can fix the circuit; burn out makes an overdriven LED stay dark for the rest of the run, which fails the judge's no-damage check.
  • Every LED is slightly different. The datasheet's forward voltage is a typical value; each LED in a build gets a fixed offset (0.1 V either way by default), as real parts do. Two "identical" LEDs can glow at noticeably different brightness from the same resistor.
  • Brightness is a ratio. The simulator reports brightness as current ÷ 20 mA, capped at 1.5. At 4 mA it reads 0.2; the judge's "lit" checks usually accept anything above zero.
  • Resistor power. A resistor turns current into heat: P = I² × R. The 330 Ω resistor above dissipates 0.004² × 330 ≈ 5 mW, far below its 1/4 W rating — but a small resistor in a high-current path can overheat, and the simulator will warn.
  • If you want the full water-tank explanation of voltage, current and resistance, SparkFun's Voltage, Current, Resistance, and Ohm's Law tutorial is a good next read.