TPL-16Templates/Potentiometer
Potentiometer
Read an analog value from a potentiometer and use it to fade an LED's brightness via PWM, while printing the raw and mapped values to the Serial Monitor.
Open in Playgroundbeginner · analog input · PWM · serial · potentiometer
FIG. 1Potentiometer · circuitTPL-16
02Sketch
sketch.inoArduino C++
25 lines
// Potentiometer — Analog Read → LED Brightness
// Turn the knob on the canvas and watch the LED fade + the value print to Serial.
const int POT_PIN = A0;
const int LED_PIN = 9; // PWM-capable pin
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
Serial.println("Potentiometer ready — turn the knob!");
}
void loop() {
int raw = analogRead(POT_PIN); // 0–1023
int brightness = map(raw, 0, 1023, 0, 255);
analogWrite(LED_PIN, brightness);
Serial.print("Raw: ");
Serial.print(raw);
Serial.print(" Brightness: ");
Serial.println(brightness);
delay(100);
}03Components
- 01Arduino Uno
- 02Potentiometer
- 03LED (yellow)
- 04Resistor 220Ω
04Wiring
| Component pin | Arduino pin |
|---|---|
| Potentiometer VCC | 5V |
| Potentiometer GND | GND |
| Potentiometer Signal | A0 |
| Resistor Pin 1 | Pin 9 |
| LED Anode (+) | Resistor Pin 2 |
| LED Cathode (−) | GND |
Ready when you are
Have a circuit in mind?
No hardware, no installs — a browser is enough.