DEV Community

Cover image for Arduino-ESP32 4.0 is out - the two changes that can quietly break your sketch
ElectroDai
ElectroDai

Posted on Originally published at electrodai.com

Arduino-ESP32 4.0 is out - the two changes that can quietly break your sketch

Espressif released Arduino-ESP32 core 4.0.0 on 19 November 2026. It moves the Arduino core from ESP-IDF 5.5 to ESP-IDF v6.1.1 and adds the new RISC-V ESP32-S31. Officially supported chips are now ESP32, S2, S3, S31, C3, C5, C6, H2 and P4.

Most sketches will just recompile. Two changes are worth knowing before you click "Update" in Boards Manager.

1. ledcWrite() full-on is now 1 << resolution

In 4.0 the valid duty range for ledcWrite() / ledcFade*() is 0 to 2^res inclusive. At 8-bit, 100 % is 256, not 255. Values above max are clamped.

So ledcWrite(pin, 255) at 8-bit is now 255/256. You won't see that on an LED, but it's no longer a true "always high" if you are driving a MOSFET gate or a relay through PWM.

analogWrite() is unchanged: 0..255 at 8-bit, and 255 still means full on.

Quick grep for your codebase:

grep -rnE "ledc(Write|Fade).*(255|1023|4095|\(1 *<< *[a-zA-Z_]+\) *- *1)" .
Enter fullscreen mode Exit fullscreen mode

A fade sketch that is correct on 4.0 and also prints the core and IDF version:

// LEDC fade that is correct on Arduino-ESP32 4.0
// LED + 220 ohm resistor on GPIO 2 (onboard LED on many dev boards)
const int LED_PIN = 2;
const int FREQ    = 5000;  // 5 kHz PWM
const int RES     = 8;     // 8-bit resolution
const int FULL_ON = 1 << RES; // 256 = 100% on in core 4.0

void setup() {
  Serial.begin(115200);
  ledcAttach(LED_PIN, FREQ, RES);   // 3.x/4.x API (no channels needed)

  // Print which core you are running
  Serial.printf("Arduino-ESP32 core %d.%d.%d, IDF %s\n",
                ESP_ARDUINO_VERSION_MAJOR, ESP_ARDUINO_VERSION_MINOR,
                ESP_ARDUINO_VERSION_PATCH, ESP.getSdkVersion());
}

void loop() {
  for (int d = 0; d <= FULL_ON; d += 4) {  // fade up to truly full
    ledcWrite(LED_PIN, d);
    delay(10);
  }
  for (int d = FULL_ON; d >= 0; d -= 4) {  // fade back down
    ledcWrite(LED_PIN, d);
    delay(10);
  }
}
Enter fullscreen mode Exit fullscreen mode

(API calls from the official migration guide; I haven't compiled this on 4.0.0 hardware yet.)

2. WebServer got hardened

The built-in WebServer now has request limits and stricter parsing:

  • URI > 2048 bytes → 414, header line > 4096 bytes → 431, slow clients → 408
  • serveStatic() rejects . / .. segments (and serveStatic("/", fs, "/") finally works)
  • arg() / hasArg() no longer leak values from a previous keep-alive request
  • authenticate() accepts only proper Basic/Digest headers; Digest nonces are signed with a TTL
  • SSE moved to the server: server.client().setSSE(true) → server.enableSSE() (old call deprecated, removal planned for 5.0)

Every limit can be raised with a -D build flag, but the docs warn this reopens memory-exhaustion risk.

Should you update?

  • New project on a common board: yes, just fix any ledcWrite(..., 255).
  • Something that has to work next week: stay on 3.3.13 (released 17 Nov, still on IDF 5.5).
  • ESP32-S31 board: you need 4.0. Expect some third-party libraries to lag on the new RISC-V core.

Rolling back is painless: Tools → Board → Boards Manager → esp32 → pick 3.3.13 → Install. Your sketches aren't touched.


The full beginner version (troubleshooting table, Nepal-specific tips, FAQ) is on ElectroDai: https://electrodai.com/tutorial/arduino-esp32-core-4-0-what-changed

Sources: Espressif arduino-esp32 4.0.0 release notes and migration guides on docs.espressif.com.

Top comments (0)