CCNAP

TPL-25Templates/Slide Potentiometer

Slide Potentiometer

Read 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.

Open in Playgroundbeginner · analog input · PWM · serial · slide potentiometer
beginner

FIG. 1Slide Potentiometer · circuitTPL-25

02Sketch

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);
}

03Components

  • 01Arduino Uno
  • 02Slide Potentiometer
  • 03LED (yellow)
  • 04Resistor 220Ω

04Wiring

Component pinArduino pin
Slide Potentiometer VCC5V
Slide Potentiometer GNDGND
Slide Potentiometer SignalA0
Resistor Pin 1Pin 9
LED Anode (+)Resistor Pin 2
LED Cathode (−)GND

All templates

Ready when you are

Have a circuit in mind?

No hardware, no installs — a browser is enough.