In this tutorial, you’ll learn how to check and change the ESP32 clock speed (CPU frequency) in the Arduino IDE. The ESP32 runs at 240MHz by default, and you can change its CPU frequency at any time in your code with setCpuFrequencyMhz(), or before upload from the Arduino IDE Tools menu. We’ll also see which CPU frequencies are valid on each ESP32 chip, and what happens to WiFi, Bluetooth, Serial, PWM, and timers when you go below 80MHz.
Then, we’ll test it on real hardware: how much faster the code runs at each CPU frequency, from 240MHz down to 10MHz, on my oscilloscope, what breaks below 80MHz and how to fix it, and how much current each CPU frequency costs you. This is very useful for battery-powered projects and for squeezing the most performance out of the ESP32. Without further ado, let’s get right into it!
ESP32 Set CPU Frequency Example (setCpuFrequencyMhz)
To change the ESP32 CPU frequency in Arduino, call setCpuFrequencyMhz(80) with the new frequency in MHz. It returns true when the frequency is applied, and you can read it back with getCpuFrequencyMhz(). No library or #include is needed. On the ESP32 (40MHz crystal), the valid values are 240, 160, 80 (WiFi and Bluetooth work) and 40, 20, 10 (no WiFi, no Bluetooth).
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
/* * LAB Name: ESP32 Set CPU Frequency (Quick Example) * Author: Khaled Magdy * For More Info Visit: www.DeepBlueMbedded.com */ void setup() { Serial.begin(115200); // Valid values on ESP32 (40MHz XTAL): 240, 160, 80, 40, 20, 10 if (setCpuFrequencyMhz(80)) { Serial.print("CPU Frequency Is Now: "); Serial.print(getCpuFrequencyMhz()); Serial.println(" MHz"); } else { Serial.println("Invalid CPU Frequency!"); } } void loop() { } |
The rest of this tutorial explains how the ESP32 CPU clock works, all the related functions, and what each frequency gives you in speed (measured on my bench) and in power consumption.
Note: All examples in this tutorial are tested with: ESP32 DevKit V1 (ESP32-WROOM-32), Arduino-ESP32 core 3.3.12, Arduino IDE 2.x.
ESP32 Clock Speed: Default & Valid CPU Frequencies
The ESP32 CPU clock speed is 240MHz by default in the Arduino core, and it can be set to 240, 160, 80, 40, 20, or 10MHz (with the usual 40MHz crystal). The first 3 come from the internal PLL, and the lower 3 come from the crystal divided by 1, 2, or 4. This difference matters a lot, as the table below shows.
| CPU Frequency | Clock Source | APB Bus Clock | WiFi / Bluetooth | Chip Current (Datasheet) | Workload Time (Measured) |
|---|---|---|---|---|---|
| 240MHz | PLL | 80MHz | Yes | 30 – 68mA | 2092µs |
| 160MHz | PLL | 80MHz | Yes | 27 – 44mA | 3143µs |
| 80MHz | PLL | 80MHz | Yes | 20 – 31mA | 6308µs |
| 40MHz | XTAL / 1 | 40MHz | No | Not listed | 12796µs |
| 20MHz | XTAL / 2 | 20MHz | No | Not listed | 26131µs |
| 10MHz | XTAL / 4 | 10MHz | No | Not listed | 54958µs |
I measured the execution time column on my ESP32 DevKit V1 in LAB 3 below, and the current column comes from the ESP32 datasheet, which only lists the 3 PLL frequencies. If your board has a 26MHz crystal (rare, and you can check it with getXtalFrequencyMhz()), the lower options become 26 and 13MHz instead of 40, 20, and 10MHz.
ESP32-S3, C3, C6 & Other ESP32 Chips Clock Speed
Every ESP32 chip has its own maximum CPU frequency and its own list of valid values. Here they are, from the board definitions of the Arduino-ESP32 core 3.3.12:
| Chip | Default CPU Clock | Valid CPU Frequencies (Arduino) | CPU Core |
|---|---|---|---|
| ESP32 | 240MHz | 240, 160, 80, 40, 20, 10MHz | 2x Xtensa LX6 |
| ESP32-S2 | 240MHz | 240, 160, 80, 40, 20, 10MHz | 1x Xtensa LX7 |
| ESP32-S3 | 240MHz | 240, 160, 80, 40, 20, 10MHz | 2x Xtensa LX7 |
| ESP32-C3 | 160MHz | 160, 80, 40, 20, 10MHz | 1x RISC-V |
| ESP32-C6 | 160MHz | 160, 120, 80, 40, 20, 10MHz | 1x RISC-V (+ LP core) |
| ESP32-C5 | 240MHz | 240, 120, 80, 40, 20, 10MHz | 1x RISC-V (+ LP core) |
| ESP32-C2 | 120MHz | Fixed in the Arduino core | 1x RISC-V |
| ESP32-H2 | 96MHz | Fixed in the Arduino core | 1x RISC-V |
| ESP32-P4 | 360MHz | 400MHz on chip revision 3 and newer | 2x RISC-V |
WiFi and Bluetooth need a CPU frequency of 80MHz or more on all of them (the Arduino IDE marks these options with “(WiFi)” or “(WiFi/BT)”). To see the exact list for the chip on your desk, call getSupportedCpuFrequencyMhz() as in LAB 1.
How The ESP32 CPU Clock Works
The ESP32 has two clock sources that can drive the CPU: the external 40MHz crystal (XTAL_CLK) and the internal PLL (Phase-Locked Loop), which multiplies the crystal frequency up to 320MHz or 480MHz. The CPU clock (CPU_CLK) is taken from one of them through a divider. When you call setCpuFrequencyMhz(), the core picks the source and the divider for you: the PLL for 240, 160, and 80MHz, and the crystal for 40, 20, and 10MHz.

The peripherals don’t run from the CPU clock directly. They’re clocked by the APB bus clock (APB_CLK), which is derived from the CPU clock, and some of them use REF_TICK, a 1MHz clock divided down from APB. Here is the rule you need to remember:
- When the CPU runs from the PLL (240, 160, or 80MHz), the APB clock is always 80MHz. The peripherals don’t notice any change.
- When the CPU runs from the crystal (40, 20, or 10MHz), the APB clock is equal to the CPU clock. Every peripheral that runs from APB slows down with the CPU, unless it’s re-configured after the change. We’ll see that on the scope in LAB 4.
The core keeps REF_TICK at 1MHz at every CPU frequency, and the Arduino core uses it for the Serial port at baud rates up to 250000. That’s why Serial at 115200 keeps working at 10MHz in core 3.x (LAB 2), while it printed garbage at low CPU frequencies in the old core 1.0.x days, as some readers reported in the comments below. You can find all the clock details in Espressif’s Clock Tree documentation.
Why Change The ESP32 CPU Frequency?
There are 2 reasons to change the ESP32 CPU frequency. Number one is power consumption. All digital logic circuits consume more power the higher the clock rate is. Every clock edge switches millions of CMOS transistors, and each switching event charges the gates’ capacitance and causes a short shoot-through current spike. The more clock edges you have per second, the more current spikes there are. In other words, the dynamic power of the CPU rises roughly linearly with its clock frequency.

The second reason is performance: running at the full 240MHz to meet a timing requirement, process data faster, or finish a task sooner and go back to sleep. As you’ll see in the power consumption section below, the static part of the power (leakage, flash, the board’s regulator and USB chip) doesn’t scale with the clock, so lowering the frequency saves less than you might expect.
ESP32 CPU Frequency Functions (Arduino)
These are the functions of the Arduino-ESP32 core for the CPU clock. They’re part of the core ( esp32-hal-cpu.h), so you can call them in any sketch without an #include.
| Function | What It Does | Returns |
|---|---|---|
setCpuFrequencyMhz(mhz) | Changes the CPU frequency at runtime. Fails (and changes nothing) for a value the chip can’t generate | bool: true on success |
getCpuFrequencyMhz() | Reads the current CPU frequency | MHz |
getXtalFrequencyMhz() | Reads the crystal frequency (40MHz on most boards) | MHz |
getApbFrequency() | Reads the APB bus clock frequency | Hz |
getSupportedCpuFrequencyMhz() | Lists the valid CPU frequencies of the running chip, as text (core 3.3.12 and newer) | const char* |
addApbChangeCallback(arg, cb) | Registers a function that the core calls before and after every APB clock change | bool |
Note: If setCpuFrequencyMhz() gets a value that isn’t valid (like 100 or 30), it returns false and the CPU frequency doesn’t change. The error message with the list of valid values only shows up in the Serial Monitor if you set Tools > Core Debug Level to Error or higher. Always check the return value.
Set The ESP32 CPU Frequency From The Arduino IDE Menu
You can also set the CPU frequency before uploading, with no code at all: select the ESP32 Dev Module board, then pick the frequency from Tools > CPU Frequency. The core applies it right before setup() runs, so the whole sketch runs at that frequency. You can still change it later in your code with setCpuFrequencyMhz().
Note: The DOIT ESP32 DEVKIT V1 board option has no CPU Frequency menu, and it’s fixed at 240MHz. If you don’t see the menu, select ESP32 Dev Module instead. It works with the DevKit V1 board just fine.
In PlatformIO, the same setting is board_build.f_cpu = 80000000L in your platformio.ini file.
Components For This Tutorial’s LABs
| QTY. | Component Name | Amazon.com | AliExpress |
| 1 | ESP32 DevKit V1 (DOIT) Board | Amazon | AliExpress |
| 1 | Breadboard & Jumper Wires | Amazon | AliExpress |
| 1 | Micro USB Cable | Amazon | AliExpress |
| 1 | Oscilloscope (optional, for LABs 3 & 4) | Amazon | – |
The oscilloscope is optional. It’s only used to see the GPIO toggle speed and the PWM signals in LAB 3 and LAB 4.
LAB 1: Read ESP32 CPU, XTAL & APB Clock Frequencies
In this first example, we’ll read the ESP32’s clock frequencies and print them to the Serial Monitor: the chip model, the CPU frequency, the crystal frequency, the APB bus frequency, and the list of CPU frequencies that this exact chip accepts.
ESP32 Read CPU Frequency Code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
/* * LAB Name: ESP32 Read CPU, XTAL & APB Clock Frequencies * Author: Khaled Magdy * For More Info Visit: www.DeepBlueMbedded.com */ void setup() { Serial.begin(115200); delay(1000); Serial.print("Chip Model = "); Serial.print(ESP.getChipModel()); Serial.print(" (Rev "); Serial.print(ESP.getChipRevision()); Serial.print("), Cores = "); Serial.println(ESP.getChipCores()); Serial.print("CPU Freq = "); Serial.print(getCpuFrequencyMhz()); Serial.println(" MHz"); Serial.print("XTAL Freq = "); Serial.print(getXtalFrequencyMhz()); Serial.println(" MHz"); Serial.print("APB Freq = "); Serial.print(getApbFrequency()); Serial.println(" Hz"); #if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 3, 12) // Lists every CPU frequency this chip accepts (Arduino-ESP32 core 3.3.12 or newer) Serial.print("Supported CPU Freqs = "); Serial.println(getSupportedCpuFrequencyMhz()); #endif } void loop() { } |
Code Explanation
The ESP.getChipModel(), ESP.getChipRevision(), and ESP.getChipCores() functions tell us which ESP32 chip we’re running on. Then, getCpuFrequencyMhz() and getXtalFrequencyMhz() return their values in MHz, while getApbFrequency() returns the APB bus clock in Hz, so don’t forget that when you print or compare it.
The last part is wrapped in an #if check of the core version, because getSupportedCpuFrequencyMhz() (with no arguments) was added in core 3.3.12. With an older core, the sketch still compiles and simply skips that line.
ESP32 Read CPU Frequency Result
This is the real output on my ESP32 DevKit V1 (ESP32-D0WDQ6 chip). It runs at 240MHz from a 40MHz crystal, the APB bus clock is 80MHz, and the chip reports exactly the 6 valid CPU frequencies from the table above.

LAB 2: Change ESP32 CPU Frequency at Runtime
In this example, we’ll change the ESP32 CPU frequency on the fly, stepping through every valid frequency from 240MHz down to 10MHz, plus an invalid value (100MHz) to see how setCpuFrequencyMhz() fails. After each change, we’ll print the CPU and APB frequencies over the Serial port at 115200 baud, which also shows whether Serial keeps working at the low frequencies.
ESP32 setCpuFrequencyMhz() Example Code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
/* * LAB Name: ESP32 Change CPU Frequency (Runtime) * Author: Khaled Magdy * For More Info Visit: www.DeepBlueMbedded.com */ // Try 240, 160, 80, 40, 20, 10 (and an invalid one like 100) const uint32_t FREQS_MHZ[] = {240, 160, 80, 40, 20, 10, 100}; const uint8_t N_FREQS = sizeof(FREQS_MHZ) / sizeof(FREQS_MHZ[0]); void printClocks() { Serial.print("CPU = "); Serial.print(getCpuFrequencyMhz()); Serial.print(" MHz, APB = "); Serial.print(getApbFrequency() / 1000000); Serial.println(" MHz"); } void setup() { Serial.begin(115200); delay(1000); Serial.print("Default -> "); printClocks(); } void loop() { for (uint8_t i = 0; i < N_FREQS; i++) { Serial.print("setCpuFrequencyMhz("); Serial.print(FREQS_MHZ[i]); Serial.print(") "); if (setCpuFrequencyMhz(FREQS_MHZ[i])) { Serial.print("OK -> "); } else { Serial.print("FAIL -> "); } printClocks(); delay(2000); } } |
Code Explanation
The FREQS_MHZ[] array holds the frequencies to try. In the loop(), we call setCpuFrequencyMhz() with each one and check its return value, then printClocks() reads back the real CPU and APB frequencies. The delay(2000) keeps working correctly at every frequency, because the core updates the system timer when the clock changes.
ESP32 Change CPU Frequency Result
Here is the output on my ESP32 DevKit V1. Every valid frequency is applied, and the APB clock stays at 80MHz down to 80MHz, then follows the CPU clock at 40, 20, and 10MHz. The invalid 100MHz request returns FAIL, and the CPU simply stays at the previous frequency (10MHz).

Notice that the Serial output at 115200 baud stays readable even at 10MHz. I ran 3 full cycles with zero garbage characters. On core 3.x, the Serial port runs from the fixed 1MHz REF_TICK clock (for baud rates up to 250000), so the CPU frequency doesn’t affect it.
LAB 3: ESP32 CPU Frequency Speed Test
Now, let’s see how much the CPU frequency affects the speed of your code. In this example, we’ll run the same CPU-bound workload (100,000 iterations of integer math) at each CPU frequency and time it with micros(). Then, we’ll toggle a GPIO pin (GPIO5) as fast as the CPU can for 3 seconds and measure the toggle frequency on my oscilloscope.

Wiring: scope CH1 probe hooked on the GPIO5 wire, CH3 probe on the GPIO18 wire (used in LAB 4), and both probe ground leads on GND. Nothing else is connected, the ESP32 is powered from the USB cable.
If you’re not sure where GPIO5 and GPIO18 are on your board, check out the ESP32 DevKit V1 Pinout guide.
ESP32 CPU Speed Test Code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
/* * LAB Name: ESP32 CPU Frequency Speed Test (Execution Time & GPIO Toggle) * Author: Khaled Magdy * For More Info Visit: www.DeepBlueMbedded.com */ #define TOGGLE_PIN 5 const uint32_t FREQS_MHZ[] = {240, 160, 80, 40, 20, 10}; const uint8_t N_FREQS = sizeof(FREQS_MHZ) / sizeof(FREQS_MHZ[0]); volatile uint32_t Result = 0; // A fixed CPU-bound workload: 100k iterations of integer math uint32_t runWorkload() { uint32_t x = 12345; for (uint32_t i = 0; i < 100000; i++) { x = x * 1103515245 + 12345; x ^= (x >> 7); } return x; } void setup() { pinMode(TOGGLE_PIN, OUTPUT); Serial.begin(115200); delay(1000); Serial.println("CPU (MHz) | Workload Time (us) | millis()"); } void loop() { for (uint8_t i = 0; i < N_FREQS; i++) { setCpuFrequencyMhz(FREQS_MHZ[i]); // 1. Time the CPU-bound workload uint32_t t0 = micros(); Result = runWorkload(); uint32_t tWork = micros() - t0; // 2. A 1-second delay (the PC timestamps each line to check timekeeping) delay(1000); Serial.print(getCpuFrequencyMhz()); Serial.print(" | "); Serial.print(tWork); Serial.print(" | "); Serial.println(millis()); Serial.flush(); // 3. Toggle a GPIO pin as fast as the CPU can for 3 seconds (scope on GPIO5) uint32_t tEnd = millis() + 3000; while (millis() < tEnd) { for (uint16_t k = 0; k < 1000; k++) { digitalWrite(TOGGLE_PIN, HIGH); digitalWrite(TOGGLE_PIN, LOW); } } } } |
Code Explanation
The runWorkload() function is a simple pseudo-random number generator loop. It’s pure CPU work with no memory or peripheral access, so its execution time shows the raw CPU speed. The Result variable is volatile so the compiler can’t optimize the workload away.
The GPIO toggle part uses digitalWrite() in a tight loop. Its speed is set by how fast the CPU executes the digitalWrite() calls, so the toggle frequency on the scope follows the CPU clock directly.
ESP32 CPU Frequency vs Speed Result
Here are the results on my ESP32 DevKit V1. The workload time scales exactly with the CPU clock: 2.09ms at 240MHz, 6.31ms at 80MHz (3x slower), and 54.9ms at 10MHz (26x slower).


The capture below shows the GPIO5 toggle signal on my oscilloscope at 240MHz (left, 500ns/div) and at 10MHz (right, 10µs/div). CH1 (yellow) is the probe on GPIO5, and CH3 (cyan) is the probe on GPIO18, which isn’t used in LAB 3, so it stays low. The orange arrow under each capture marks one toggle period. The pin toggles at 926.6kHz at 240MHz and 38.6kHz at 10MHz, exactly 24 times slower, just like the 240/10 clock ratio. I got the same 1/24 ratio back in 2021 on the old core, but digitalWrite() itself is slower in core 3.x, so the absolute toggle rate is lower than it was then. The first HIGH pulse in the 10MHz capture is longer, because that’s where the loop leaves the 1000-toggle inner loop to check millis(). That one pulse lowers the scope’s own readout for this frame to 36.97kHz, while the average over the run is 38.6kHz.

The millis() column also proves that timekeeping stays correct at every CPU frequency. I compared it with the PC’s clock over 56 seconds of stepping through all the frequencies, and the difference was only 6ms, which is within the USB timing jitter.
LAB 4: What Changes Below 80MHz (APB Clock & PWM)
When the ESP32 CPU frequency goes below 80MHz, the APB bus clock drops with it (LAB 2 showed APB = 40, 20, 10MHz). In this example, we’ll see what that does to the PWM outputs. We’ll run 2 PWM signals at the same time: a fast 50kHz PWM on GPIO5 and a slow 1kHz PWM on GPIO18, both set up at 240MHz. Then we lower the CPU frequency step by step, measure both signals on the scope, apply ledcChangeFrequency(), and measure them again.
Wiring: the same as LAB 3: scope CH1 probe on GPIO5, CH3 probe on GPIO18, and the probe ground leads on GND.
ESP32 APB Clock PWM Test Code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
/* * LAB Name: ESP32 APB Clock Below 80MHz (PWM Frequency Test) * Author: Khaled Magdy * For More Info Visit: www.DeepBlueMbedded.com */ #define PWM_FAST_PIN 5 // 50kHz, 8-bit PWM (scope CH1) #define PWM_SLOW_PIN 18 // 1kHz, 8-bit PWM (scope CH3) const uint32_t FREQS_MHZ[] = {240, 80, 40, 20, 10}; const uint8_t N_FREQS = sizeof(FREQS_MHZ) / sizeof(FREQS_MHZ[0]); void setup() { Serial.begin(115200); delay(1000); // Both PWM outputs are configured while the CPU runs at 240MHz (APB = 80MHz) ledcAttach(PWM_FAST_PIN, 50000, 8); ledcAttach(PWM_SLOW_PIN, 1000, 8); ledcWrite(PWM_FAST_PIN, 128); // 50% duty cycle ledcWrite(PWM_SLOW_PIN, 128); // 50% duty cycle } void loop() { for (uint8_t i = 0; i < N_FREQS; i++) { setCpuFrequencyMhz(FREQS_MHZ[i]); Serial.print("CPU = "); Serial.print(getCpuFrequencyMhz()); Serial.print(" MHz, APB = "); Serial.print(getApbFrequency() / 1000000); Serial.println(" MHz -> PWM not re-configured (measure GPIO5 & GPIO18 now)"); delay(5000); // Re-apply the PWM frequencies after the CPU clock change ledcChangeFrequency(PWM_FAST_PIN, 50000, 8); ledcChangeFrequency(PWM_SLOW_PIN, 1000, 8); ledcWrite(PWM_FAST_PIN, 128); ledcWrite(PWM_SLOW_PIN, 128); Serial.println(" ledcChangeFrequency() applied"); delay(5000); } } |
Code Explanation
We attach both PWM pins with ledcAttach() while the CPU runs at 240MHz, so the LEDC driver picks its clock source and divider for an 80MHz APB clock. After every setCpuFrequencyMhz() call, we leave the PWM untouched for 5 seconds, then call ledcChangeFrequency() for both pins, which re-calculates the divider for the current clock, and wait another 5 seconds.
ESP32 PWM Frequency Below 80MHz Result
These are the frequencies I measured on my oscilloscope, with CH1 (yellow) on GPIO5 for the 50kHz PWM and CH3 (cyan) on GPIO18 for the 1kHz PWM:
| CPU / APB Clock | 50kHz PWM (Before) | 50kHz PWM (After ledcChangeFrequency) | 1kHz PWM (Before & After) |
|---|---|---|---|
| 240 / 80MHz | 50kHz | 50kHz | 1000Hz |
| 80 / 80MHz | 50kHz | 50kHz | 1000Hz |
| 40 / 40MHz | 25kHz | 50kHz | 1000Hz |
| 20 / 20MHz | 25kHz | 50kHz | 1000Hz |
| 10 / 10MHz | 25kHz | 25kHz (fails) | 1000Hz |

The capture above shows the CPU at 40MHz: before the fix on the left (10µs/div) and after ledcChangeFrequency() on the right (5µs/div). The orange arrows mark one period of the CH1 signal: 40µs (25kHz) before the fix, and 20µs (50kHz) after it. The 1kHz PWM on CH3 appears as a flat line at these timebases, because one period (1ms) is far wider than the screen, so each capture shows only part of a HIGH or LOW phase.
The fast 50kHz PWM runs from the APB clock, and it halves every time the APB clock halves under it: 80MHz to 40MHz gives 25kHz (and so does every later step, because we re-applied the frequency at the previous step). Calling ledcChangeFrequency() fixes it at 40MHz and 20MHz. At 10MHz, the fix fails with this error in the Serial Monitor, because an 8-bit PWM at 50kHz needs a 12.8MHz timer clock (50kHz x 256), more than the 10MHz APB clock can give:

The slow 1kHz PWM didn’t move at all. At such a low frequency, the LEDC driver can run the timer from a clock that doesn’t follow the APB bus, so the CPU frequency change doesn’t affect it. This explains why the problem appears with fast PWM signals and not with slow ones.
| Peripheral (ESP32) | Below 80MHz CPU (Core 3.3.12, Tested) |
|---|---|
| Serial (UART) at 115200 baud | Keeps working (LAB 2) |
| millis(), micros(), delay() | Keep correct time (LAB 3) |
| PWM at 1kHz | Unchanged (LAB 4) |
| PWM at 50kHz | Frequency halves with APB. Call ledcChangeFrequency() again (LAB 4) |
| WiFi | Crashes at 40MHz (task watchdog). Needs 80MHz or more |
The ESP32-S2, S3, C3, and C6 can run the PWM (LEDC) from the 40MHz crystal clock, and the Arduino core picks it by default on those chips, so this LAB matters most on the classic ESP32 boards like the DevKit V1.
Tip: Set the CPU frequency first (in the IDE menu or at the beginning of setup()), then initialize your peripherals. If you must change it later, re-apply the PWM and other peripheral settings after the change, or register an addApbChangeCallback() function that does it for you, and pick a PWM frequency and resolution that the lowest APB clock you’ll use can still reach.
Does WiFi Work Below 80MHz?
No. I tested it on the same board with a WiFi scan at each CPU frequency. The scan found 6 to 7 networks at 240, 160, and 80MHz. Starting WiFi at 40MHz crashed the ESP32: the WiFi task starves the idle task, the task watchdog fires, and the board keeps rebooting:

And when I dropped the CPU to 40MHz while WiFi was already running at 240MHz, setCpuFrequencyMhz(40) returned true with no crash, but the next scan found 0 networks (it found 7 at 240MHz). So the rule is simple: if your project uses WiFi or Bluetooth, never go below 80MHz.
ESP32 CPU Frequency vs Power Consumption
Lowering the ESP32 CPU frequency from 240MHz to 80MHz cuts the chip’s active current from up to 68mA down to 20 – 31mA, with WiFi and Bluetooth off. These are the numbers from the ESP32 Datasheet (Power Consumption by Power Modes, Modem-sleep mode, where the CPU runs and the radio is off):

| CPU Frequency | ESP32 Chip Current (CPU On, Radio Off) | Notes |
|---|---|---|
| 240MHz | 30 – 68mA | Dual-core chip, the range depends on the CPU load |
| 160MHz | 27 – 44mA | Dual-core chip (27 – 34mA single-core) |
| 80MHz | 20 – 31mA | Dual-core chip (20 – 25mA single-core), lowest with WiFi/BT |
| 40, 20, 10MHz | Not listed | Lower still, but the fixed part (flash, leakage, the board) stays |
| Light Sleep | 0.8mA | CPU paused, RAM kept |
| Deep Sleep | 10µA | CPU off, RTC timer and RTC memory on |
WiFi changes the picture completely: the datasheet lists about 95 – 100mA while the radio is receiving or listening, and up to 240mA while it transmits, which dwarfs the difference between 240MHz and 80MHz. So for a WiFi project, the CPU frequency is a small knob, and sleep modes are the big one.
Keep in mind that these numbers are for the ESP32 chip alone. A whole DevKit board draws more at any CPU frequency, because its voltage regulator, USB-to-serial chip, and power LED add their own current, and they don’t care about the CPU clock at all.
Tip: Lower isn’t always better for battery life. A task that takes 1ms at 240MHz takes about 3ms at 80MHz (LAB 3), so the energy for that task can end up nearly the same. If your ESP32 wakes up, does a short job, and sleeps again, it’s often better to run it at 240MHz, finish fast, and go back to sleep sooner. This is called “race to idle”.
Which ESP32 CPU Frequency Should You Use?
Use 240MHz when your code needs the speed, 80MHz for most WiFi and Bluetooth projects that want to save power, and 40MHz or lower only for projects with no radio that spend most of the time waiting. Here’s a quick guide:
| Your Project | CPU Frequency | Why |
|---|---|---|
| Heavy math, graphics, audio, fast sampling | 240MHz | Maximum speed. Finishing sooner and then sleeping often saves more energy than running slowly |
| WiFi / Bluetooth project on a battery | 80MHz | The lowest frequency that still runs WiFi and Bluetooth |
| Battery sensor node, no radio, mostly waiting | 10 – 40MHz | Lowest active current, but re-configure the APB peripherals (LAB 4) |
| Long waits between short tasks | Use sleep modes | Light sleep (0.8mA) and deep sleep (10µA) beat any CPU frequency |
Lowering the CPU frequency only reduces the active current. If your ESP32 spends most of its time waiting, ESP32 Sleep Modes will save far more power than any CPU frequency.
ESP32 CPU Frequency Troubleshooting
setCpuFrequencyMhz() Returns false
The frequency you asked for isn’t valid for your chip or crystal (for example 100, 30, or 5MHz on an ESP32). The CPU keeps its previous frequency. Use one of the values from the table above, or print getSupportedCpuFrequencyMhz() to see the list for your chip.
CPU Frequency Still Reads 240MHz
Check that setCpuFrequencyMhz() returned true and that you read getCpuFrequencyMhz() after it. The Tools > CPU Frequency setting is applied before setup(), so a value set in your code later always wins. On ESP32 chips rated for 160MHz (ESP32-S0WD), 240MHz is refused.
Serial Monitor Shows Garbage After Lowering The CPU Clock
Update your ESP32 core. On core 3.x, Serial at baud rates up to 250000 runs from the 1MHz REF_TICK clock, which stays correct at 10MHz (tested in LAB 2). Garbage at a low CPU frequency happens with old cores (1.0.x, which ran the UART from APB), or with baud rates above 250000, which still use the APB clock. In that case, call Serial.updateBaudRate() after the frequency change, or use 115200 baud.
PWM Frequency Is Wrong After Changing The CPU Frequency
You went below 80MHz on a classic ESP32, and a PWM that runs from the APB clock changed with it (a 50kHz PWM became 25kHz at 40MHz in LAB 4). Call ledcChangeFrequency() after the change, or set the CPU frequency before ledcAttach(). Re-check other APB peripherals the same way (I2C, SPI, timers).
ledc: requested frequency and duty resolution can not be achieved
The PWM frequency times 2resolution is higher than the clock the LEDC can use at this CPU frequency. At 10MHz, an 8-bit 50kHz PWM (12.8MHz) is impossible. Lower the PWM resolution (7-bit needs 6.4MHz), lower the PWM frequency, or use a higher CPU frequency.
Task Watchdog Got Triggered (CPU 0: wifi) at 40MHz
WiFi doesn’t work below 80MHz. Starting it at 40MHz makes the WiFi task starve the idle task, so the task watchdog resets the board in a loop (LAB 4). Use 80, 160, or 240MHz for any project that uses WiFi or Bluetooth, and switch the radio off with WiFi.mode(WIFI_OFF) before you go lower.
Can You Overclock the ESP32?
No. setCpuFrequencyMhz() refuses anything above the chip’s rated maximum (240MHz on the ESP32, S2, and S3, 160MHz on the C3 and C6), and the PLL can’t produce a higher CPU clock in the Arduino core. For more speed, split the work across both ESP32 cores with FreeRTOS tasks, or move to the ESP32-S3 or the 400MHz ESP32-P4.
Wrap Up
To conclude this tutorial, we’ve seen how to check and change the ESP32 clock speed in Arduino: setCpuFrequencyMhz() and the related functions, the valid CPU frequencies for each ESP32 chip, the clock tree behind them, and what happens to the APB peripherals below 80MHz. We’ve also measured on real hardware how the CPU frequency affects the speed of your code, and compared the current consumption at each CPU frequency.
To save even more power, check out the ESP32 Sleep Modes Tutorial. For the PWM outputs used in LAB 4, check out the ESP32 PWM Tutorial. If you’ve got any questions or suggestions, drop me a comment below and I’ll be glad to help! And check out the ESP32 Programming Tutorials series for more ESP32 tutorials.
Download ESP32 CPU Frequency Project Files
Download all attachment files for this Article/Tutorial (project files, schematics, code, etc.) using the link below. Everything is tested and verified to work on real hardware, as you’ve seen in the demo videos & screenshots. Please consider supporting my work if it helped you.
ESP32 CPU Frequency FAQ
The ESP32 CPU runs at 240MHz by default in the Arduino core, on 2 Xtensa LX6 cores. You can lower it to 160, 80, 40, 20 or 10MHz. The ESP32-S3 also runs at up to 240MHz, while the ESP32-C3 and C6 run at up to 160MHz.
Yes, by far. The Arduino UNO’s ATmega328P runs at 16MHz on an 8-bit core, while the ESP32 runs at up to 240MHz on two 32-bit cores. It also has far more memory (520KB of SRAM against 2KB).
No. In deep sleep, the CPU is powered down, so its frequency doesn’t matter. The deep sleep current (about 10µA for the chip) is the same whatever CPU frequency you used before. The ULP coprocessor runs from its own RTC clock, so the CPU frequency doesn’t affect it either.
No. WiFi and Bluetooth need a CPU frequency of at least 80MHz. Use 80MHz as the lowest CPU frequency for any ESP32 project that uses WiFi or Bluetooth.
The Arduino Nano ESP32 uses the ESP32-S3 chip, so it runs at 240MHz by default, on 2 Xtensa LX7 cores. Like the other ESP32 boards, you can lower it with setCpuFrequencyMhz() to 160, 80, 40, 20 or 10MHz, and WiFi and Bluetooth need 80MHz or more.
Yes. In the Arduino-ESP32 core, millis(), micros() and delay() use the esp_timer, which the core updates on every CPU frequency change, so they keep correct time at every frequency from 240MHz down to 10MHz.
Oh, thanks so much for this detailed explanation! YOU’re the BEST, Keep going
Thank you, Henry! I’m glad the tutorial helped. I’ve now updated it for the Arduino-ESP32 core 3.x, with every result measured on real hardware.
Does setting the CPU core clock affecting the ULP co-processor? In term of power consumption, does lowering the CPU clock will further reduce the power during deep sleep?
Good question, Adam. The CPU frequency doesn’t affect the deep sleep current, because the CPU is powered down in deep sleep (about 10µA for the ESP32 chip). The ULP coprocessor runs from its own RTC clock, so the CPU frequency doesn’t affect it either. I’ve added this to the FAQ section of the tutorial.
If I slow down the CPU frequency the 115200 baud setting is no longer valid in the terminal. (I get garbage characters instead of cpu freq info.) I’m surprised you have the correct text displayed…
I get the same result as well. I also get garbage chracters instead of CPU fre info.
Thanks for reporting this (and thanks, blendwoit, for confirming it). The garbage output came from the old Arduino-ESP32 core 1.0.x, which clocked the UART from the APB bus, so the baud rate changed whenever the CPU frequency went below 80MHz. In core 3.x, Serial at baud rates up to 250000 runs from the fixed 1MHz REF_TICK clock, and I tested 115200 baud down to 10MHz with no errors (LAB 2 in the updated tutorial). If you still see it, update your ESP32 core, or call Serial.updateBaudRate() after changing the CPU frequency.