Skip to content

PWM LED Dimming - Analog Output on ESP32

Beginning of the lesson

🔌 What is PWM?

Pulse Width Modulation (PWM) is a technique that creates the illusion of analog voltage using rapid digital on/off switching. Instead of providing a steady voltage, PWM rapidly toggles between HIGH (3.3V) and LOW (0V).

Key Concept: The duty cycle determines how long the signal stays HIGH versus LOW during each cycle.
  • 0% duty cycle = Always OFF (LED off)
  • 50% duty cycle = Half ON, half OFF (LED at 50% brightness)
  • 100% duty cycle = Always ON (LED at full brightness)

Because the switching happens thousands of times per second, our eyes perceive a smooth, steady brightness level rather than flickering.

⚡ ESP32 PWM Advantages

ESP32 has significantly more powerful PWM capabilities compared to Arduino Uno:

Feature Arduino Uno ESP32
PWM Channels 6 (fixed pins) 16 independent
Frequency Range ~490Hz or ~980Hz 1Hz - 40MHz
Resolution 8-bit (0-255) Up to 16-bit (0-65535)
Pin Flexibility Specific pins only ANY GPIO pin
Important: ESP32 uses a different approach than Arduino's simple analogWrite(). You must configure PWM channels first!
📊 Understanding PWM Duty Cycle

The chart below shows how different duty cycles affect the average voltage output:

Interactive visualization — available in the full lesson

Continue this lesson on YourAIZone

The full lesson has the complete explanation, worked examples, common mistakes, tests with instant checking and an AI tutor. Start right away as a guest, or create an account to keep your progress.

In the full lesson

  • The complete explanation
  • Worked examples
  • Common mistakes and how to avoid them
  • Test questions: 15
  • AI tutor that answers questions about the topic
  • Progress tracking for students, parents and teachers