ESP32: PWM Motor and LED Control
Use hardware PWM safely for dimming and motor-speed control.
◷ 45 minParts and tools
- ESP32
- Logic-level MOSFET
- Flyback diode
- DC motor or LED
Lesson
Learning objective
Use hardware PWM safely for dimming and motor-speed control.
Procedure
- Review the circuit and confirm the board voltage.
- Build and inspect the wiring before applying power.
- Upload the example, observe the result and record your readings.
- Change one parameter, predict the result and test again.
Troubleshooting
Check power, ground, pin selection, polarity, compiler target and serial output. Use a multimeter or logic analyser where appropriate.
Example code
const int pin=18;
void setup(){ ledcAttach(pin,5000,8); }
void loop(){ ledcWrite(pin,128); }Knowledge check
A motor should be driven through which component?
