The Arduino Servo library doesn't compile for the ESP32

  • ESP32
  • Servo

You may see

error: 'SOC_LEDC_TIMER_BIT_WIDE_NUM' was not declared in this scope; did you mean 'SOC_LEDC_TIMER_BIT_WIDTH'?
This library only supports boards with an AVR, SAM, SAMD, NRF52, STM32F4

Why it happens

  • Older versions of Servo.h don't support the ESP32 at all.
  • Newer ones do, but may not fit your version of the ESP32 board package.

How to fix it

  1. Install ESP32Servo from the Library Manager.
  2. Change the first line to #include <ESP32Servo.h>. Most commands stay the same.

It worked if: Verify passes and the servo sweeps with the ESP32Servo example.

Seen in a real run (some lines are close variants of it). The first line came from Servo 1.3.0 with ESP32 core 3.1.3. The second is from older versions of the library. Sources: Servo library source, ESP32Servo.

Didn't help? Search another error or ask us.