03 / Templates · beginner
SLIDE POTENTIOMETER
Open in PlaygroundRead an analog value from a linear slide potentiometer and use it to fade an LED's brightness via PWM, while printing the raw and mapped values to the Serial Monitor.
beginneranalog inputPWMserialslide potentiometer
sketch.inoArduino C++
25 lines
// Slide Potentiometer — Analog Read → LED Brightness
// Drag the slider 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("Slide potentiometer ready — drag the slider!");
}
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);
}- Arduino Uno01
- Slide Potentiometer02
- LED (yellow)03
- Resistor 220Ω04
| Component Pin | Arduino Pin |
|---|---|
| Slide Potentiometer VCC | 5V |
| Slide Potentiometer GND | GND |
| Slide Potentiometer Signal | A0 |
| Resistor Pin 1 | Pin 9 |
| LED Anode (+) | Resistor Pin 2 |
| LED Cathode (−) | GND |