The Arduino has a fixed PWM frequency of 490Hz - or does it? On digital pins 3, 9, 10 and 11 it's 490Hz, but on pins 5 and 6 it's 976Hz. Confused?
And it is possible to change the PWM frequency to a higher (or lower) frequency by altering the timer prescalers. Here's how it's done.

By Julian

Youtuber, shed dweller, solar charge controller aficionado

12 thoughts on “Arduino pwm tutorial #1 – how to change pwm frequency”
  1. Avataaar/Circle Created with python_avatars Alf says:

    i don't get why it is so hard to change the frequency, I still don't get how it works and have to copy pre made code

  2. Avataaar/Circle Created with python_avatars cowsongs says:

    THANK YOU. This is huge for driving any non-trivial load off an Arduino pin. For an LED, it's fine. But if you want to drive some other entire circuit module, maybe some transistor circuit, etc, and you need to approximate smooth DC, a PWM at high frequency can very efficiently and simply be filtered to reasonably smooth DC with a small cap and resistor, much more easily (and with quicker response) than low freq 490 Hz PWM.

  3. Avataaar/Circle Created with python_avatars Sri Balaji says:

    Its varying the duty cycle 🥲

  4. Avataaar/Circle Created with python_avatars Icaros Savvides says:

    I think you'll find that the discrepancy between the expected and measured nominal 31Khz frequency at the end of the video is down to being on too slow a 'scope range, if you set to 1us/div you'll likely be closer to target.

  5. Avataaar/Circle Created with python_avatars karim invt says:

    Plz code 3-phase

  6. Avataaar/Circle Created with python_avatars Usman Yaqoob says:

    Hello
    can i reduce frequency to 10hz

  7. Avataaar/Circle Created with python_avatars TYGAMatt says:

    This is many moons old, but would like to ask how you got the PWM library to install. I've had no luck!
    Tried installing from manage libraries but it doesn't show up and tried the include library/zip file from the sketch. Just says the PWM.h file doesn't exist. Most frustrating.

  8. Avataaar/Circle Created with python_avatars paul meynell says:

    Excellent as usual

  9. Avataaar/Circle Created with python_avatars Pooraram Jakhar says:

    Can you run HDD ~18000RPM
    With controlled speed
    By this arduino
    I will pay for this
    It's part of my huge project..

  10. Avataaar/Circle Created with python_avatars Max Xiang says:

    Very helpful

  11. Avataaar/Circle Created with python_avatars webslinger2011 says:

    Was fumbling around for 3 days looking for this. This will help on my arduino audio school project. Thanks!!!

  12. Avataaar/Circle Created with python_avatars h3ct0r1991 says:

    Thank you so much Julian, it's a excellent tutorial.
    Regards from Colombia!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.