Home » ESP32 PWM Calculator – Frequency, Resolution & Duty Cycle Tool

ESP32 PWM Calculator – Frequency, Resolution & Duty Cycle Tool

by shedboy71
ESP32 tools

ESP32 PWM Calculator

Calculate ESP32 PWM frequency, resolution, duty cycle, LED dimming values, servo pulse widths, motor PWM settings and ready-to-use Arduino or MicroPython code.

PWM Settings

Results

Frequency: -
Resolution Steps: -
Maximum Duty Value: -
Calculated Duty Value: -
Duty Cycle: -
PWM Period: -
High Time: -
Low Time: -

LED Brightness Preview

Brightness preview: 50%

Suggested ESP32 PWM Settings

Use Case Typical Frequency Typical Resolution Notes
LED Dimming 500 Hz – 5 kHz 8–12 bit Higher frequency reduces visible flicker.
DC Motor 10 kHz – 25 kHz 8–10 bit Higher frequency can reduce audible whining.
Servo Motor 50 Hz Usually 16 bit Servo control normally uses pulse width timing.
Buzzer / Tone 100 Hz – 5 kHz+ 8 bit Frequency affects pitch.

Arduino Code Example

MicroPython Code Example

How ESP32 PWM Works

The ESP32 uses LEDC PWM hardware to generate pulse-width modulation signals. PWM rapidly switches a pin on and off. The frequency controls how often the signal repeats, while the duty cycle controls how long the signal stays high during each cycle.

For LED dimming, the duty cycle controls perceived brightness. A low duty cycle makes the LED appear dimmer, while a high duty cycle makes it brighter. For motor control, the duty cycle can control speed. For buzzers, the frequency changes the pitch.

Frequency vs Resolution Trade-Off

On the ESP32, very high PWM frequencies reduce the maximum practical resolution. A 20-bit PWM signal gives extremely fine duty cycle control, but it cannot usually be used at very high frequencies. For common projects, 8-bit to 12-bit resolution is often enough.

Good Starting Values

For LED dimming, start with 5,000 Hz and 8-bit resolution. For DC motors, try 20,000 Hz and 8-bit resolution. For servos, use 50 Hz and calculate the correct pulse width for your servo instead of treating it like a normal brightness-style PWM signal.

Understanding ESP32 PWM

Pulse Width Modulation (PWM) is one of the most useful features available on the ESP32. Rather than outputting a constant analogue voltage, the ESP32 rapidly switches a digital pin on and off. By adjusting how long the signal stays high during each cycle, it can simulate different power levels for LEDs, motors, buzzers, and many other devices.

The ESP32 includes dedicated LEDC (LED Control) hardware that can generate PWM signals independently of the main processor. This means PWM outputs remain stable even when the microcontroller is busy handling Wi-Fi, Bluetooth, sensor readings, or other tasks.

For most projects, PWM is used to control brightness, speed, position, or sound. Small changes to frequency and duty cycle can significantly affect how connected hardware behaves.

Frequency and Duty Cycle Explained

Two settings determine how a PWM signal behaves:

Frequency

Frequency determines how many complete PWM cycles occur every second.

Examples:

  • 50 Hz = 50 cycles per second
  • 1,000 Hz = 1,000 cycles per second
  • 20,000 Hz = 20,000 cycles per second

Different applications benefit from different frequency ranges.

Application Typical Frequency
Servo Motors 50 Hz
LED Dimming 500 Hz – 5 kHz
DC Motor Control 10 kHz – 25 kHz
Audio Generation 100 Hz – 20 kHz

Duty Cycle

Duty cycle represents the percentage of each cycle that the signal remains high.

Examples:

  • 0% = always off
  • 25% = on for one quarter of the cycle
  • 50% = equal on and off time
  • 75% = mostly on
  • 100% = always on

For an LED, a higher duty cycle increases brightness. For a motor, it generally increases speed.

Choosing the Right Resolution

PWM resolution determines how many individual brightness or power levels are available.

Common values include:

Resolution Available Levels
8-bit 256
10-bit 1,024
12-bit 4,096
16-bit 65,536

Higher resolutions provide smoother transitions, especially for LED fading applications. However, increasing resolution can reduce the maximum frequency available.

For many practical projects:

  • 8-bit is sufficient for motors
  • 10-bit or 12-bit works well for LEDs
  • 16-bit is often used for servos and precision control

Recommended ESP32 PWM Settings

If you are unsure where to start, the following settings are usually reliable:

LED Dimming

  • Frequency: 5,000 Hz
  • Resolution: 8-bit
  • Duty Cycle: Variable

This frequency is high enough to eliminate visible flicker in most situations.

DC Motor Speed Control

  • Frequency: 20,000 Hz
  • Resolution: 8-bit
  • Duty Cycle: 10–100%

Using frequencies above the audible range can reduce motor noise.

Servo Motors

  • Frequency: 50 Hz
  • Resolution: 16-bit

Servos rely on pulse timing rather than simple duty cycle percentages, so frequency accuracy is particularly important.

Passive Buzzers

  • Frequency: 200 Hz – 5 kHz
  • Resolution: 8-bit

Changing frequency changes the tone produced by the buzzer.

Common ESP32 PWM Mistakes

Many beginners encounter similar issues when first working with PWM.

Using Input-Only Pins

GPIO 34–39 are input-only on most ESP32 boards and cannot generate PWM output.

Choosing a Frequency That Is Too Low

Very low frequencies can cause visible LED flicker or motor vibration.

Choosing a Frequency That Is Too High

Extremely high frequencies may reduce available resolution and make configuration more difficult.

Ignoring Boot Strapping Pins

Some ESP32 GPIOs affect the boot process. Using them incorrectly can prevent the board from starting normally.

Common boot-sensitive pins include:

  • GPIO 0
  • GPIO 2
  • GPIO 4
  • GPIO 5
  • GPIO 12
  • GPIO 15

Real-World PWM Project Ideas

Once you understand PWM, you can build a wide range of ESP32 projects.

Popular examples include:

  • Smart LED lighting systems
  • RGB LED controllers
  • Automatic plant lighting
  • Motor speed controllers
  • Fan speed regulators
  • Robotic vehicle control
  • Servo-driven mechanisms
  • Smart blinds and curtains
  • Audio tone generators
  • Home automation devices

Many ESP32 projects use PWM alongside Wi-Fi and Bluetooth features, allowing remote control through mobile apps, web dashboards, or cloud platforms.

Why the ESP32 Is Popular for PWM Projects

The ESP32 is particularly well suited for PWM applications because it offers:

  • Multiple PWM channels
  • Flexible frequency settings
  • High-resolution duty cycle control
  • Integrated Wi-Fi and Bluetooth
  • Low cost
  • Excellent Arduino and MicroPython support

You may also like

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.