Tutorial 3 - Dimming an LED with a Potentiometer

Learn how to control the brightness of an LED using a potentiometer. This teaches you how to read analog input and write analog output using Arduino's PWM functionality.

Circuit Diagram

💡Tip: If your LED doesn’t dim smoothly, double-check that the LED is on a PWM-capable pin ( ~3, ~5, ~6, ~9, ~10, or ~11). Not all digital pins support brightness control.

What You'll Need

  1. Arduino Uno x 1
  2. Breadboard x 1
  3. LED x 1
  4. 220Ω Resistor x 1
  5. Potentiometer (10kΩ recommended) x 1
  6. Jumper wires x 7
  7. USB Cable x 1
  8. Arduino IDE installed

Instructions

  1. Place the potentiometer on the breadboard.
  2. Connect one outer pin of the potentiometer to 5V, the other to GND.
  3. Connect the middle pin (wiper) to A0 on the Arduino.
  4. Connect the longer leg (anode) of the LED to digital PWM pin 9.
  5. Connect the shorter leg (cathode) through a 220Ω resistor to GND.
  6. Connect jumper wires (GND & VCC) from the breadboard to GND & VCC on the Arduino.
  7. Plug your Arduino into your computer using a USB cable.
  8. Open the Arduino IDE, and paste in the code below.
  9. Under Tools, select your board type and COM port.
  10. Click Upload and watch the LED brightness change as you turn the knob!

The Code


void setup() {
  pinMode(9, OUTPUT);  // LED pin
}

void loop() {
  int sensorValue = analogRead(A0);       // Read potentiometer value (0-1023)
  int ledBrightness = map(sensorValue, 0, 1023, 0, 255); // Map to 0-255
  analogWrite(9, ledBrightness);          // Set LED brightness
}
        

Schematic Diagram

Dimming LED Schematic

Schematic diagrams show how current flows and how components connect logically — not just physically.

B2. Control an LED I1. Servo Sweep
© 2025 Ohmly