From an analog input to a digital output. Concept illustration, not a wiring diagram.
Build a potentiometer-controlled LED dimmer on an Uno R3. You need a 10 kilohm potentiometer, LED, 330 ohm resistor, breadboard, and jumpers. The task combines ADC scaling, PWM output, and independent serial reporting.
With power disconnected, connect the potentiometer's outer pins to 5V and GND, and its wiper to A0. Connect D9 through the 330 ohm resistor to the LED anode, and the cathode to GND. Confirm the wiper pin from the part's pinout. The LED series path is the same circuit used in the foundations lesson.
Signal
Purpose
Range on Uno R3
A0
Read knob voltage
0–1023 ADC codes
D9
LED PWM output
0–255 duty command
Serial
Report raw reading
9600 baud
The PWM pin switches between logic levels. It does not provide a smoothly adjustable DC voltage to arbitrary devices. An LED's perceived brightness is also not linearly proportional to the numeric command.
Upload a complete controller
Arduino C++
const byte potPin = A0;
const byte ledPin =9;
unsigned long lastReport =0;
voidsetup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
voidloop() {
constint raw =analogRead(potPin);
constint duty = raw / 4;
analogWrite(ledPin, duty);
const unsigned long now =millis();
if (now - lastReport >=250) {
lastReport = now;
Serial.print(F("raw=")); Serial.print(raw);
Serial.print(F(" duty=")); Serial.println(duty);
}
}
On this board, integer division by four maps 0–1023 to 0–255. ADC sampling and LED updates continue while reporting waits for its interval. Use Serial Monitor at 9600 baud to compare knob position and output.
Acceptance checks: Fully toward GND gives near zero and an off LED. The other end gives near full scale and a bright LED. Mid-position is around half-scale, subject to component tolerance. Response continues between serial reports. If readings drift with the knob disconnected, that is a floating input, not a valid sensor reading.
Extensions: Add a debounced D2 button to enable/disable output, preserving the knob setting. Add a filter and measure the new response time. Write down the desired startup state before changing the program.
Clean Code: Use descriptive constants instead of magic numbers
Instead of calling digitalWrite(13, HIGH) directly in your code, define descriptive constants like const int LED_PIN = 13; at the top of your file. This makes your code self-documenting and extremely easy to update if you change your wiring.