Find all your DIY electronics in the MakerShed. 3D Printing, Kits, Arduino, Raspberry Pi, Books & more!

Another clever trick from the world of electronics – Pulse Width Modulation is a simple method for controlling analog devices via a digital signal. It’s also a very efficient way to drive motors, lamps, LEDs, & more.

If you’ve ever faded an LED with an Arduino – you’ve used PWM. But you don’t need a microcontroller to generate a PWM signal. The ever-versatile 555 timer chip can be configured to modulate its output duty cycle in response to a potentiometer – with the help of some relatively simple circuitry. Or for a more robust solution, consider the DC to Pulse Width Modulator kit suitable for sending up to 6.5A of current and built around the Motorola SG3525 – a chip dedicated to the art of PWM.

Oh and – I’d be denying my own nature if I didn’t mention at least one audio-related application. Indeed, PWM comes in very handy for generating simple sound from a microcontroller – melodies too!

Subscribe to the MAKE Podcast in iTunes, download the m4v video directly, or watch it on YouTube and Vimeo.

Collin Cunningham

Born, drew a lot, made video, made music on 4-track, then computer, more songwriting, met future wife, went to art school for video major, made websites, toured in a band, worked as web media tech, discovered electronics, taught myself electronics, blogged about DIY electronics, made web videos about electronics and made music for them … and I still do!


Related

Comments

  1. Good demonstration.  I was a bit confused initially that the power supply voltage was powering the motor.  After reading the kit docs, I understand that the power supply voltage shown was only used as a variable reference to change the duty cycle, and the power for the motor was from a different supply. Possibly this could be given more emphasis.  

    1. you raise a good point – I intended to explain that third connection powering the board and also show the reference voltage as a second trace on my scope.  Unforch, plans went astray when I noticed my second probe was busted :/

    2. you raise a good point – I intended to explain that third connection powering the board and also show the reference voltage as a second trace on my scope.  Unforch, plans went astray when I noticed my second probe was busted :/

  2. Good demonstration.  I was a bit confused initially that the power supply voltage was powering the motor.  After reading the kit docs, I understand that the power supply voltage shown was only used as a variable reference to change the duty cycle, and the power for the motor was from a different supply. Possibly this could be given more emphasis.  

  3. Good demonstration.  I was a bit confused initially that the power supply voltage was powering the motor.  After reading the kit docs, I understand that the power supply voltage shown was only used as a variable reference to change the duty cycle, and the power for the motor was from a different supply. Possibly this could be given more emphasis.  

  4. I’ve used this before. Interesting ideas:
    :can be used in CRT or digital monitors to have more than 6 colors, or 2 if monochrome, through rapidly turning (sub)pixels on or off.
    :can dim a florescent light. Make sure the PWM output voltage is equal to the necessary input voltage for the light! My PWM driver takes out a third of the voltage to internal resistance, so 9V into the PWM driver is needed for a 6V light.
    :reducing the oscillation of a line follower, thermostat, or other difficult-to-maintain outputs.
    :I would appreciate it if someone were to post instructions for a 120V, home outlet-style PWM driver. Maybe someone could have the electronics in their house dimmed by an Ardruino based upon how close they are to the appliance, or use a simpler relay to shut off appliances like mircrowaves, and turn them back on before anyone can reach them.

  5. I’ve used this before. Interesting ideas:
    :can be used in CRT or digital monitors to have more than 6 colors, or 2 if monochrome, through rapidly turning (sub)pixels on or off.
    :can dim a florescent light. Make sure the PWM output voltage is equal to the necessary input voltage for the light! My PWM driver takes out a third of the voltage to internal resistance, so 9V into the PWM driver is needed for a 6V light.
    :reducing the oscillation of a line follower, thermostat, or other difficult-to-maintain outputs.
    :I would appreciate it if someone were to post instructions for a 120V, home outlet-style PWM driver. Maybe someone could have the electronics in their house dimmed by an Ardruino based upon how close they are to the appliance, or use a simpler relay to shut off appliances like mircrowaves, and turn them back on before anyone can reach them.

  6. I’ve used this before. Interesting ideas:
    :can be used in CRT or digital monitors to have more than 6 colors, or 2 if monochrome, through rapidly turning (sub)pixels on or off.
    :can dim a florescent light. Make sure the PWM output voltage is equal to the necessary input voltage for the light! My PWM driver takes out a third of the voltage to internal resistance, so 9V into the PWM driver is needed for a 6V light.
    :reducing the oscillation of a line follower, thermostat, or other difficult-to-maintain outputs.
    :I would appreciate it if someone were to post instructions for a 120V, home outlet-style PWM driver. Maybe someone could have the electronics in their house dimmed by an Ardruino based upon how close they are to the appliance, or use a simpler relay to shut off appliances like mircrowaves, and turn them back on before anyone can reach them.

  7. I’ve used this before. Interesting ideas:
    :can be used in CRT or digital monitors to have more than 6 colors, or 2 if monochrome, through rapidly turning (sub)pixels on or off.
    :can dim a florescent light. Make sure the PWM output voltage is equal to the necessary input voltage for the light! My PWM driver takes out a third of the voltage to internal resistance, so 9V into the PWM driver is needed for a 6V light.
    :reducing the oscillation of a line follower, thermostat, or other difficult-to-maintain outputs.
    :I would appreciate it if someone were to post instructions for a 120V, home outlet-style PWM driver. Maybe someone could have the electronics in their house dimmed by an Ardruino based upon how close they are to the appliance, or use a simpler relay to shut off appliances like mircrowaves, and turn them back on before anyone can reach them.

  8. T W says:

    At time 1:41 you say “The amount of time our pulse wave is on vs. off.” The red line is 4 units and the blue line is 4 units.  However, the duty cycle is 50%.  I think it should be “the amount of time our pulse wave is on vs the length of time for the entire pulse.” or some such. 
    from: http://www.its.bldrdoc.gov/fs-1037/dir-013/_1849.htm 
    duty cycle: 1. In an ideal pulse train, i.e. , one having rectangular pulses, the ratio of the pulse duration to the pulse period.  
    pulse period: The reciprocal of the pulse repetition rate.
    pulse repetition rate: The number of pulses per unit time.

    I *think* I have that right.  I’m not an electrician.  If I’m wrong, let me know.

    Also, I love your vids.  Keep ‘em comin!

  9. I’m quite sure T W is correct about the definition of a duty cycle.

    This also leads into playing sounds. I’m almost positive that you can’t use only PWM to create a tone. Try it with a pezio buzzer. I did and it wouldn’t change the sound based on a potentiometer I had connected to my Arduino. This is because sounds are based on frequency/period of a signal/pulse: how often it repeats. A PWM pulse always repeats in the same amount of time, so it will only make one tone. For example, on Arduino’s PWM code page*, it says that the frequency of the PWM signal is 490Hz. When you change the PWM value, you change the duty cycle, which is like the makeup of the signal, but not how long the signal (pulse) itself lasts.

    *http://arduino.cc/en/Reference/AnalogWrite

  10. I’m quite sure T W is correct about the definition of a duty cycle.

    This also leads into playing sounds. I’m almost positive that you can’t use only PWM to create a tone. Try it with a pezio buzzer. I did and it wouldn’t change the sound based on a potentiometer I had connected to my Arduino. This is because sounds are based on frequency/period of a signal/pulse: how often it repeats. A PWM pulse always repeats in the same amount of time, so it will only make one tone. For example, on Arduino’s PWM code page*, it says that the frequency of the PWM signal is 490Hz. When you change the PWM value, you change the duty cycle, which is like the makeup of the signal, but not how long the signal (pulse) itself lasts.

    *http://arduino.cc/en/Reference/AnalogWrite

  11. Did a similar experiment in college. Instead though we used a microcontroller that sent an adjustable duty cycle square wave to a FET that used a built in LED and a light effect transistor, which in turn amplified the signal and drove a motor at different speeds. Neato man.