Learning Goals 5 min
By the end of this lesson you will be able to:
- Identify the three pins of a potentiometer — two ends and a centre wiper — and explain why the wiper voltage sweeps smoothly from 0 V to 5 V as the knob turns.
- Wire a potentiometer as a built-in voltage divider: end pins to 5V and GND, wiper to an analog input. No partner resistor needed — the pot is the divider.
- Read the wiper with
analogRead(0–1023) and use the value to drive an output continuously — LED brightness, tone frequency, animation speed — whatever needs a smoothly tweakable knob.
Warm-Up 10 min
L01-36 to L01-39 introduced four environmental sensors — the world dictates what they read. Today's sensor is different: it's a human input. A knob the user turns. The chip reads the position. The link between finger and software has never been more direct.
Quick-fire puzzle
Knobs are everywhere — a stereo's volume dial, a car's heating control, a guitar amp's tone, the old-style dimmer switch in a dining room. They all feel the same: turn left, less; turn right, more.
- Inside any of these, what physical thing do you think changes when you turn the knob?
- If the dimmer dial were just a regular variable resistor — say, between 0 Ω and 10 kΩ — wired directly to an LED, what would happen as you turned it?
- Could you wire that same dimmer dial to an Arduino's analog input the way you wired the LDR last week? What new piece would you need?
Reveal the answer
- A long strip of resistive material has a sliding metal contact (the "wiper") pressed against it. As the knob turns, the wiper slides along the strip. The fraction of the strip on each side of the wiper acts as a resistor.
- The LED would dim and brighten with the knob — more resistance = less current = dimmer LED. But this only works for the LED; for a microcontroller you don't have one.
- You'd need a partner resistor to make a voltage divider — exactly what you built in L01-36 with the LDR. Here's the punchline of today's lesson: a potentiometer is a built-in voltage divider. The wiper acts as the junction. You don't need to add a partner; the part already contains both halves of the divider, with the wiper position controlling the ratio.
New Concept — the wiper is the junction 15 min
The big idea — three pins, one knob
A potentiometer (or "pot" for short) is a three-pin component that looks like a small blue or grey cube with a knob or shaft on top. Inside:
- A resistive track shaped in an arc (rotary pots) or strip (slider pots) with a fixed total resistance — typical hobby values are 10 kΩ or 100 kΩ.
- A wiper — a small metal arm that touches the track and moves along it as the knob turns.
- Three external pins: two end pins connected to the two ends of the track, and one wiper pin in the middle.
The trick: connect the two end pins to 5V and GND. The track is now a 10 kΩ resistor with 5 V across it. The wiper taps a point somewhere along that track — depending on knob position. That point's voltage is exactly the junction of a voltage divider, with the two halves of the track playing the roles of R1 and R2 from L01-38.
What the wiper voltage works out to
Reusing L01-38's formula with Rb as the bottom resistor:
Vwiper = 5 V × Rb / (Ra + Rb)
And since Ra + Rb always equals the pot's full rated value, this simplifies into "the fraction of the track between the wiper and GND":
- Wiper at the GND end (Rb = 0):
Vwiper = 0 V→analogRead = 0 - Wiper in the middle (Ra = Rb):
Vwiper = 2.5 V→analogRead ≈ 512 - Wiper at the +5 V end (Ra = 0):
Vwiper = 5 V→analogRead = 1023
So a pot wired with ends to +5 V and GND gives you the full analogRead range, sweeping smoothly as you turn the knob. That's the whole point of the part.
The "value doesn't really matter" rule
You'll see 10 kΩ pots, 100 kΩ pots, even 1 kΩ pots in hobby kits. For analogRead, the value almost doesn't matter — the divider ratio is what determines the wiper voltage, and the ratio is what knob position controls regardless of the total. A 10 kΩ pot at half-turn gives the same 2.5 V as a 100 kΩ pot at half-turn.
The total value only matters for current: a 1 kΩ pot wastes 5 mA continuously (5 V ÷ 1 kΩ) through its track; a 100 kΩ pot wastes only 0.05 mA. Both are fine for a Uno; the 10 kΩ default is a nice middle ground.
Reading the wiper in code
Identical to L01-36 — there is no new function or pattern. Just read A0:
int knob = analogRead(A0); // 0..1023 across the knob's full sweepThat's the entire interface. Compare against a threshold for binary decisions (if (knob > 512) …), or scale to drive an output continuously (analogWrite(LED_PIN, knob / 4)), or use the number any way that makes sense.
Why it matters
Pots are the bridge between human and machine. Every physical knob on every device — guitar amplifier tone, oven temperature dial, lab-equipment fine-tune, old-school radio volume — is some form of pot. They also make development dramatically easier: instead of editing a constant in code and re-uploading every time you tune a parameter, wire a pot, point your sketch at it, and tune live with your fingers. Today's lesson is the foundation of every "control surface" you'll build, plus the developer's secret weapon for prototyping.
Worked Example — knob to LED brightness 20 min
The wiring
Three components: the pot, one LED with a 220 Ω resistor, and the breadboard's shared rails.
- Pot straddling three columns: one end-pin column jumpers to the + rail (5V), the other end-pin column to the − rail (GND), the middle (wiper) column runs a green signal wire to A0.
- LED on ~D9 with a 220 Ω resistor (L01-07 wiring), cathode to the − rail. ~D9 is PWM-capable, which you'll need for the brightness control.
- The + rail jumpers to the Arduino's 5V pin; the − rail jumpers to GND.
On the breadboard what you build
On paper what engineers draw
A0 reads whatever fraction of the 5 V it has reached. That is L01-38's divider with a knob on it.Step 1 — Print the wiper value live
// Pot reader — see the value as you turn the knob
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println(analogRead(A0));
delay(100);
}Upload at 9600 baud, open the Monitor. Turn the knob fully one way — the reading should pin at 0 or 1023. Turn the other way — pins at the opposite extreme. Turn through the middle — readings sweep smoothly through every value in between. Roughly half a turn = roughly 512. If your minimum isn't 0 and your maximum isn't 1023, you've wired only two of the three pins; recheck the divider connections.
Step 2 — Drive the LED brightness from the knob
The killer app of pots: live continuous control of an output.
// Knob dimmer — turn pot, LED brightens or dims
const int POT_PIN = A0;
const int LED_PIN = 9;
void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
int knob = analogRead(POT_PIN); // 0..1023
int bright = knob / 4; // 0..255 (1023/4 ≈ 255)
analogWrite(LED_PIN, bright);
Serial.print("knob=");
Serial.print(knob);
Serial.print(" bright=");
Serial.println(bright);
delay(30);
}Upload. Turn the knob; the LED brightens and dims smoothly. Watch the Monitor — knob value sweeps 0–1023, brightness value sweeps 0–255, both move in lockstep. Your finger now controls a continuous PWM output through twenty lines of code.
Trace the maths on paper
For each knob position, fill in what the sketch sends to the LED.
| Knob position | analogRead | knob / 4 | LED visible brightness |
|---|---|---|---|
| Fully left | 0 | 0 | off |
| Quarter turn | ~256 | ____ | ____ (about 25%) |
| Halfway | ~512 | ____ | ____ (about 50%) |
| Three-quarter turn | ~768 | ____ | ____ |
| Fully right | 1023 | ~255 | full brightness |
Notice that 1023 / 4 = 255 remainder 3 — integer division throws away the remainder. The biggest possible PWM value you can get from this formula is 255, not 256, which is conveniently the maximum analogWrite accepts. The maths is exact at both ends — no clamping needed.
Basic 7 min
Goal: A pot-driven tone. Replace the LED with a piezo on D8 (L01-14 wiring). Turn the knob; the buzzer's pitch slides up and down. Range: 200 Hz at full left, 2000 Hz at full right.
1. Think first (on paper, no typing yet). The real puzzle is turning the knob (0–1023) into a frequency (about 200–2000 Hz):
- The knob gives 0 at full left. What do you add so the lowest note is 200 Hz?
- The range needs to be about 1800 Hz wide, but the knob only goes up to 1023. What can you multiply by to stretch it? It doesn't have to land exactly on 2000.
- Test your sum on paper with 0, 512 and 1023.
2. Code it. Start from your Step 2 knob dimmer. Swap the LED for the buzzer, and replace the brightness maths and analogWrite with your frequency and a note that keeps playing (L01-32). Keep a short delay (about 20 ms) at the end of loop().
3. Upload and observe. Turn the knob slowly end to end. Compare the lowest and highest notes with your paper numbers.
It works if: full left gives a low hum, full right a high squeal, and the pitch slides smoothly in between.
Questions:
- Write your frequency line here: ____. What range does it actually give? Work out the lowest and highest. ____
- You've built a tiny theremin! Sweep your finger through the knob smoothly — does the pitch sound continuous or stepped? ____
- You didn't need
noToneanywhere. Why not? ____ (Hint: eachtonecall instantly replaces the previous frequency without stopping in between.) - Try dividing the knob by 2 instead of multiplying. What's the new pitch range? Does the lower end sound very different? ____
Challenge 1 7 min
Goal: A knob-controlled blink rate. Add an LED on D8 (any digital pin). The LED blinks; the knob sets the blink interval from 50 ms (very fast) at full left to 1000 ms (slow) at full right.
The two ends of the knob, over the same two seconds:
1. Think first (on paper, no typing yet):
- The knob gives 0–1023. That is already nearly a second in milliseconds. What do you add so the shortest blink is 50 ms, not 0?
- Your L01-22
millis()blink compares the time against a fixed interval. If the interval comes from the knob instead, how often must the knob be read? - Why would a
delay()-based blink feel sluggish when you turn the knob?
2. Code it. Start from your L01-22 millis() blink sketch. First add the knob reading and upload (nothing should change yet). Then let the knob set the interval.
3. Upload and observe. Turn the knob to each end and compare with the diagram. Then turn it while the LED is in a long blink — does the change show up straight away?
It works if: full left flickers fast, full right blinks about once a second, and the speed changes the moment you turn the knob.
Questions:
- Write your interval line here: ____. What are the shortest and longest intervals it gives? ____
- Why does this need
millis()rather thandelay(interval)? Try replacing it withdelayand see what happens to knob responsiveness. ____ - Reverse it so left = slow, right = fast. What did you change? ____
- What's the smallest blink interval that still looks like blinking to your eye, rather than just "dim"? ____ (Hint: around 30 ms is the human flicker fusion threshold.)
Challenge 2 6 min
Goal: A pot-tuned threshold for the L01-36 nightlight. Now you don't pick the threshold in code — the user dials it in. Two analog sensors at once (LDR on A0, pot on A1), one LED on D8.
The Monitor should let you watch both numbers side by side, like this:
light=420 threshold=600 dark=1 light=421 threshold=380 dark=0
1. Think first (on paper, no typing yet):
- In your L01-36 nightlight, the threshold is fixed when you upload. Now it must follow the knob. Can it still be a
const? When must it be read? - The LED rule is the same as before: light when the LDR reading is below the threshold. Where does each of the two numbers come from now?
darkon the Monitor is 1 or 0. Which comparison gives you that yes/no?
2. Code it. Start from your L01-36 nightlight sketch. Wire the pot's wiper to A1 and the LED to D8. Change the threshold first, then add the prints.
3. Upload and observe. In normal room light, turn the knob slowly until the LED switches on. Read both numbers at that moment.
It works if: you can sit in normal room light and turn the knob until the LED just switches on — and back until it just switches off.
Questions:
- What did you do with the old
THRESHOLDconstant, and why? ____ - Predict, then test: what does the LED do with the pot fully right (threshold = 1023)? Why? ____
- And with the pot fully left (threshold = 0)? ____
- Compare this with the L01-36 stretch task (auto-calibrating with millis). Which approach feels more "real product" — and why? ____ (Hint: both have a place; physical knobs vs auto-calibration is a UX design decision.)
Challenge 3 — pot-controlled animation speed 10 min
"Take last week's chase animation, add a tempo knob"
Open your L01-34 sketch — the five-LED chase / bounce / wave animation that used 2D arrays. Today, replace the hardcoded stepMs value in your playPattern calls with a live reading from a pot wired to A1. Turning the knob speeds the animation up or slows it down without uploading.
Your task:
- Keep the L01-34 wiring (5 LEDs on D7–D11, sharing GND). Add a pot wired the L01-40 way (ends to 5V and GND, wiper to A1). You'll use 6 Arduino pins total: D7–D11 + A1.
- The step time should run from about 30 ms (super fast) to about 235 ms (relaxed) across the knob's range.
- Every
playPatterncall should use the knob's step time instead of its own fixed number. Do not changeplayPattern,showFrameor the arrays.
1. Think first (on paper, no typing yet):
- The knob gives 0–1023, and you want about 30–235. The range you want is about 205 wide. What can you divide 1023 by to get about 205? What do you then add so the bottom is 30? Check with 0 and 1023.
- Where in
loop()should the knob be read so every round of patterns picks up the newest setting? - How many places in
loop()currently have a hard-coded step time?
2. Code it. Open your L01-34 sketch, save a copy, and change only loop() (plus a pin constant if you like).
3. Upload and observe. Turn the knob while the chase runs. You should see the animation respond in real time.
It works if:
- Fully-left knob (reading near 0): the animation blurs into a continuous moving glow.
- Fully-right knob (reading near 1023): the animation crawls one step every quarter-second or so.
- Mid-knob: the chase looks like the default L01-34 speed.
- You can change the speed during the animation — the next step picks up the new value.
Recap 5 min
A potentiometer is a three-pin component containing a built-in voltage divider — a resistive track between two end pins with a sliding wiper (middle pin) that taps a point along it. Wire the two ends to 5 V and GND; the wiper now sweeps from 0 V to 5 V as you turn the knob. Read it with analogRead(A0) — no partner resistor needed because the divider is inside the part. The value (10 kΩ, 100 kΩ) hardly matters for ADC reading; only ratio matters. Use the result to drive any continuous output — LED brightness, tone frequency, animation speed, threshold value — turning your finger into a live software dial.
- Potentiometer (pot)
- A three-pin variable resistor with a moving wiper. The two end pins are fixed at the ends of the resistive track; the wiper taps a point along it. The most common manually-adjusted analog input.
- Wiper
- The sliding contact inside a pot. Its position along the resistive track is what the knob controls. The middle pin connects to it.
- End pins
- The two pins at the ends of a pot's resistive track. Interchangeable — swap them and the knob simply turns the other way for the same reading.
- Built-in voltage divider
- The key insight about pots: with the two end pins at 5 V and GND, the part already is a divider. No partner resistor needed; the wiper voltage gives you the full ADC sweep from 0 to 1023.
- Live tuning
- The developer's practice of wiring a pot to a code parameter — speed, threshold, brightness — so it can be adjusted while the sketch is running, instead of editing constants and re-uploading. One of the most useful prototyping tricks.
- Linear vs audio (log) taper
- Linear pots change voltage evenly with knob angle. Audio-taper pots crowd the change into one end (matching how the ear hears volume). Hobby-kit pots are almost always linear; check the label if it matters.
Extra Mission 5 min
Part 1 — Design a knob-controlled device
Knobs are everywhere: volume, oven timers, fan speed. Design a device where one or two knobs set something.
Your design must include:
- What the device is.
- What each knob controls, and its range — for example 200 to 2000 Hz, or 50 to 1000 ms.
- The formula that turns 0–1023 into that range.
- The outputs it drives, and their pins.
Part 2 — Make it
Build it with up to two pots on A0 and A1. Print the raw knob value and your scaled value side by side.
Bring back next class:
- The saved
.inofile. - A short video showing each knob changing the output.
- A Serial Monitor screenshot of raw and scaled values.
Heads up for next class: L01-41 "The map() Function" introduces the one-liner that replaces every knob / 4, knob * 2 + 200, knob / 5 + 30 in today's lesson. Same idea — scale a value from one range to another — but the built-in map() makes it readable in a glance. After today, you'll be doing these conversions manually; tomorrow you'll have a clean tool for them.