Skip to content

필사 모드: Ohm's Law for Programmers: Understanding Voltage, Current, and Resistance in Numbers

English
0%
정확도 0%
💡 왼쪽 원문을 읽으면서 오른쪽에 따라 써보세요. Tab 키로 힌트를 받을 수 있습니다.

Introduction — The Day I Forgot One Resistor and Burned an LED

Plug an LED into a breadboard: long leg to Arduino D9, short leg to GND. The code is one line: digitalWrite(9, HIGH). The LED flashes painfully bright for an instant, dims, and goes dark. Plug it back in — it won't light again.

This almost never happens in software. Bad code throws an exception or returns the wrong value, but a function doesn't physically vanish. In hardware, the component vanishes. And it vanishes almost always because of one number nobody got right.

In the circuit above, that number is current. Nobody decided how much current would flow through the LED, because the part that decides it — a resistor — wasn't there. This post's goal is to get you to the point where you can calculate that number yourself.

Voltage, Current, Resistance — What These Three Numbers Actually Mean

Let's pin down the terms first. If these three stay fuzzy, every calculation that follows stays fuzzy too.

Current (current) is flow. Its unit is the ampere, symbol I. One ampere is one coulomb of charge passing a cross-section in one second. In the microcontroller world you'll mostly deal with milliamps: a single LED draws around 15mA, and a single Arduino pin can safely supply roughly 20mA at most.

Voltage (voltage) is not a flow — it's a difference. Its unit is the volt, symbol V. The crucial thing here is that voltage isn't a property of one point; it's a relationship between two points. The sentence "pin D9 is at 5V" is really shorthand for "the potential difference between pin D9 and GND is 5V." State no reference point, and a voltage has no value.

This is the part programmers find strangest. A variable holds one value, but voltage always requires two points. That's why a multimeter has two probes — you cannot build a one-probe voltmeter.

Resistance (resistance) is a constraint. Its unit is the ohm, symbol R. It describes how little current gets to flow for a given voltage.

Ohm's law ties these three together.

V = I × R
I = V / R
R = V / I

These are the same equation in three shapes; which one you reach for just depends on which quantity you don't already know. In practice, when you're actually building a circuit, the third form gets used most: the voltage that will be applied and the current you want flowing are usually already fixed, and finding the resistor that produces exactly that is most of component selection.

Let's plug in a number. Connect a single 220-ohm resistor between a 5V supply and GND, nothing else:

Current = 5V / 220 ohm = 0.0227A = 22.7mA

That 22.7mA isn't a result you compute so much as a value physics enforces. As long as the supply holds 5V and the resistor stays 220 ohms, no other value can possibly flow.

Here's a misconception programmers run into constantly, worth settling now: the power supply sets the voltage, and the component decides the current. A "5V 2A adapter" doesn't mean it forces 2A through anything — it means it's capable of supplying up to 2A. The current that actually flows is determined by the resistance of whatever is connected. Connect nothing, and 0A flows, and the adapter has no complaint about that.

How Far the Water Analogy Holds — And Where It Breaks

Almost everyone learns electricity through the water analogy: voltage is pressure, current is flow rate, resistance is a narrow pipe. The analogy works remarkably well — and it works even better once you know precisely where it breaks down.

Start with what it gets right. Higher pressure pushes more water through, and a narrower pipe lets less through — that's Ohm's law. Put several pipes in parallel and the overall flow goes up — that's why parallel resistors lower the total resistance. Water doesn't vanish partway down a pipe — that's Kirchhoff's current law.

Now, where it breaks.

First, water flows with just one end open. Current only flows through a closed path. Wire one end to 5V and leave the other end dangling in midair, and the current is zero. Pull a hose out of a bucket and water gushes everywhere; pull a wire out of a circuit and absolutely nothing happens. This is exactly why beginners forget to hook up GND and ask, "I gave it power — why doesn't it work?"

Second, water sits inside a pipe, but charge doesn't wait around inside a circuit. The water analogy tempts you into picturing current as "matter being delivered," but what actually carries the energy is the electromagnetic field surrounding the conductor, and the electrons themselves drift extremely slowly. This distinction shows up in practice with high-speed signals: a wire's length and layout changing the shape of a signal is something a flow-rate model simply can't explain.

Third, and most importantly, in the water analogy a pipe's resistance is fixed. But a large share of real circuit components do NOT have fixed resistance. An LED's resistance changes drastically depending on the voltage across it. A transistor's resistance changes based on a third signal entirely. Try to understand an LED through the water analogy and you land squarely on the wrong conclusion. We'll dig into this in detail in the LED resistor calculation post.

So here's the summary: in a circuit that's nothing but resistors and a supply, lean on the water analogy all you like. The moment an active component shows up, drop the analogy and look at that part's actual characteristic curve instead.

Calculating Series and Parallel Circuits by Hand

On a breadboard you'll only ever run into two arrangements: series, where parts line up one after another, and parallel, where parts sit side by side across the same two points.

Series — Same Current, Divided Voltage

Say you connect a 220-ohm and a 330-ohm resistor one after the other across a 5V supply.

Combined resistance = 220 ohm + 330 ohm = 550 ohm
Current              = 5V / 550 ohm = 0.00909A = 9.09mA

Current has only one place to go, so both resistors carry exactly 9.09mA. Apply Ohm's law again and the voltage across each one falls out.

Voltage across 220 ohm = 0.00909A × 220 ohm = 2.00V
Voltage across 330 ohm = 0.00909A × 330 ohm = 3.00V
Total                  = 5.00V

The total comes out exactly equal to the supply voltage. That's not a coincidence — it's a law, and we'll name it in a moment. This structure also has a name of its own: a voltage divider. It means you can split 5V into 2V and 3V, and this is exactly the trick used to knock down a sensor's output or match an analog input's range.

Parallel — Same Voltage, Divided Current

Now connect that same 220-ohm and 330-ohm resistor side by side, both across 5V and GND. Since both ends of each resistor land on the same two points, both see the full 5V.

Current through 220 ohm = 5V / 220 ohm = 22.7mA
Current through 330 ohm = 5V / 330 ohm = 15.2mA
Total current            = 22.7 + 15.2 = 37.9mA

Working backward gives the combined resistance:

Combined resistance = 5V / 0.0379A = 132 ohm

The formula confirms it:

Combined resistance = (220 × 330) / (220 + 330) = 72600 / 550 = 132 ohm

A parallel combination's resistance is always smaller than the smallest individual resistor — which makes sense, since you've opened up another path, so the total flow naturally rises. This fact doubles as a quick sanity check in practice: if a calculated combined resistance comes out larger than the smallest component in the group, you made an arithmetic mistake somewhere.

Shared quantityDivided quantityCombined resistanceUsed in practice for
SeriesCurrentVoltageSum of each resistorVoltage dividers, LED current limiting
ParallelVoltageCurrentSmaller than the smallest valueEvery load hanging off a supply rail

That last column matters. Hang three sensors off a board's 5V rail and all three sit in parallel, so the current each one demands simply adds together. An Arduino Uno's 5V rail tops out around 450mA, and a Raspberry Pi's 3.3V rail around 50mA — and checking whether you're about to blow past that limit is nothing more than adding up parallel currents.

Kirchhoff's Two Laws — Tools for Debugging

Earlier, the sum of the voltages across two series resistors came out exactly equal to the supply voltage, and the sum of two parallel branch currents came out equal to the total current. Both of these have names, and they're not exam trivia — they're tools for finding out why a circuit isn't working.

Voltage Law — Go Around the Loop and It Sums to Zero

Follow a closed path all the way around, adding up every rise and fall in voltage along the way, and the total comes out to exactly zero. Climb 5V at the supply, and you must come back down by 5V total across the components to arrive back where you started. Return to your starting point and find the potential has changed, and that's a contradiction — it means it wasn't actually the same point.

Here's how this law gets used in practice. You have a 5V supply with a resistor and an LED in series, and the LED won't light. You measure across the resistor with a multimeter and read 5V. That's the answer right there. Since the loop must sum to zero, the voltage across the LED has to be 0V. Zero voltage in a closed circuit means the LED's position is, electrically, just a plain wire — either the LED is shorted, or its two legs are plugged into the same row on the breadboard.

The opposite result is just as useful. If the resistor reads 0V and the LED reads 5V, then no voltage dropping across the resistor means no current is flowing at all. Either the LED is in backwards, or a leg has broken off.

Two voltage readings are enough to tell these two failures apart. That's the practical value of this law.

Current Law — What Goes Into a Node Comes Back Out

The total current flowing into a node equals the total current flowing out of it. Charge doesn't pool up at a node.

The parallel calculation from earlier IS this law in action. The 37.9mA leaving the supply splits at the junction into 22.7mA and 15.2mA, then recombines into 37.9mA on its way back to GND.

The most important practical form of this law is the current budget. The current returning to a board's GND is the sum of everything every load consumes. So even when each individual part is safely within its own limit, the total can still blow past the board's limit. A Raspberry Pi allows 16mA per GPIO pin, but only 50mA across all GPIO pins combined. Push 15mA through each of four pins and every pin passes individually — but the total of 60mA fails. That whole calculation is nothing but the addition from the current law.

Once you're dealing with more than a handful of parts, doing that addition by hand gets tedious. Drop your board and parts into this site's circuit wiring validator and it computes the per-pin current and the totals for the 3.3V/5V rails, showing you which limit gets hit first. It's a good way to cross-check your own hand calculation.

Power — Why Resistors Get Hot, and How to Pick a Wattage Rating

Push current through a resistor and it warms up. That's not a side effect — it's literally what a resistor does. Electrons inside the resistive material collide with atoms and lose kinetic energy, and that energy becomes lattice vibration — heat. A resistor is a component that converts electrical energy into heat, and limiting current means dumping exactly that much energy as heat.

The amount dumped is power, measured in watts.

P = V × I

Substituting Ohm's law gives two more convenient forms:

P = I² × R
P = V² / R

Let's use the earlier series example: 9.09mA flowing through the 330-ohm resistor, with 3.00V across it.

P = 3.00V × 0.00909A = 0.0273W = 27.3mW

A typical carbon-film resistor is rated 1/4W, i.e. 250mW. 27.3mW is a ninth of that, so there's no issue whatsoever.

Now flip the situation. Connect a single 100-ohm resistor to a 12V supply:

Current = 12V / 100 ohm = 0.12A = 120mA
Power   = 12V × 0.12A = 1.44W

That's 1.44W. What happens if you plug in a 1/4W resistor there? It's nearly six times the rating, so the resistive body climbs to hundreds of degrees. The carbon film oxidizes and its resistance drifts upward, the color bands scorch black, and eventually the film breaks and goes open. If you're unlucky, the breadboard plastic melts before any of that even finishes. This calls for a cement resistor rated 3W or higher.

The rule of thumb is to leave plenty of margin on the rating. A common practical guideline is to pick a rating at least double the calculated power dissipation. There are two reasons. A resistor's rating is normally specified at 25°C ambient with free airflow, which isn't the case once it's crammed inside an enclosure or wedged between other parts. And running near the rating for a long stretch causes the resistance value itself to drift slowly.

RatingPhysical formSafe real-world usable powerTypical use
1/8W (125mW)Very small carbon filmUnder 60mWTight PCB space
1/4W (250mW)Most common brown bodyUnder 125mWLED current limiting, pull-ups
1/2W (500mW)Slightly thicker bodyUnder 250mW12V-class circuits
2W and upWhite, angular cement resistorUnder 1WPower stages, dummy loads

LED current-limiting resistors are almost always under 50mW, so 1/4W leaves plenty of margin — which is exactly why nearly every resistor in a beginner kit is 1/4W. Just remember that doesn't mean "every resistor gets to be 1/4W"; once you start working with 12V and up, you need to actually run the numbers.

Actually Measuring with a Multimeter (And the Mistake That Blows the Fuse)

When calculation and reality disagree, the measurement is what you trust. A multimeter is hardware's debugger, and using one correctly means knowing one asymmetry cold.

Voltage: Measured in Parallel, Across the Component

Voltage is a difference between two points, so you just touch a probe to each point you care about — you never need to break the circuit to do it. To measure across a resistor, just touch one probe to its left leg and the other to its right leg, and you're done.

This works because a voltmeter's internal resistance is very large — typically 10 megohms. Measuring a 5V point, the current leaking through the meter is:

5V / 10000000 ohm = 0.0000005A = 0.5 microamps

Compared to the tens of milliamps flowing in the circuit, that's essentially nothing. So the act of measuring doesn't disturb the circuit.

It matters that you don't lose track of your reference point while measuring. Clip the black probe onto GND and touch the red probe around with your other hand — that's the approach least prone to mistakes. Every reading then becomes a potential relative to GND, and readings are directly comparable to each other.

Current: Measured in Series, Breaking the Circuit to Insert the Meter

Current is an amount passing a specific point, so to measure it you have to actually make it pass through that point: you break the circuit at one spot and connect the two cut ends to the probes, so the current flows through the meter itself.

An ammeter's internal resistance is very small — roughly 10 ohms on the mA range, around 0.01 ohms on the 10A range. It has to be small so it disturbs the circuit as little as possible. Even so, it's never exactly zero, so the act of measuring changes the circuit a little. Push 20mA through a 10-ohm shunt on the mA range:

0.02A × 10 ohm = 0.2V

0.2V gets consumed inside the multimeter. This is the burden voltage. In a 5V circuit, 0.2V is 4 percent, usually negligible — but in a 3.3V circuit running on a tight margin, this value alone can make a circuit suddenly stop working. If a symptom disappears only while you happen to be measuring, this burden voltage is worth suspecting.

The Mistake Everyone Makes Once — Measuring Voltage on the Current Range

Once you're used to measuring voltage, switching to current tends to send your hand onto autopilot: you spin the dial to A but leave the probes right where they were, on 5V and GND. That means you've just connected an ammeter in parallel across the supply.

Let's calculate exactly what happens the instant that occurs. An ammeter is essentially a wire with almost no resistance. Using the mA range's 10 ohms:

Current = 5V / 10 ohm = 0.5A = 500mA

The fuse on the mA jack is usually rated 200mA or 500mA, so it blows instantly. Had you been plugged into the 10A jack instead, that's 0.01 ohms, which in theory would mean hundreds of amps — and in practice, as much as the supply can push. A USB supply's protection circuit will cut it off, but a lithium battery will make the probes glow red-hot.

And this accident passes quietly. A multimeter with a blown fuse still measures voltage perfectly fine, and simply always shows zero for current. So the next day you find yourself tearing the circuit apart wondering "why is the current zero." When current keeps reading zero, suspecting the multimeter's fuse before the circuit is the right order of operations.

The habit that prevents this is simple: the moment you finish measuring current, move the probe straight back to the voltage jack. Keep the probe position — not the dial — at its default state, and your hand can go on autopilot without causing an accident.

Resistance Measurement Has One Precondition

Measuring resistance works by having the multimeter apply a small voltage of its own and measuring the current that results. That requires two things to be true.

First, the circuit's power must be off. If the power is live, the meter's own applied voltage mixes with the circuit's voltage and the reading turns to garbage — and in the worst case, it damages the meter.

Second, the resistor you're measuring must be isolated from the circuit. Measure it while it's still plugged into the board, and you also measure whatever else is connected in parallel with it. As we saw earlier, a parallel combination is always smaller than the smallest individual value, so you'll read a value smaller than the real one. If a resistor marked 220 ohms reads 132 ohms, the resistor isn't bad — there's a 330-ohm resistor sitting in parallel with it.

Reading Voltage Directly with an Arduino

You can also measure voltage with a board, no multimeter needed — that's exactly what an analog input does. The Arduino Uno's ADC converts anything from 0V up to the reference voltage into an integer from 0 to 1023.

// Read the voltage on A0 and convert it to volts.
// Note: the Uno's A0 is only safe up to 5V. Anything higher needs a voltage divider first.

const int SENSE_PIN = A0;
const float VREF = 5.0;      // Reference voltage. On USB power this actually wanders between 4.7 and 5.1V.
const float ADC_STEPS = 1024.0;

// Values for when you're using a voltage divider. If you're not, leave both at 0 and skip the correction below.
const float R_TOP = 10000.0;    // The side toward what you're measuring
const float R_BOTTOM = 20000.0; // The side toward GND

void setup() {
  Serial.begin(115200);
}

void loop() {
  int raw = analogRead(SENSE_PIN);

  // One step is 5.0 / 1024 = 0.00488V, roughly 4.9mV.
  float pinVolts = (raw * VREF) / ADC_STEPS;

  // If a divider was used, convert back to the original voltage.
  // Divider ratio = R_BOTTOM / (R_TOP + R_BOTTOM) = 20000 / 30000 = 0.667
  float sourceVolts = pinVolts * ((R_TOP + R_BOTTOM) / R_BOTTOM);

  Serial.print("raw=");
  Serial.print(raw);
  Serial.print("  pin=");
  Serial.print(pinVolts, 3);
  Serial.print("V  source=");
  Serial.print(sourceVolts, 3);
  Serial.println("V");

  delay(500);
}

Two lessons are packed into this code.

One is resolution. 5V divided into 1024 steps means each step is about 4.9mV. Anything smaller than that is, in principle, indistinguishable no matter how carefully you write the code — you cannot get past this limit.

The other is reference voltage. The code above hardcodes VREF at 5.0, but an Arduino running on USB power actually has its 5V rail wandering between 4.7V and 5.1V. That means every single reading already carries a few percent of built-in error. If you need an accurate value, either measure the actual voltage on the 5V pin with a multimeter and feed that into VREF, or use the built-in reference voltage instead. The same principle applies here too: measurement is the authority, not calculation.

Conclusion — Choosing a Component Ultimately Means Deciding on a Current

Everything above boils down to one sentence: choosing a component in a circuit mostly means deciding how many milliamps you want.

Voltage is usually a given. The board is either 5V or 3.3V, and that's not something you get to pick. The voltage a component needs is written on its datasheet too. What's left as a free variable is current, and the component that sets it is the resistor. That's why the calculation for choosing a resistance value takes up so much of circuit design.

And going back to the LED at the top of this post, it's now obvious why that circuit failed. There was no resistor, so nothing had decided the current. With nothing deciding it, current climbs to whatever maximum physics allows — and that maximum is almost always higher than what the component can survive.

Next time, we'll properly calculate that LED circuit: confirming with real numbers why an LED isn't a part you can treat like a resistor, and why every color ends up needing a different resistance value.

현재 단락 (1/131)

Plug an LED into a breadboard: long leg to Arduino D9, short leg to GND. The code is one line: `digi...

작성 글자: 0원문 글자: 17,667작성 단락: 0/131