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
| Qty | Part | What it does |
|---|---|---|
| 1 | Arduino Uno | the microcontroller board |
| 1 | 220 Ω resistor | Limits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down. |
| 1 | yellow LED | Lights when A (anode, the bent leg) is high and C (cathode) is low. Use a resistor. |
| 1 | Potentiometer | VCC to 5V, GND to GND, SIG to an analog pin. Drag the knob; analogRead gives 0–1023. |
Wiring
| # | From | To |
|---|---|---|
| 1 | Arduino Uno pin 9 | 220 Ω resistor leg 1 |
| 2 | 220 Ω resistor leg 2 | yellow LED anode (A, long leg) |
| 3 | Arduino Uno GND | yellow LED cathode (C, short leg) |
| 4 | Arduino Uno GND | Potentiometer GND |
| 5 | Arduino Uno A0 | Potentiometer SIG |
| 6 | Arduino Uno 5V | Potentiometer VCC |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
- Add the parts. Add a 220 Ω resistor, a yellow LED and a potentiometer from the parts palette.
- Wire 1. Connect Arduino Uno pin 9 to 220 Ω resistor leg 1.
- Wire 2. Connect 220 Ω resistor leg 2 to yellow LED anode (A, long leg).
- Wire 3. Connect Arduino Uno GND to yellow LED cathode (C, short leg).
- Wire 4. Connect Arduino Uno GND to Potentiometer GND.
- Wire 5. Connect Arduino Uno A0 to Potentiometer SIG.
- Wire 6. Connect Arduino Uno 5V to Potentiometer VCC.
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- 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
- Arduino LED Blink: Wiring, Code and Simulator
- Arduino LDR Light Sensor: Wiring, Code and Simulator
- Arduino NTC Thermistor Thermometer: Wiring, Code and Simulator
- Arduino PWM to Analog RC Filter: Wiring, Code and Simulator
- Arduino Capacitance Meter: Wiring, Code and Simulator
- Arduino DC Motor PWM Speed Control with MOSFET: Wiring, Code and Simulator