← All labs

LAB 005

Potentiometer: Measure and Dim

Measure a changing voltage on A0 and set the brightness of a resistor-protected LED on PWM pin D9.

Intro labArduino Uno R365 minTeams of 2

01

What you will build

A knob controls the perceived brightness of an external LED.

Why it matters

Input, measurement, processing and output form a reusable embedded control chain.

What you will learn

  • potentiometer as voltage divider and 10-bit ADC
  • analogRead 0–1023 and Serial Monitor
  • PWM analogWrite 0–255 on Uno D9, proportional control

02

Parts per station

  • 1 each An independently programmable Uno R3 per simultaneous station.
  • 1 each A small breadboard is a possible substitute after inspection.
  • 1 each Ordinary discrete LEDs; colors are optional.
  • 1 each One verified 220–330 Ω current-limiting resistor per LED; count and values before class.
  • 1 each Verify three accessible terminals; use a typical 10 kΩ pot if available.
  • several assorted Count leads usable for the chosen circuit before class.
  • 1 each Availability unconfirmed. One working USB-A to USB-B DATA cable for upload; cable length need not be 10 feet. This canonical item is procurement-only, so existing cable stock must be verified, not assumed.
Station planning and software

Three separately counted Uno R3 boards and four counted 830-point breadboards; fifth complete independent station is unconfirmed. Kit boards and small breadboards may add capacity only after identification and testing. Count usable USB data cables, LEDs, resistors, jumpers and any inputs before meeting. Count potentiometers. Five-LED bar graph additionally needs five LEDs and five resistors per station.

  • Arduino IDE or Arduino CLI with Arduino AVR Boards core; select Arduino Uno and the connected serial port.

Arduino IDE is the only required development environment. Arduino CLI is optional.

03

Assembly

Disconnect USB before changing breadboard wiring; check connections before reconnecting.

Use one 220–330 Ω resistor in series with each ordinary LED. Never connect 5V directly to GND.

Use Uno 5V and GND only across the potentiometer; never place the pot wiper on a GPIO output.

  1. 01

    Disconnect USB; connect pot outer terminals to Uno 5V and GND, and middle wiper to A0.

  2. 02

    First upload the observation sketch; set Serial Monitor to 9600 baud and turn the knob to see roughly 0–1023.

  3. 03

    Disconnect USB; build a D9 → 220–330 Ω resistor → LED anode → LED cathode → GND branch.

  4. 04

    Inspect connections, reconnect, upload the core brightness sketch and turn the knob slowly.

FromToPurpose / notes
Uno D9LED 1 series resistor 220–330 ΩDrive output with current limitingPut the resistor in series, never across 5V and GND.
LED 1 series resistorLED 1 anode (long leg)Feed LED in forward directionResistor may instead go on the cathode side if it stays in series.
LED 1 cathode (short leg/flat side)Uno GNDComplete the circuitLED must not be connected directly across 5V and GND.
Uno 5Vpotentiometer outer terminal 1Provide top of voltage dividerPower off before moving connections.
Uno GNDpotentiometer outer terminal 2Provide bottom of voltage dividerCommon ground with the LED circuit.
potentiometer center wiperUno A0Measure a 0–5 V variable inputSwitch the outer terminals to reverse knob direction.

Predict before you run

  • Does the knob change the measured number continuously or only HIGH/LOW?
  • At half travel, will duty cycle be near zero, half, or full?
Expected result

At one end of the knob LED is off, at the other it is bright; intermediate values change perceived brightness.

  • Check raw readings change in the observation sketch at 9600 baud.
  • Check brightness changes across at least three knob positions.

04

Code

On Uno D9, analogWrite produces PWM: fast on/off pulses with a duty setting of 0–255, not a continuous analog voltage.

Code experiments
01-read-potentiometer.inoDownload .ino
// Pot outer legs to 5V/GND; wiper A0; onboard LED gives a coarse check.
const int potPin = A0;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  int raw = analogRead(potPin);
  digitalWrite(LED_BUILTIN, raw >= 512 ? HIGH : LOW);
  delay(50);
}

About this version

experiment · Arduino Uno R3 · beginner

Read A0; onboard LED signals when the value exceeds midscale.

Only the potentiometer and three jumper leads; onboard LED is already on the Uno.

First analog measurement without an external output.

Hardware and wiring for this sketch
FromToPurpose / notes
Uno 5Vpotentiometer outer terminal 1Provide top of voltage dividerPower off before moving connections.
Uno GNDpotentiometer outer terminal 2Provide bottom of voltage dividerCommon ground with the LED circuit.
potentiometer center wiperUno A0Measure a 0–5 V variable inputSwitch the outer terminals to reverse knob direction.

How the code works

Lines 9–9

Uno R3 converts the 0–5 V input on A0 to a number from 0 to 1023.

Read A0; onboard LED signals when the value exceeds midscale.

How it works

Input, measurement, processing and output form a reusable embedded control chain.

The Uno samples 0–5 V on A0 into 0–1023; PWM on D9 switches rapidly with 0–255 duty-setting values. The full chain is input → read → process → output.

Experiments & challenges

  • Compare 0, near midpoint, and 1023 readings.
  • Swap only the pot outer 5V and GND leads with power off, then predict direction.
Scale it up

Optional threshold program, inverted response, and five-LED bar graph on D8–D12 each make a different decision from the same A0 reading.

Challenge

Map the knob backwards so clockwise dims, or choose three distinct brightness bands.

Check your understanding

Why can the analog reading be 700, but PWM output accepts 0–255?

Is PWM a steady 2.5 V analog output?

Learning summary

The Uno samples 0–5 V on A0 into 0–1023; PWM on D9 switches rapidly with 0–255 duty-setting values. The full chain is input → read → process → output.

Use this control chain next with light or temperature sensors, RGB LED, buzzer or a separately powered actuator design.

Troubleshooting

No upload or no power

Check USB data cable, selected Uno board and serial port; verify the power LED.

Unexpected external LED behavior

Disconnect USB, check the breadboard row, LED polarity, series resistor, GND, then compare the code pin with the wire.

Serial always 0 or 1023

Verify wiper goes to A0, both outer terminals reach 5V/GND, and Serial Monitor is at 9600 baud.

LED only on/off

Use the D9 PWM circuit and brightness sketch; compare mapped 0–255 values, and verify resistor and polarity.