How does PWM actually control motor speed and LED brightness

Sharing is caring!

How Does PWM Actually Control Motor Speed and LED Brightness?

Free Daily Electronics Newsletter

Tutorials, news, and one component explained simply — every day.

Subscription Form
PWM duty cycle controlling LED brightness
PWM controls LED brightness by varying the duty cycle — the ratio of ON time to total period

Pulse Width Modulation sounds complicated, but the concept is surprisingly simple. Imagine you’re controlling a light switch, but instead of leaving it on or off, you’re flicking it on and off really, really fast—so fast that your eyes can’t see the individual flickers. If the switch is on 50% of the time and off 50% of the time, the light appears half as bright. If it’s on 75% of the time, it looks three-quarters as bright.

That’s PWM in a nutshell. A microcontroller like an Arduino Uno (datasheet) toggles a digital output pin between HIGH (typically 5V or 3.3V) and LOW (0V) at a fixed frequency. The ratio of “on time” to “off time” is called the duty cycle, and it’s measured as a percentage.

For example:

  • A 0% duty cycle means the pin is always LOW—completely off
  • A 50% duty cycle means the pin is HIGH half the time
  • A 100% duty cycle means the pin is always HIGH—full power

The magic happens because many electronic components respond to the average voltage or power over time, not the instantaneous switching. This is especially true when the switching happens fast enough—typically hundreds or thousands of times per second.

How PWM Dims LEDs (And Why Your Eyes Can’t Tell)

When you dim an LED using PWM, you’re not actually reducing the current flowing through it during the “on” periods. During each pulse, the LED receives full current and glows at full brightness. But because these pulses happen so quickly—often at 500 Hz to 20 kHz—your eye’s persistence of vision averages out the flashes into what appears to be a steady, dimmer light.

PWM duty cycle comparison showing 0%, 25%, 50%, and 100% duty cycles
Duty cycle determines average power: 0% is always off, 100% is always on

Think of it like a movie projector. A film runs at 24 frames per second, each frame separated by a moment of darkness, but your brain perceives smooth, continuous motion. PWM works on the same principle, but much faster.

How PWM tricks the human eye - rapid switching appears as steady brightness
Switching faster than ~100Hz makes the flickering invisible to the human eye

Here’s the practical advantage: because the LED is either fully on or fully off, you’re not wasting power as heat in a current-limiting resistor or dimming circuit. This makes PWM incredibly efficient compared to analog dimming methods. That’s why nearly every modern LED light bulb, from your desk lamp to automotive headlights, uses PWM control internally.

You can see PWM in action in projects like building an 8x8x8 LED cube with Arduino, where controlling brightness across hundreds of LEDs would be impossible without PWM’s efficiency.

How PWM Controls Motor Speed (The Mechanical Side)

Motors are where PWM gets really interesting. Unlike LEDs, which respond almost instantly to changes in voltage, motors have mechanical inertia. A DC motor’s rotor has mass, and it takes time to speed up or slow down. This physical property is what makes PWM motor control work so elegantly.

How PWM controls DC motor speed using inertia to smooth rapid on-off pulses
Motor inertia smooths the PWM pulses into steady rotation at reduced speed

When you apply a PWM signal to a DC motor:

  1. During the “on” pulse, the motor receives full voltage and accelerates
  2. During the “off” period, the motor coasts, gradually slowing down due to friction and load
  3. Before it slows down significantly, the next “on” pulse arrives, accelerating it again

If the PWM frequency is high enough (typically 1 kHz to 20 kHz for motors), the motor’s mechanical inertia smooths out these pulses. The rotor can’t physically respond to each individual pulse, so it settles into a steady average speed determined by the duty cycle.

A 25% duty cycle delivers one-quarter of the average power, resulting in roughly one-quarter of the maximum speed. A 75% duty cycle gives you three-quarters speed. It’s not perfectly linear due to motor characteristics and load, but it’s close enough for most applications.

Understanding how different components respond to control signals is crucial—whether you’re using PWM with motors or choosing the right communication protocol for sensors in your project.

The Frequency Factor: Why Speed Matters

Not all PWM is created equal. The frequency—how many times per second the signal switches—matters tremendously, and different applications need different frequencies.

PWM frequency comparison showing effects of 100Hz, 1kHz, and 20kHz
Higher PWM frequencies eliminate visible flicker and audible motor whine

For LEDs: Too low a frequency (below 100 Hz) and you’ll see visible flickering, especially in your peripheral vision or if the LED is moving. Most microcontrollers default to 490 Hz or 980 Hz for LED control, which works well. Some sensitive people can still detect flicker at these frequencies, so premium applications use 5 kHz or higher.

For motors: Too low a frequency and you’ll hear an audible whine—that’s the motor vibrating at the PWM frequency. Too high a frequency and you can actually cause excessive heating in the motor driver circuit due to switching losses. Sweet spot for most DC motors: 1 kHz to 20 kHz.

For servo motors: Standard hobby servos don’t use typical PWM. They expect a 50 Hz signal where the pulse width (not duty cycle) determines position—typically 1 ms for 0° and 2 ms for 180°. This is technically PWM, but specialized for position control rather than power control.

When working with microcontrollers like the ESP32 with built-in peripherals, you often have hardware-based PWM generators that can achieve much higher frequencies and better precision than software-based PWM.

PWM in the Real World: Beyond the Basics

PWM isn’t just for hobby projects. It’s everywhere in modern electronics:

  • Computer fans: Your CPU cooler uses PWM to adjust fan speed based on temperature
  • Power supplies: Switch-mode power supplies use PWM at hundreds of kilohertz to efficiently convert voltages
  • Electric vehicles: The motor controllers in EVs use sophisticated PWM techniques to control massive amounts of power
  • Audio amplifiers: Class D amplifiers use PWM to achieve 90%+ efficiency
  • Solar charge controllers: PWM regulates how much power flows from solar panels to batteries

In fact, the same principles that let you fade an LED in a simple Arduino sensor project are scaled up to control multi-kilowatt industrial motors and grid-tied inverters.

The Hardware Behind PWM: Timers and Transistors

Inside your microcontroller, PWM is generated by hardware timers—specialized circuits that count clock cycles and toggle output pins at precise intervals. An Arduino Uno has three timers that generate six PWM outputs on pins 3, 5, 6, 9, 10, and 11. These aren’t magic—they’re just counters that compare their current count to a threshold value you set in your code.

How Arduino generates PWM using internal timer counter and comparator
Arduino’s internal timer counts 0-255 and compares against the analogWrite() threshold

But microcontroller pins can’t drive much current—typically 20-40 mA maximum. For LEDs, that’s often enough, but for motors, you need a driver circuit. This is where transistors come in, acting as electronically controlled switches that let small PWM signals control large currents.

A MOSFET (datasheet example) or motor driver IC like the L293D (datasheet) takes your 5V PWM signal and switches much higher voltages and currents to the motor. The transistor is doing the heavy lifting—the microcontroller is just giving it instructions. This relationship between control signals and power devices mirrors concepts explored in understanding how “smart” components actually work.

Common PWM Pitfalls (And How to Avoid Them)

Even though PWM is straightforward, beginners often run into these issues:

Problem: Motor makes a high-pitched whine.
Solution: Increase your PWM frequency. Most Arduino PWM defaults are too low for quiet motor operation.

Problem: LED seems to flicker on camera or in peripheral vision.
Solution: Increase frequency above 1 kHz, or use analog dimming for camera-facing applications.

Problem: Motor driver IC gets extremely hot.
Solution: You might be switching too fast for your particular driver, or you need a heatsink. Check driver specifications.

Problem: Motor doesn’t start spinning until duty cycle reaches 30-40%.
Solution: This is normal—motors have starting friction. You need minimum torque to overcome static friction. Compensate in software or use a motor controller with current feedback.

Conclusion

PWM is one of those beautiful engineering solutions that’s both simple and powerful. By rapidly toggling between on and off states, it gives you smooth, efficient control over components without complex analog circuitry. Whether you’re dimming LEDs, controlling motor speed, or building something more ambitious, understanding PWM is fundamental to modern electronics.

The next time you adjust your screen brightness or feel a smartphone’s haptic feedback, remember: that’s PWM at work, switching thousands of times per second to create the illusion of analog control in a purely digital world. From Faraday’s early electrical discoveries to modern transistor-based switching, the evolution of electronics has always been about finding clever ways to control power—and PWM might be one of the cleverest.

<

Parts List

Here are the components mentioned for experimenting with PWM:

Free Daily Electronics Newsletter

Tutorials, news, and one component explained simply — every day.

Free Daily Electronics Newsletter

Tutorials, news, and one component explained simply — every day.

Subscription Form (#5)
Scroll to Top