- Pulse-Width Modulation or PWM is a very simple but important principle of electronics. PWM is used in many industries, but regardless of application, the theory remains the same. PWM allows for analog like controlls through a digital circuit. Digital circuits have two states on and off. Similar to a light switch, there's no other option available. Analog signals can be adjusted to any value from off to full power. Similar to a dimmer switch on a light, the power level can be adjusted to any value between high and low.
This graphic outlines the various components of an electrical wave. The Wavelength is how long it takes for a wave to complete one cycle. This is also called frequency or period. The Amplitude is the height of the wave. In our case, 5 volts on the Arduino. An important part of a Pulse Wave is the Duty Cycle. Duty Cycle is the percentage of time the signal is high in the peroid of the wave. In this wave, the Duty Cycle is 50 percent. This is called a Square Wave meaning the signal is high for 50 percent of the Wavelength and low for the other 50 percent.
If the wave was high for 75 percent of the peroid and low for 25 percent of the period, we would say that that wave has a Duty Cycle of 75 percent. This image shows an LED turned on with a Digital Right Command. If you output a Pulse Wave from the Arduino with a 75 percent Duty Cycle to an LED, the LED would appear to be about 75 percent as bright as the LED that was simply turned on with the Digital Right Command. At 50 percent, the LED is dimmer still.
Duty Cycle is the magic behind PWM. On a high frequency wave, by adjusting the amount of time the signal is high, you can change the Average Voltage over time to get any value between high and low. This is shown by the grey line. The pulse gets steadily wider. When I overlay this purple line, you can see that over time the Average Voltage steadily increases and then decreases. Using this principle, you can adjust the brightness of an LED similar to an Analog controller.
Pulse-Width Modulation will also allow the Arduino to set the speed of a motor, or I can set the direction a servo is pointing. Without PWM, these devices would only have two settings on or off.
- Using basic PWM output
- Adjusting the brightness of LEDs
- Color mixing with RGB LEDs
- Using analog inputs to drive output
- Testing components with a multimeter
- Using the map function
- Debugging code efficiently with the serial monitor
- Controlling servos and motors