Arduino Playground

Potentiometer Playground

The potentiometer is connected to Analog pin A0, and the LED to pin 11. Rotating the potentiometer will change the blink rate of the LED:

Can you make the potentiometer control the brightness of the LED instead?


Have questions? Feedback? Please share with us below:

sketch.ino

/* Potentiometer controlled LED Blink */

void setup() {
  pinMode(A0, INPUT);
  pinMode(11, OUTPUT);
}

void loop() {
  digitalWrite(11, HIGH);
  delayPotentiometer();
  digitalWrite(11, LOW);
  delayPotentiometer();
}

int delayValue() {
  int value = analogRead(A0);
  return map(value, 0, 1023, 100, 1000);
}

void delayPotentiometer() {
  for (int i = 0; i < delayValue(); i++) {
    delay(1);
  }
}