Skip navigation

LED & Potentiometer
This example shows you how to obtain a value from a potentiometer using the Arduino’s analog pins. We then take this value and use it to adjust the brightness of an LED connected to digital pin 10. Note the pin you use for the LED must be labeled PWM.

Materials you’ll need:

  • Arduino Duemilanove
  • 10k Potentiometer
  • 1K ohm resistor (brown, black, red)
  • LED

    Arduino Sketch

     * Potentiometer LED Dimmer
     * ------------------------
     * Dims a LED connected to digital pin 10 based on the value obtained 
     * from a 10k potentiometer connected to analog pin 0.
     * Created January 2010
     * Matt Wiechec
    int potPin = 2;    // select the input pin for the potentiometer
    int ledPin = 10;   // select the pin for the LED
    int potVal = 0;    // variable to store the value coming from the sensor
    void setup() {
      pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT
      Serial.begin(9600);       // for debugging via the Serial Monitor
    void loop() {
      potVal = analogRead(potPin);            // read the value from the sensor
      potVal = map(potVal, 0, 1023, 0, 255);  // scale it to use it with the LED
      analogWrite(ledPin, potVal);            // set brightness
      Serial.print("Pot Val: ");


    LED/Potentiometer Schematic


    LED/Potentiometer Illustration





    1. Although I couldn’t get the code to work, this illustration was a life saver. How did you make that illustration? It’s brilliant.

      • The illustrations were made in Adobe Illustrator. Glad you are finding the resources helpful.

    Leave a Reply

    Fill in your details below or click an icon to log in: Logo

    You are commenting using your account. Log Out /  Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out /  Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out /  Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out /  Change )


    Connecting to %s

    %d bloggers like this: