esp32.diy

ESP32 LED Pin Number: Which GPIO Drives an LED?

Nov 22, 2026 · 8 min read · Beginner

ESP32 LED Pin Number: Which GPIO Drives an LED?
TL;DR The ESP32 has no single LED pin number: the LEDC peripheral generates PWM on whichever GPIO you attach, and the built-in board LED varies by model and manufacturer. One source board defines its built-in LED as GPIO2, but another working ESP32 build uses GPIO2 as a display control line, so always check your own board's pinout.
LED pin on ESP32No fixed pin — LEDC drives the GPIO you attach
LEDC channels (original ESP32)16 channels, 2 groups, 4 timers per group
LEDC channels (S2/S3/P4)8 channels, 1 group, 4 timers
LEDC channels (C3/C5/C6/H2)6 channels, 1 group, 4 timers
PWM resolution range1–14 bits (1–20 bits on original ESP32)
Lowest frequency, 40 MHz XTAL at 8-bitAbout 153 Hz

What is the ESP32 LED pin number?

There is no single LED pin number on the ESP32. The LED Control (LEDC) peripheral is designed primarily to control LED intensity and to generate PWM for other purposes, and it outputs on GPIOs that you choose. You attach a pin, and the driver assigns it a channel. The pin number is therefore whatever pin your LED is wired to and attached in code.

What most people actually mean by the LED pin is the LED already mounted on a development board. Wikipedia notes that ESP32 dev kits and boards expose a variety of GPIO pins and connectors, and that their configuration varies by model and manufacturer. The sources do not give one family-wide built-in LED GPIO.

A concrete data point: an ESP32 sketch in one source declares

const int LED_BUILTIN = 2;

so on that particular board the built-in LED was GPIO2. Treat that as one board's assignment, not a rule. Another source example uses GPIO2 as the display DC line in a working ESP32 plus ST7789 build, so the same pin number can do a completely different job on a different project.

The practical workflow is: find your board's pinout from the vendor or its GitHub repository, pick a free GPIO, and attach it to LEDC.

An ESP32 board successfully driving an ST7789 SPI TFT display in a test build.\2

An ESP32 board successfully driving an ST7789 SPI TFT display in a test build.

How many LED (PWM) channels does each ESP32 have?

The number of LEDC channels depends on the SoC, not on the board. From the Arduino-ESP32 LEDC documentation:

ESP32 SoC Channels Groups Timers per group
ESP32 16 2 4
ESP32-S2 8 1 4
ESP32-S3 8 1 4
ESP32-C3 6 1 4
ESP32-C5 6 1 4
ESP32-C6 6 1 4
ESP32-H2 6 1 4
ESP32-P4 8 1 4

Two things matter here. A channel drives one or more GPIOs and owns the duty cycle and fade behaviour. A timer owns the PWM frequency and resolution. They are separate resources, and this split is the source of most surprises, covered in the gotchas below.

Second, the channel count is not a pin list. The sources state how many channels each SoC can generate; they do not enumerate which GPIO numbers are valid LEDC outputs on a given board. On the original ESP32 the channel ranges are 0–7 for group 0 and 8–15 for group 1. Other SoCs have a single group, so all of their channels share one pool of 4 timers.

A second view of the same ESP32-driven display running its test pattern.\2

A second view of the same ESP32-driven display running its test pattern.

How do you assign an LED to a pin in code?

The Arduino-ESP32 LEDC API attaches a pin and then writes duty to it. The core functions are:

bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution);
bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, int8_t channel);
bool ledcWrite(uint8_t pin, uint32_t duty);
bool ledcSetClockSource(ledc_clk_cfg_t source);

Key behaviours from the documentation:

If you do not need dimming, a plain digital output also works. The multitasking example source uses ordinary GPIO output for LEDs:

const int output26 = 26;
const int output27 = 27;
pinMode(output26, OUTPUT);
digitalWrite(output26, LOW);

That is on and off only, with no dimming and no fade.

What frequency and resolution limits should you expect?

Frequency and duty resolution are coupled. The documentation gives the relationship as:

freq ≈ ledc_clock / (clock_divider × 2^resolution)

Because the clock divider has a limited range, every clock source and resolution combination has a minimum and a maximum achievable frequency. Asking for a frequency that is too low for the chosen resolution fails the same way as asking for one that is too high.

Setting or limit Value or effect
Resolution range 1–14 bits (1–20 bits on original ESP32)
XTAL clock (Arduino default where supported) Typically 40 MHz
Minimum at 40 MHz, 8-bit resolution About 153 Hz
Increasing resolution (e.g. 9–14 bits) Allows lower frequencies
Reducing resolution Raises the minimum frequency
Changing the clock source Must be done before attaching channels

The original ESP32 does not support XTAL as an LEDC source and defaults to LEDC_AUTO_CLK instead. If you need the exact ceiling and floor for your board, the documentation points to an LEDC frequency range example that prints the achievable minimum and maximum for the current setup. Real limits depend on the SoC, the clock source and the board configuration. Also check getXtalFrequencyMhz() rather than assuming 40 MHz.

Which ESP32 pins should you avoid for LEDs?

The sources do not list a reserved-pin table for LED duty, but they do show where conflicts come from.

Pins claimed by other peripherals. UART0 is typically used for programming and debug output, and the original ESP32 has three UARTs available. If both RX and TX are detached from UART, the driver is stopped, and this can happen when another peripheral starts using those pins. In one-wire UART mode, an external deinit of the shared pin, such as a pinMode() call or another peripheral claiming the GPIO, terminates the UART driver. So an LED attached to a debug pin is not just a wiring question; it can kill the serial link you rely on for troubleshooting.

Pins already used by a bus. A working ESP32 build in the sources drives an ST7789 display with this pin set:

#define TFT_DC 2
#define TFT_CS 15
#define TFT_MOSI 23
#define TFT_CLK 18
#define TFT_RST 4
#define TFT_MISO 19

That is six GPIOs consumed by one display. Add Wi-Fi or storage and the free list shrinks fast, so plan the LED pin early.

GPIO2 overlap. GPIO2 appears as the built-in LED in one source example and as the display DC line in another. Both are plausible on different builds, which is why a generic chart is not enough.

Silkscreen errors. In a separate board debug, the root cause of a display that only produced a white screen was a swapped silkscreen label: GPIO16 was marked as GP18 and GPIO18 as GP16, and both pins were in active use by the SPI interface. The fix was to follow the vendor repository pinout instead of the board markings. Whatever pin number you think you are using, confirm it against the vendor documentation.

Fixed-pin LP UARTs. On ESP32-C5, ESP32-C6 and ESP32-C61, low-power UARTs use fixed GPIOs for RX, TX, CTS and RTS, and setPins() cannot change them. On ESP32-P4 the LP UART follows the normal pin rules instead.

Gotchas: channels, timers and shared frequencies

These are the traps that make two LED pins change brightness together or refuse to dim independently.

To keep frequency control independent, the documentation gives two options: attach the pins with a different frequency and resolution from the start, or, on the original ESP32, put them in different channel groups, for example channel 0 and channel 8. Each group has its own pool of 4 timers on all current SoCs, so you can have up to 4 independent frequencies per group. On the single-group SoCs, all channels draw from one pool of 4 timers.

Safe usage and debugging notes

Do not block the scheduler. A source example shows an ESP32 rebooting with a task watchdog abort after two pinned tasks kept running without letting the idle task reset the watchdog. The log named IDLE0 on CPU 0 as the starved task while Task1 and Task2 were running. LED animations are a common place to write blocking loops, so keep loops non-blocking, and avoid high-priority spun tasks if you also need Wi-Fi, a web server or serial output working alongside the LEDs.

Confirm the pinout before soldering. Boards vary by model and manufacturer, silkscreen labels can be wrong, and a single wrong pin can leave you staring at a blank or white display. Pull the pin map from the vendor or their repository.

Check what else owns the pin. Before attaching an LED, confirm nothing else is using that GPIO for UART, SPI, a display or another peripheral. Peripheral managers can reclaim pins, and the UART driver stops if its pins are taken away.

Measure, do not guess, the PWM range. Frequency and resolution limits are interdependent and depend on the SoC, clock source and board. Print the achievable range for your configuration instead of copying numbers between chips.

Known gap. The sources used here do not give per-pin current limits, absolute maximum ratings or logic voltage levels for ESP32 LED wiring, so none are quoted. Check the Espressif datasheet for your specific module before driving anything beyond a small indicator LED.

Frequently asked questions

Is GPIO2 the built-in LED pin on every ESP32?

No. One source sketch defines LED_BUILTIN as 2 for that board, but board layouts vary by model and manufacturer, and the sources do not list a universal built-in LED GPIO. Check your own board pinout.

Can any ESP32 GPIO be used to drive an LED with PWM?

LEDC drives GPIOs that you attach, and it is the peripheral designed for LED intensity control. The sources do not enumerate which GPIO numbers are valid LEDC outputs, so avoid pins already claimed by UART, SPI or a display.

Why do two of my LED pins change brightness together?

They probably share a timer. Pins attached with the same frequency and resolution in the same group reuse one timer, and changing the frequency on one pin changes all channels on that timer.

Why does a low PWM frequency fail at 8-bit resolution?

Frequency and resolution are coupled. At a 40 MHz XTAL clock with 8-bit resolution the minimum is about 153 Hz. Increase the resolution, or change the clock source with ledcSetClockSource() before attaching channels.

How many independent LED frequencies can I get?

Up to 4 independent frequencies per group, since each group has its own pool of 4 timers. The original ESP32 has 2 groups; the S2, S3, C3, C5, C6, H2 and P4 have a single group.

Bottom line

There is no ESP32 LED pin number to memorise. You attach an LED to a GPIO you control through the LEDC peripheral, and the only pin that exists out of the box is whatever your specific board wired to its built-in LED. Pick a pin that no other peripheral owns, attach it with a frequency and resolution you actually need, and confirm the layout against the vendor documentation before you trust the silkscreen.

Sources

en.wikipedia.orgESP32 (Wikipedia)github.comLED Control (LEDC) (arduino-esp32 docs)github.comSerial (UART) (arduino-esp32 docs)stackoverflow.comSB Components Micro RP2040 and ST7789 2.4 TFT LCD SPI display not working together using any librarystackoverflow.comESP32 - Multi Tasking with while in a task

This guide summarises the public sources listed above in our own words. Check the original documentation before relying on exact figures.