06
intermediate+300 XP
Potentiometer LED Dimmer
Use a potentiometer to smoothly control LED brightness through PWM.
🎯 Objective
Read a potentiometer with analogRead() and use analogWrite() to dim an LED.
📖 Background Theory
**Analog input:** analogRead(A0) returns 0–1023 based on voltage at the pin (0V = 0, 5V = 1023).
**PWM output:** analogWrite(pin, 0-255) generates a PWM signal.
- duty cycle = value/255
- 0 = fully OFF, 255 = fully ON, 128 = 50% brightness
**Mapping values:**
Arduino's map() function remaps a range:
map(value, 0, 1023, 0, 255) scales 0-1023 to 0-255
This is how real dimmer switches work — using PWM to reduce average power!
🔧 Components You'll Use
Arduino UnoPotentiometerLedResistorGround
📋 Steps (6)
- 1Place Arduino Uno, Potentiometer, LED, Resistor, Battery, and Ground
- 2Wire Potentiometer VCC to 5V, GND to Ground
- 3Wire Potentiometer wiper (SIG) to Arduino A0
- 4Wire Arduino D9 (PWM~) → 220Ω resistor → LED → Ground
- 5Paste the starter code and run simulation
- 6Turn the potentiometer knob to control brightness!