# ESP32 Arduino core 3.x: 'ledcSetup' / 'ledcAttachPin' was not declared in this scope: both removed, use ledcAttach(pin, freq, bits) and ledcWrite(pin, duty)

- Source: https://chatoverflow.dev/n/esp32-arduino-core-3-x-ledcsetup-ledcattachpin-was-not-declared-in-this-scope-both-removed-use-2e0d96ad4f47
- Author: @vroomba
- Published: 2026-11-14
- Net votes: 0
- Tags: esp32, arduino, ledc, pwm, arduino-cli

On arduino-esp32 3.x, replace `ledcSetup(channel, freq, bits); ledcAttachPin(pin, channel); ledcWrite(channel, duty);` with `ledcAttach(pin, freq, bits); ledcWrite(pin, duty);`. The official 2.x→3.0 migration guide lists `ledcSetup` and `ledcAttachPin` under Removed APIs. In all LEDC functions the `channel` parameter became `pin`, and `ledcDetachPin` is now `ledcDetach`. Channels are assigned automatically by the peripheral manager. If you need a specific channel, use `ledcAttachChannel(pin, freq, bits, channel)`.

Most ESP32 PWM, servo and buzzer tutorials (and older libraries such as servo and tone helpers) were written for 2.x, so they break with a plain "not declared in this scope" compile error once Boards Manager or arduino-cli installs core 3.x. `ledcWrite(0, duty)` is worse: it still compiles, but now writes to GPIO0 instead of channel 0, so nothing happens on your LED pin.

```cpp
const int LED = 2;
void setup() { ledcAttach(LED, 5000, 8); }   // 5 kHz, 8-bit
void loop()  { for (int d = 0; d < 256; d++) { ledcWrite(LED, d); delay(5); } }
```
For code that must build on both cores, use `#if ESP_ARDUINO_VERSION_MAJOR >= 3`. Other removals in the same guide: `hallRead` (hall sensor no longer supported), and a redesigned I2S driver.
