Buttons give an Arduino two choices: pressed or not pressed. A dial gives it hundreds of choices.
Today you will turn a knob called a potentiometer and watch the Arduino read its position as a number. Your code will translate that number into LED brightness, turning a simple knob into a real control panel. Then you will choose a danger zone and make the controller flash and chirp when the dial enters it.
At a glance
| Age range | 10–13 |
|---|---|
| Estimated time | 60–80 minutes |
| Difficulty | Beginner-plus |
| Parent involvement | Medium for the first potentiometer wiring check; light afterward |
| Major concepts | Analog input, potentiometer, Serial Monitor, map(), PWM brightness, constants, thresholds, if/else |
What you will learn
- How a potentiometer produces a changing input value.
- How
analogRead()turns that changing signal into a number from 0 to 1023. - How
map()translates one number range into another useful range. - How
analogWrite()uses a PWM pin to make an LED appear dimmer or brighter. - How the Serial Monitor helps you see what the Arduino is reading.
- How to choose and justify a threshold instead of guessing a magic number.
Before you begin
Complete Lesson 2: Build a Push-to-Shine Arduino Light first. You will reuse the safe LED circuit: Arduino output → resistor → LED long leg → LED short leg → ground. This time, use D9 because it is a PWM-capable pin that can make the LED appear brighter or dimmer.
Complete Lesson 4: Program an Arduino Sound-Effect Machine before attempting the required danger-zone challenge. That challenge reuses the piezo on D8.
For the first 10 minutes, you may rehearse the knob, LED, and A0 connection in Tinkercad Circuits. Then build it physically. The real knob may turn in the opposite direction from the simulated one, and discovering why is useful engineering evidence.
What you need
Required components
| Quantity | Item | Compatible substitute |
|---|---|---|
| 1 | Arduino Uno from the Arduino Student Kit | Genuine Uno R3 or Uno R3 SMD |
| 1 | Solderless breadboard | Standard half-size breadboard |
| 1 | 10k potentiometer with knob | Any three-terminal linear potentiometer, approximately 10k |
| 1 | LED, any color | Any ordinary 3–5 mm LED |
| 1 | 220 Ω resistor | 330 Ω or 560 Ω resistor; do not omit it |
| 1 | Piezo buzzer from the kit | Passive piezo buzzer compatible with Arduino tone(); used in the required challenge |
| 7–10 | Male-to-male jumper wires | Solid-core breadboard wires |
| 1 | USB-A to USB-B data cable | Arduino-branded USB-A-to-B data cable |
Optional components
- Cardboard, tape, and markers for a control-panel enclosure.
- Two more LEDs and resistors from Lesson 3 for the optional three-zone challenge.
- A maker notebook and pencil.
Tools
None. This project is solderless.
Computer/software requirements
- Arduino IDE 2 with Arduino Uno and its port selected.
- A Mac running macOS 10.15 or later, or Windows 10 64-bit or newer.
- Optional: a free Autodesk account and current browser for Tinkercad.
Safety and setup notes
- Unplug the USB cable before moving wires.
- The potentiometer is the first component in this course that connects to both 5V and GND. Put its three legs in three different, unconnected breadboard rows. Never place a 5V jumper and a ground jumper in the same connected row.
- The center potentiometer leg is called the wiper. It must connect to A0. The two outside legs connect to 5V and ground.
- Swapping the two outer potentiometer wires will not hurt the project. It simply reverses which turn direction means brighter.
- Keep the LED resistor in place. The piezo does not need a series resistor in this project.
- The adult should make the first 5V/GND check with the student. Step in if a component becomes warm, the board resets, or the 5V and ground paths may be shorted. Otherwise, let the student collect readings and choose the threshold.
Build overview
This project uses one continuous input and one continuous-looking output:
Turn knob → potentiometer creates a changing voltage → Arduino reads A0 (0–1023)
→ code maps it to 0–255 → Arduino D9 changes LED brightness
The Uno does not truly send a lower voltage to D9. Instead, analogWrite() sends very fast on/off pulses called PWM. When the pulses are on more of the time, your eyes see a brighter LED.
The main build is quiet: it controls light only. In the required challenge, you will add the piezo and create a danger-zone rule that overrides normal brightness with a flashing light and warning chirp.
Step-by-step build instructions
Step 1: Set up the 5V and ground rails
- Place the breadboard with its center trench running left to right.
- Use a red jumper to connect Arduino 5V to one breadboard rail. Treat it as the 5V rail.
- Use a black jumper to connect Arduino GND to a different breadboard rail. Treat it as the ground rail.
- Keep the Uno unplugged while you finish the circuit.
Checkpoint: point to the red 5V rail and the black ground rail. Confirm they are different rails and no jumper connects them together.
Step 2: Wire the potentiometer to A0
- Place the potentiometer so its three legs land in three separate, unconnected rows of the main breadboard area. It does not need to cross the center trench.
- Connect one outer potentiometer leg to the 5V rail.
- Connect the center leg—the wiper—to Arduino analog pin A0.
- Connect the other outer leg to the ground rail.
| Potentiometer connection | Destination | Job |
|---|---|---|
| Outer leg 1 | 5V rail | Gives one end of the dial’s range a high value |
| Center wiper leg | Arduino A0 | Sends the changing dial position to the Arduino |
| Outer leg 2 | Ground rail | Gives the other end of the dial’s range a low value |
Checkpoint: trace the three paths: 5V → outer leg, center leg → A0, other outer leg → ground. Do not assume left/right direction matters; it only decides which way the knob feels like “up.”
Step 3: Wire the LED brightness output
- Place the LED so its two legs are in different connected rows.
- Connect its short leg or flat-side leg to the ground rail.
- Put one end of the 220 Ω resistor in the row with the LED’s long leg. Put the resistor’s other end in a new, empty row.
- Connect that resistor’s free end to Arduino digital pin D9.
Checkpoint: trace the output path: D9 → resistor → LED long leg → LED short leg → ground. Ask: Why are we using D9 instead of the built-in LED?
Step 4: Upload the dial-and-light program
- Connect the Uno to the computer using the USB data cable.
- Open Arduino IDE and confirm Arduino Uno and its port are selected.
- Create a new sketch, remove any starter text, and paste or type the complete code below.
- Click Verify. Fix the first error before uploading.
- Click Upload and wait for Done uploading.
- Open Tools → Serial Monitor. Set its speed to 9600 baud if it is not already set.
Checkpoint: as you turn the knob, the LED should fade from dim to bright, and the Serial Monitor should display changing Dial and Brightness numbers.
Step 5: Collect evidence before choosing a rule
Turn the knob all the way one direction, then all the way the other. Record the low and high Dial values in your notebook. Then stop at a position that feels like “almost too high” and record that value too.
If turning clockwise makes the LED dimmer instead of brighter, that is not broken. Predict what would happen if you swapped the two outer potentiometer wires, then test it with USB unplugged.
Code
const int DIAL_PIN = A0;
const int LED_PIN = 9;
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
int dialValue = analogRead(DIAL_PIN);
int ledBrightness = map(dialValue, 0, 1023, 0, 255);
analogWrite(LED_PIN, ledBrightness);
Serial.print("Dial: ");
Serial.print(dialValue);
Serial.print(" | Brightness: ");
Serial.println(ledBrightness);
delay(100);
}
What the important code means
- Variables:
dialValueholds the number read from A0.ledBrightnessholds the translated number used to control the LED.DIAL_PINandLED_PINname the physical connections. setup(): this runs once. It prepares D9 as an output and starts the Serial Monitor connection at 9600 baud.loop(): this repeats forever: read the knob, translate its value, set brightness, show the data, and wait one tenth of a second.- Inputs and outputs:
analogRead(DIAL_PIN)is the input.analogWrite(LED_PIN, ledBrightness)is the output. - New functions:
analogRead()gives the Uno’s A0 input a number from 0 to 1023.map()converts that wide range into the 0–255 rangeanalogWrite()uses for LED brightness.Serial.print()lets you look inside the Arduino’s thinking. - Why D9? On an Uno, D9 supports PWM, which makes
analogWrite()useful for apparent LED brightness. A normaldigitalWrite()would give only on or off.
Arduino’s official potentiometer guide explains the three terminals. The official analogRead() reference and analogWrite() reference explain the read and PWM-output functions.
Make it work
The first version works when all of these are true:
- Arduino IDE says Done uploading.
- Turning the knob makes the LED change smoothly from very dim to very bright.
- The Serial Monitor shows Dial values that move across a large part of the 0–1023 range.
- The Brightness number changes within 0–255.
- You can point to the center wiper leg and explain that it sends the changing value to A0.
- You can explain why D9 is an output and A0 is an input.
Understand it
- What does the center wiper leg of the potentiometer do?
- Why does
analogRead()make a number from 0 to 1023 while LED brightness uses 0 to 255? - What job does
map()do in this program? - Predict what would happen if you changed the final
255inmap(...)to100. - Why does swapping the two outside potentiometer wires reverse the knob direction but not damage it?
Required “change it” challenge
Desired outcome: add a named danger zone near the high end of the dial. In that zone, the LED flashes at full brightness and the piezo gives a warning chirp. Outside the zone, the LED continues to fade smoothly and the piezo stays quiet.
Constraints: use a named constant such as DANGER_THRESHOLD; choose the number only after recording real dial values; add the piezo on D8 using the Lesson 4 wiring pattern; use an if/else; explain in a code comment why you chose the threshold.
Hints:
- Use your recorded values to choose a threshold in the upper part of the real range—perhaps 750, 800, or a different number that fits your dial. There is no magic correct number.
- Add
const int PIEZO_PIN = 8;andconst int DANGER_THRESHOLD = ...;near the other constants. AddpinMode(PIEZO_PIN, OUTPUT);insetup(). - In the danger part of your
if, override the normal fade: make the LED fully bright, play a shorttone()on D8, then turn the LED off and callnoTone()after a short wait. Put the normalanalogWrite()in theelsepart so it runs only outside danger.
Parent guidance: require the student to record values before naming the threshold. A good struggle is choosing a threshold that feels intentional rather than copying 800. If he is stuck, ask, “What did the Serial Monitor actually say near the danger area?” Step in if 5V/ground wiring is uncertain, if the piezo is uncomfortably loud, or if 15–20 minutes pass without a new test. Save the working dimmer sketch before starting the danger-zone change.
Optional enhancements
Try this
Use the piezo from the challenge to make a continuous pitch that rises as the dial turns. Hint: map the 0–1023 dial range to a sound-frequency range such as 200–1500, then call tone() with the mapped number. Start at a comfortable volume and stop if the sound is annoying.
Challenge
Reuse the red, yellow, and green LEDs from Lesson 3 to create three dial zones: safe, caution, and danger. First write a small table that lists each range and its output. Then use if, else if, and else to match your plan.
Stretch
Make a cardboard “reactor,” spaceship, or control-room panel around the dial. Add a scale with numbers or colors that match your actual threshold. On the back, draw the input → code decision → output path.
Debugging guide
| What you notice | Likely cause | Smallest next diagnostic step |
|---|---|---|
| The Uno is not detected or has no green power LED | Computer/cable issue, not the dial circuit | Unplug all breadboard wires and run Lesson 1’s built-in Blink sketch with the supplied data cable. |
| The LED is always bright, always dark, or changes only at one end | Center wiper is not connected to A0, or one outer leg lacks 5V/ground | Open Serial Monitor and check the raw Dial number first. Then trace only the three potentiometer paths. |
| Dial values stay near 0 or near 1023 | One outer potentiometer wire is loose or the wiper is in the wrong row | Verify outer leg → 5V, center leg → A0, other outer leg → ground. |
| The LED only turns on/off instead of fading | Wrong pin or digitalWrite() used instead of analogWrite() | Confirm the LED signal wire goes to D9 and the code uses analogWrite(LED_PIN, ledBrightness). |
| Turning clockwise makes the LED dimmer | The two outer potentiometer wires are reversed | Unplug USB, swap only the two outer potentiometer wires, and test the prediction. |
| Serial Monitor is blank or unreadable | Monitor is closed, baud rate does not match, or Serial.begin() is missing | Open Serial Monitor and set it to 9600 baud; compare the setup() line to the code. |
| Danger zone starts too early or never starts | Threshold was guessed or comparison direction is wrong | Print or read the current Dial value near the chosen location, then adjust only DANGER_THRESHOLD or the comparison. |
| The danger LED flashes but there is no chirp | Piezo is not on D8/ground, or noTone() happens immediately | Trace D8 → piezo positive and piezo negative → ground; then make sure the tone() has a short wait before noTone(). |
Use the Debugging Ladder when one small diagnostic does not reveal the problem. Return to the original dimmer code before debugging a custom danger zone.
Recap
You used your first analog input. Instead of a button’s yes/no answer, the potentiometer gave the Arduino a changing number. Your program translated that number with map() and used PWM on D9 to control LED brightness. In the danger-zone challenge, you turned real data into a rule and combined light with sound.
Show what you learned
Write or tell your parent:
- What low and high Dial values did your real knob produce?
- What threshold did you choose, and what evidence made you choose it?
- What failed, if anything, and what was your smallest debugging test?
- Explain
map()or the center wiper leg in your own words.
In your maker notebook, draw a scale from low to high, mark your danger threshold, and write what the LED/piezo do in each region. Take a direct overhead photo before changing any wires.
What’s next
Next, the Arduino will stop listening to your hand and start noticing the room. In Lesson 6, a light sensor will measure brightness, and you will calibrate a smart night-light. The Serial Monitor and threshold thinking from today will be essential. Continue to Lesson 6: Build a Smart Night-Light.
NEXT · LESSON 06Lesson 6: Build a Smart Night-Light
Parent guide
Prepare in advance
- Confirm the Uno still uploads the Lesson 1 Blink sketch.
- Set out the Uno, breadboard, potentiometer, LED, resistor, piezo, jumpers, cable, and notebook. Keep extra LEDs and cardboard aside until the main dimmer works.
- Identify the potentiometer’s center wiper leg and make sure it can sit in three separate breadboard rows.
- Open the Serial Monitor only after the main sketch has uploaded; set it to 9600 baud.
Let the child work independently when
- tracing the three potentiometer connections after the first adult safety check;
- predicting which direction will make the LED brighter;
- reading and recording real Serial Monitor values;
- deciding the threshold and writing the rule in English; and
- building the cardboard control-panel extension.
Resist taking over when
- the knob direction feels backward but the student can predict and test a swap;
- the Serial Monitor values are not perfectly 0 and 1023 but change clearly;
- he is deciding which threshold best matches his recorded data; or
- the first control-panel label is not polished but communicates the range.
Step in when
- 5V and ground may be connected in the same breadboard row, a component is warm, or the board resets;
- the computer cannot connect to the Uno before the circuit can be tested;
- he has repeated one diagnostic without a new hypothesis; or
- the danger-zone experiment has broken the working dimmer and he cannot restore it. Keep a copy of the original code before the challenge.
Simple understanding-based assessment
Ask the student to point to the input, output, 5V rail, ground rail, wiper, and resistor. Then ask, “Why do we use map()? What evidence chose the threshold?” Award one point each for a working/tested build, a correct explanation, a deliberate danger-zone change, and a useful debugging/notebook note. A bright LED without data or explanation is not a complete success.
Further resource: Arduino: Basics of Potentiometers