Digital ChallengeWorkshop · Arduino × Processing
L04Workshop lab

Ohm Meter

Measure a resistor with a resistor.

Use a known resistor as a reference, read the divider voltage, apply Ohm’s law, and show the unknown value in Processing — including kΩ / MΩ units and an out-of-range warning.

2 × 45 min difficultyPhysicsMathematics
Ohm Meter
Ohm’s lawVoltage dividerADC errorUnit conversion
01Before you start

What you’ll learn

By the end of this lab you can…
  • 1State Ohm’s law and the divider formula that matches this wiring.
  • 2Explain why the unknown resistor sits on the 5 V side in the handbook figure.
  • 3Compute R_x from V_A0 and discuss when the measurement is accurate.
  • 4Guard against a missing resistor (open circuit → do not divide by zero).
Key vocabulary
Ohm’s law
V = I × R. Voltage, current and resistance are three faces of one relationship.
Known / reference resistor
The resistor whose value you trust (here 1 kΩ). You calculate the other one from it.
Tolerance
A 1 kΩ ±5 % resistor may actually be 950–1050 Ω. That error transfers into R_x.
Open circuit
No path for current. analogRead sits near 0 or 1023 and the formula explodes — guard it.
02Kit list

Required equipment

ComponentQtyPurpose
Arduino Uno1ADC
Known resistor (1 kΩ)1Reference
Unknown resistor1The one you measure
Breadboard + jumpers1Divider
USB + both IDEs1Display
03Theory

One formula — the one that matches the figure

The original handbook wrote two opposite formulas. The Fritzing figure labels the unknown on the 5 V side and the known toward GND. The firmware below follows that figure.

Unknown on the 5 V side, known to GND, tap to A0 — workshop figure.
Unknown on the 5 V side, known to GND, tap to A0 — workshop figure.
Formula
V_A0 = 5 V × R_known / (R_x + R_known)
Unknown on the 5 V side, known on the GND side.
Formula
R_x = R_known × (5 V / V_A0 − 1)
If you swap the two resistors
The formula flips to R_x = R_known × V_A0 / (5 V − V_A0). Pick one wiring, write it on the breadboard, and do not mix the equations.

Accuracy is best when R_x ≈ R_known. If you measure 1 MΩ against a 1 kΩ reference, V_A0 is a few millivolts — one ADC step is a huge error. Choose a known resistor in the same decade as the unknown.

InteractiveVirtual ohm meterSweep R_x through the E12 series. Watch the meter and the % error.
Known resistor
V_A0 = 5 × 1.00 kΩ / (2.20 kΩ + 1.00 kΩ) = 1.563 V
analogRead = 320
R_x = 1.00 kΩ × (5 / 1.564 − 1) = 2.20 kΩ
2.20 kΩ
Real
2.20 kΩ
Measured
2.20 kΩ
Error
-0.14%
04Firmware

Arduino — solve for R_x

LeadGoes to
Unknown resistor5V → A0 (junction)
Known 1 kΩA0 → GND
A0The junction of the two resistors
OhmMeter.inoArduino · C++
const int analogPin = A0;
const float Vin = 5.0;
const float Rknown = 1000.0; // ohms — change if you use another reference

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

void loop() {
  int raw = analogRead(analogPin);
  if (raw < 2) {          // open circuit / missing unknown
    Serial.println(-1);
    delay(400);
    return;
  }
  float Vout = (raw * Vin) / 1023.0;
  float Rx = Rknown * (Vin / Vout - 1.0);
  Serial.println(Rx);
  delay(400);
}
UpdatedMatches the figure. Sends −1 when the tap is ~0 V (open / missing unknown) so Processing does not print Infinity.
05Visualise

Processing — units and range

OhmDisplay.pdeProcessing · Java
import processing.serial.*;

Serial myPort;
float resistance = 0;

void setup() {
  size(520, 240);
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil('\\n');
}

void draw() {
  background(18);
  fill(240);
  textSize(20);
  text("Measured resistance", 36, 56);
  textSize(36);
  if (resistance < 0) {
    fill(255, 92, 77);
    text("OPEN — check wiring", 36, 120);
  } else {
    text(formatOhms(resistance), 36, 120);
  }
}

String formatOhms(float r) {
  if (r >= 1e6) return nf(r / 1e6, 1, 2) + " MΩ";
  if (r >= 1000) return nf(r / 1000, 1, 2) + " kΩ";
  return nf(r, 1, 1) + " Ω";
}

void serialEvent(Serial p) {
  String val = trim(p.readStringUntil('\\n'));
  resistance = float(val);
}
06From the workshop

Student tasks

Basic
Measure a resistor whose printed value you already know.
Within ~10 % of the colour-code value.
Intermediate
Display kΩ / MΩ automatically.
2200 prints as 2.20 kΩ.
Intermediate
Warn if the reading is outside 100 Ω–1 MΩ.
A red “out of range” label.
Advanced
Add a key 1 / 2 / 3 in Processing that tells Arduino which known resistor you plugged in.
One sketch, three ranges.
Challenge
Estimate the colour-code tolerance vs your measurement error.
A short lab note: which error is bigger?
07When it doesn’t work

Troubleshooting

ProblemLikely causeFix
Always −1 or always huge.Unknown and known swapped, or a loose jumper.Unknown on 5 V side. Re-seat A0 on the junction.
20–30 % error on a 100 kΩ part.1 kΩ reference is the wrong decade.Use 10 kΩ or 100 kΩ as R_known.
Reading drifts.You are holding the resistor leads — your skin is a parallel path.Use the breadboard, not your fingers.
Golden rule
Check the physical connections first, then the code. If nothing works, unplug, close both programs, reconnect and try again.
08Student edition

Exercises

Basic · 1Intermediate · 2Advanced · 1Challenge · 1
L04-E1BasicCalculate 8 min

Do the algebra

R_known = 1000 Ω, V_A0 = 2.0 V, V_in = 5.0 V, unknown on the 5 V side. Find R_x.

R_x = 1000 × (5/2 − 1).
5/2 − 1 = 1.5, so R_x = 1500 Ω (1.50 kΩ).
L04-E2IntermediateCalculate 10 min

What does the ADC see?

R_x = 2.2 kΩ, R_known = 1.0 kΩ, unknown on 5 V side. Compute V_A0 and analogRead.

V = 5 × 1000/(2200+1000) = 1.563 V. raw ≈ 1.563/5 × 1023 = 320.
L04-E3IntermediateExplain 8 min

Why not measure 1 MΩ with 1 kΩ?

In 5–6 sentences, explain why a 1 kΩ reference is a bad choice for a 1 MΩ unknown. Mention V_A0 and one ADC step (≈ 4.9 mV).

V_A0 = 5 × 1k / (1M + 1k) ≈ 5 mV — about one ADC step. A jump of 1 count changes the computed R_x by tens of percent. The meter is “legal” but useless. Match the decades: use 100 kΩ or 1 MΩ as the known resistor.
L04-E4AdvancedDebug 8 min

Infinity on the screen

Someone unplugged the unknown resistor. Processing prints Infinity Ω. Point to the line that blew up and write the guard.

unguarded.inoArduino · C++
float Vout = (raw * 5.0) / 1023.0;
float Rx = 1000.0 * (5.0 / Vout - 1.0);
Serial.println(Rx);
If raw ≈ 0 then Vout ≈ 0 and 5.0 / Vout is infinity. Send a sentinel (−1) and let Processing print OPEN.
guardArduino · C++
if (raw < 2) { Serial.println(-1); return; }
float Vout = (raw * 5.0) / 1023.0;
Serial.println(1000.0 * (5.0 / Vout - 1.0));
L04-E5ChallengeCode 18 min

Range picker

Processing keys 1, 2, 3 send "K,1000\n", "K,10000\n", "K,100000\n". Arduino updates Rknown when a line starts with K. Keep printing R_x as a number.

On Arduino use Serial.readStringUntil and startsWith("K,"). On Processing keyPressed().
Arduino holds float Rknown = 1000. Each loop, if serial is available, read a line; if it starts with K,, parse the rest as the new known value. Processing’s keyPressed writes the matching command.
09Check yourself

Self-check quiz

Progress
0/5 answered · 0 correct
  1. Q01

    With unknown on the 5 V side, R_x equals…

  2. Q02

    Best accuracy when…

  3. Q03

    A 1 kΩ ±5 % reference means R_known might be…

  4. Q04

    Sending −1 over serial in this lab means…

  5. Q05

    Fingers on the leads make the reading…

10Beyond the classroom

Real world & extensions

Where this is used
Component testerWear sensor (pot + wiper)Liquid-level via resistanceSchool lab multimeter substitute
Extension ideas
  • +Colour-code quiz: hide the bands, measure, guess the colours.
  • +Measure a potentiometer as you turn it — a live ohm sweep.
  • +Compare three “1 kΩ” resistors from the kit and plot the spread.
Cross-curricular connections
SubjectConnection
PhysicsOhm’s law, series circuits, measurement uncertainty.
MathematicsRearranging V = Vin · R2/(R1+R2); percentage error.
11Think about it

Reflection & conclusion

?1

Which error was bigger on your desk — the resistor’s colour-code tolerance, or the ADC?

?2

How would you explain “choose a known resistor in the same decade” to a year-9 student?

?3

A multimeter uses several known resistors and a rotary switch. Which lab extension is that?

Conclusion

You did not buy an ohm meter. You built one from a law you already knew. That is the whole Digital Challenge in one sentence.