CNAP
03 / Templates · beginner

POTENTIOMETER

Open in Playground

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.

beginneranalog inputPWMserialpotentiometer
Circuit
Code
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);
}
Components
  • Arduino Uno
    01
  • Potentiometer
    02
  • LED (yellow)
    03
  • Resistor 220Ω
    04
Wiring
Component PinArduino Pin
Potentiometer VCC5V
Potentiometer GNDGND
Potentiometer SignalA0
Resistor Pin 1Pin 9
LED Anode (+)Resistor Pin 2
LED Cathode (−)GND