TCS Pune

ESP32: PWM Motor and LED Control

Practical lesson

ESP32: PWM Motor and LED Control

Use hardware PWM safely for dimming and motor-speed control.

◷ 45 min

Parts 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

  1. Review the circuit and confirm the board voltage.
  2. Build and inspect the wiring before applying power.
  3. Upload the example, observe the result and record your readings.
  4. 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?

Ready when you are

Need help with your laptop or computer?

Send us the model and fault details. Start your repair request online or contact TCS Pune directly.

WA