Dim an LED: Potentiometer, Arduino, ESP32, ESP8266 or a Web Slider?
Quick answer
- Choose Potentiometer, no code if you have no board.
- Choose Arduino analogWrite if you have an Uno.
- Choose ESP32 PWM if you have an ESP32.
- Choose ESP8266 PWM if you have a NodeMCU.
- Choose Web slider if you want to control it from a phone.
No board: potentiometer. Uno: analogWrite. The web slider is the most fun, once plain PWM works.
Side by side
Potentiometer, no code
- Who it's for
- Kids
- Level
- beginner
- Cost
- Low
- Main parts
- Breadboard, potentiometer, 2 LEDs, 100 Ω resistor
- Wiring
- Easy
- Code
- None
- It can
- Dim by hand
- It can't
- Dim by itself
Arduino analogWrite
- Who it's for
- Beginners
- Level
- beginner
- Cost
- Low
- Main parts
- Uno, LED, 330 Ω resistor
- Wiring
- Easy
- Code
- About 34 lines
- It can
- Fade smoothly, with a simulator in the lesson
- It can't
- Use every pin: only those marked ~
ESP32 PWM
- Who it's for
- Intermediate
- Level
- intermediate
- Cost
- Medium
- Main parts
- ESP32, 1 to 3 LEDs, resistors
- Wiring
- Easy
- Code
- About 23 to 33 lines; the second lesson's code needs ESP32 core 2.x or small changes
- It can
- Choose frequency and resolution, on almost any pin
- It can't
- Use the old commands on core 3.x
ESP8266 PWM
- Who it's for
- Intermediate
- Level
- intermediate
- Cost
- Low
- Main parts
- ESP8266, LED, 220 Ω resistor
- Wiring
- Easy
- Code
- About 20 lines
- It can
- Fade with the familiar analogWrite
- It can't
- Fine frequency control as on the ESP32
Web slider
- Who it's for
- Advanced
- Level
- advanced
- Cost
- Medium
- Main parts
- ESP32, LED, 220 Ω resistor, Wi-Fi
- Wiring
- Easy
- Code
- About 117 lines with HTML and async libraries
- It can
- Dim from a phone
- It can't
- Work without Wi-Fi
Written from the parts lists and code in these tutorials. Cost is a rough guide to the parts they list, compared with each other; line counts are of the main program.

