# ledcSetup or ledcAttachPin was not declared: ESP32 Arduino core 3 PWM change

> Fix ledcSetup and ledcAttachPin compile errors on ESP32 Arduino core 3.x, where PWM uses ledcAttach\(pin, freq, resolution\) instead.

Canonical: https://roboticsengineering.in/fix/esp32-ledcsetup-ledcattachpin-not-declared-core-3/ | Published: 2026-11-03 | Updated: 2026-11-03

**In ESP32 Arduino core 3.x the older ledcSetup and ledcAttachPin calls were replaced by ledcAttach.** Old tutorial code then fails to compile.

## What the message means

The new calls take the pin directly. ledcAttach(pin, frequency, resolution) sets up the channel, and ledcWrite(pin, duty) writes to the pin.

## Fix it in this order

1. Check your core version in Tools > Board > Boards Manager.
2. Replace ledcSetup(channel, freq, res) and ledcAttachPin(pin, channel) with ledcAttach(pin, freq, res).
3. Call ledcWrite with the pin number, not the channel number.
4. Or install core 2.x again if you must keep old code unchanged.
5. Read the release notes of the core version before upgrading a working project.

## Why it happens

Version 3 of the ESP32 Arduino core removed ledcSetup() and ledcAttachPin(). PWM is now set up with ledcAttach(pin, frequency, resolution) and written with ledcWrite(pin, duty), using the pin number instead of a channel.

```
const int PWM_PIN = 18;
void setup() { ledcAttach(PWM_PIN, 5000, 8); }   // pin, Hz, bits
void loop() { ledcWrite(PWM_PIN, 128); }
```

Example sketch: change the pin for your board and check your installed core version in the Boards Manager. The old calls only work on core 2.x.

## If you see this, do this

| You see | Do this |
| --- | --- |
| was not declared in this scope | Core 3 API change. |
| Code works on an older PC only | Different core versions. |

## Related

[was not declared in this scope](https://roboticsengineering.in/fix/arduino-was-not-declared-in-this-scope/), [PWM frequency](https://roboticsengineering.in/fix/arduino-pwm-motor-whine-frequency/).

Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.
