ESP32 S3 UNO - Potentiometer fade LED
This ESP32 S3 Uno potentiometer fade LED tutorial shows you how to dim an LED by turning a knob. You will wire a potentiometer and an LED to the ESP32 S3 Uno form board, read the knob position with Arduino code, and use it to set the LED brightness with PWM. When you turn the knob, the LED fades smoothly from off to full brightness.
In this tutorial, you will:
- Wire a potentiometer and an LED to the ESP32 S3 Uno
- Read the potentiometer value with analogRead()
- Convert the 0-4095 reading to a brightness level with map()
- Control LED brightness with analogWrite() (PWM)

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Buy Note: Use the LED Module for easier wiring. It includes an integrated resistor.
Overview of LED and Potentiometer
This project joins two simple parts: a potentiometer that gives an input, and an LED that shows an output. If you have not used them before, it helps to learn each one on its own first.
The tutorials below explain the pinout, how each part works, and how to program it:
ESP32 S3 Uno Pinout
The image below shows the pinout diagram of the ESP32 S3 Uno form board. Use it to find the Uno header pins (D3, A0, 3.3V…) and their GPIO numbers when you wire the circuit.

Wiring Diagram
The potentiometer goes to an analog pin, and the LED goes to a PWM pin through a 220 ohm resistor. Follow the diagram and the table below.

This image is created using Fritzing. Click to enlarge image
| Component Pin | ESP32 S3 Uno Pin |
|---|---|
| Potentiometer VCC | 3.3V |
| Potentiometer GND | GND |
| Potentiometer Output | A0 (GPIO2) |
| LED Anode (+) via 220 ohm resistor | D3 (GPIO17) |
| LED Cathode (-) | GND |
WARNING
Power the potentiometer from the 3.3V pin, not 5V. The ESP32 S3 Uno pins are not 5V tolerant, so a 5V signal on A0 can damage the board.
How To Program
The sketch does three small jobs in a loop. It reads the knob, scales the number, and sends it to the LED.
Read the potentiometer
Read the voltage on analog pin A0 (GPIO2). The ESP32 S3 Uno has a 12-bit ADC, so the value goes from 0 to 4095.
Convert to brightness
PWM brightness uses a range from 0 to 255, so scale the reading with map().
Set the LED brightness
Write the brightness to the LED on pin D3 (GPIO17) with a PWM signal.
ESP32 S3 Uno Code
The sketch below reads the potentiometer every 100 ms, turns the reading into a brightness level, and sets the LED with PWM. It also prints both values to the Serial Monitor, so you can see what happens when you turn the knob.
In setup(), the code calls analogSetAttenuation(ADC_11db). By default, the ESP32 S3 Uno ADC can only measure a small voltage. With 11 dB attenuation, the analog pin reads the full range from 0V up to about 3.3V. Without this line, the reading hits 4095 too early and the LED reaches full brightness before the knob reaches the end.
Detailed Instructions
Follow these steps one by one:
- New to the ESP32 S3 Uno? Follow ESP32 S3 Uno - Getting Started first.
- Wire it up as shown in the diagram.
- Connect the board to your computer with a USB Type-C cable.
- Open Arduino IDE, choose the ESP32S3 Dev Module board and the correct COM port.
- Copy the code above and paste it into Arduino IDE.
- Upload the code by clicking the Upload button.
- Open the Serial Monitor and set it to 9600 baud.
- Turn the potentiometer slowly from one end to the other.
- Watch the LED get brighter or dimmer, and check the values on the Serial Monitor:
- Tip: If the LED changes brightness only on one part of the knob turn, check that the analogSetAttenuation(ADC_11db) line is in setup() and that the potentiometer is powered from 3.3V.
Video Tutorial
Watch the video below to see this ESP32 S3 Uno project step by step.
FAQ
Why does the ESP32 S3 Uno read 0 to 4095 instead of 0 to 1023?
The ESP32 S3 Uno has a 12-bit ADC, so analogRead() returns a number from 0 to 4095. Boards like the UNO R4 use 0 to 1023 by default. If you copy code from those boards, change 1023 to 4095 in the map() call, or the LED will be at full brightness for most of the knob turn.
Why does the code call analogSetAttenuation(ADC_11db)?
It sets the ESP32 S3 Uno ADC input range to about 0V to 3.3V, so the full turn of the potentiometer maps to 0 to 4095. Without it, the range is smaller and the reading reaches 4095 too early. The UNO R4 does not need this line, because it is only for ESP32 boards. Keep the potentiometer output at 3.3V or less.
Can I power the potentiometer from 5V on the ESP32 S3 Uno?
No. With 5V on VCC, the potentiometer output can reach 5V, and the ESP32 S3 Uno pins are not 5V tolerant. This can damage the analog pin. Use the 3.3V pin instead.
Which ESP32 S3 Uno pins can dim an LED?
Almost every Uno header pin supports PWM, so analogWrite() works on D2 to D13. This tutorial uses D3, which is GPIO17. In code, always write the GPIO number, like 17, not D3.
Why does the LED flicker or jump at some knob positions?
The ESP32 S3 Uno ADC is a bit noisy, so the reading can move by a few steps even when the knob does not move. You can smooth it by averaging several readings, or by adding a small 0.1 µF capacitor between the potentiometer output and GND.
What if my project needs more pins than the Uno headers give?
The ESP32 S3 Uno has two extra rows of holes with more GPIOs. GPIO15 and GPIO16 support I/O, PWM and analog, so they are a good choice for an extra potentiometer. GPIO45 and GPIO35 to GPIO42 support I/O and PWM, so they work well for extra LEDs. GPIO47 and GPIO48 are output only with PWM. Solder pin headers to these holes and write the GPIO number in code. Be careful with two things. First, GPIO47 and GPIO48 may run at 1.8V instead of 3.3V on some modules (especially ones with "V" in the name, like R8V or R16V), so 3.3V devices can be damaged or act strangely. Second, GPIO0, GPIO3 (D6), GPIO45 and GPIO46 (D9) are boot strapping pins, and a wrong connection can stop the board from booting or uploading code. Use the other extra pins first.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| No COM port shows in Arduino IDE | USB driver missing or charge-only cable | Install the CP210x or CH340 driver and use a USB data cable |
| Upload fails or times out | Board is not in download mode | Hold the BOOT button, press and release RESET, then upload again |
| LED does not light at all | LED is reversed or the resistor is not connected | Put the long leg (anode) toward D3 (GPIO17) and check the 220 ohm resistor |
| LED is at full brightness for most of the knob turn | Code still maps 0 to 1023 or the attenuation line is missing | Use map(adc_value, 0, 4095, 0, 255) and keep analogSetAttenuation(ADC_11db) in setup() |
| Reading stays at 0 or 4095 | Potentiometer output is not on A0 or VCC/GND is loose | Connect the middle pin to A0 (GPIO2) and the outer pins to 3.3V and GND |
| LED brightness jumps or flickers | ADC noise or a loose breadboard wire | Press the wires in firmly and average several readings in code |
| Serial Monitor shows strange characters | Wrong baud rate | Set the Serial Monitor to 9600 baud |