Arduino Potentiometer LED Dimmer: Wiring, Code and Simulator

To build this Arduino Potentiometer LED Dimmer project you need an Arduino Uno and a 220 Ω resistor, a yellow LED and a potentiometer. analogRead on A0 sets analogWrite (PWM) on pin 9. Brightness follows the knob. Make the 6 connections in the wiring table, upload the Arduino C++ code, and drag the potentiometer knob. The LED dims and brightens, and the serial monitor shows the reading.

Open this circuit in the free Arduino Uno simulator

Parts list

QtyPartWhat it does
1Arduino Unothe microcontroller board
1220 Ω resistorLimits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down.
1yellow LEDLights when A (anode, the bent leg) is high and C (cathode) is low. Use a resistor.
1PotentiometerVCC to 5V, GND to GND, SIG to an analog pin. Drag the knob; analogRead gives 0–1023.

Wiring

#FromTo
1Arduino Uno pin 9220 Ω resistor leg 1
2220 Ω resistor leg 2yellow LED anode (A, long leg)
3Arduino Uno GNDyellow LED cathode (C, short leg)
4Arduino Uno GNDPotentiometer GND
5Arduino Uno A0Potentiometer SIG
6Arduino Uno 5VPotentiometer VCC

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add a 220 Ω resistor, a yellow LED and a potentiometer from the parts palette.
  3. Wire 1. Connect Arduino Uno pin 9 to 220 Ω resistor leg 1.
  4. Wire 2. Connect 220 Ω resistor leg 2 to yellow LED anode (A, long leg).
  5. Wire 3. Connect Arduino Uno GND to yellow LED cathode (C, short leg).
  6. Wire 4. Connect Arduino Uno GND to Potentiometer GND.
  7. Wire 5. Connect Arduino Uno A0 to Potentiometer SIG.
  8. Wire 6. Connect Arduino Uno 5V to Potentiometer VCC.
  9. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  10. Run it. Press Run. Drag the potentiometer knob. The LED dims and brightens, and the serial monitor shows the reading.

Arduino C++ code

// Dimmer: a potentiometer on A0 sets the brightness of an LED on pin 9 (PWM).
// Turn the knob and watch both the LED and the numbers in the serial monitor.
const int POT = A0;
const int LED = 9;

void setup() {
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int raw = analogRead(POT);            // 0..1023
  int level = map(raw, 0, 1023, 0, 255); // 0..255 for analogWrite
  analogWrite(LED, level);
  Serial.print("pot=");
  Serial.print(raw);
  Serial.print("  pwm=");
  Serial.println(level);
  delay(200);
}

What to try

Drag the potentiometer knob. The LED dims and brightens, and the serial monitor shows the reading.

Frequently asked questions

How do I wire the Potentiometer LED Dimmer project on an Arduino Uno?

Make 6 connections: Arduino Uno pin 9 to 220 Ω resistor leg 1; 220 Ω resistor leg 2 to yellow LED anode (A, long leg); Arduino Uno GND to yellow LED cathode (C, short leg); Arduino Uno GND to Potentiometer GND; Arduino Uno A0 to Potentiometer SIG; Arduino Uno 5V to Potentiometer VCC.

What parts do I need for this Arduino project?

An Arduino Uno and a 220 Ω resistor, a yellow LED and a potentiometer.

Can I simulate this Arduino project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.

What does the code do?

analogRead on A0 sets analogWrite (PWM) on pin 9. Brightness follows the knob.

More Arduino Uno projects