Labs / Digital · Beginner · 25 min
PWM and dimming
Understand average voltage from pulse width modulation.
Engineering instrumentation: This lab includes an instrument-style virtual test setup and parameter-driven waveform. For physical measurements, use the Practical Bench.
Parts
- ESP32
- LED and 220 ohm
- Breadboard
Steps
- Connect the LED to GPIO 18.
- Upload the PWM code.
- Change the duty cycle.
- Measure the average voltage with a multimeter.
Safety: check polarity and power off before changing the circuit.
ESP32 code (Arduino IDE)
const int LED=18;
void setup(){ ledcAttach(LED, 5000, 8); } // core 3.x
void loop(){ for(int d=0; d<=255; d++){ ledcWrite(LED,d); delay(8);} }Viva questions
What is duty cycle?
The percentage of the period the signal is HIGH.
Why does the LED look dimmer?
The average power is lower and the eye averages fast flashes.
Where is PWM used?
Motors, servos, dimmers and power supplies.