Control LED Brightness with ESP32 PWM
Overview
Pulse Width Modulation (PWM) is a technique that changes the pulse width while keeping the waveform frequency constant. PWM is primarily used for controlling the brightness of LEDs, the speed of DC motors, controlling servo motors, and any scenario where a digital source is needed to generate an analog signal.
This article discusses the PWM functionality of the ESP32 development board. All GPIO pins on the ESP32 development board (except Power, GND, Tx, Rx, and EN) can be used to generate PWM signals. We will create a simple circuit as an example to change the brightness of an LED based on the PWM signal.
PWM Terminology
Before diving into the PWM functionality on the ESP32, let's discuss some PWM-related terms:
- TON (On Time): The duration for which the signal is high.
- TOFF (Off Time): The duration for which the signal is low.
- Period: The sum of the TON and TOFF of a PWM signal.
- Duty Cycle: The percentage of time within a PWM signal period that the signal is high. For example, if a 10ms pulse stays ON (high) for 5ms, then the duty cycle is: Duty Cycle = 5/10 * 100 = 50%.