How To Change Frequency On PWM Pins Of Arduino UNO
Maybe your like
Last updated on March 27th, 2024 at 05:04 pm
Arduino Uno is one of the most commonly used development boards these days. It can be used for almost any application that one can think of. One such application is in high-frequency circuits.
But to use a controller in a high-frequency circuit like in a buck converter, the controller must be able to generate high-frequency PWM waves. And if the controller you are using is Arduino Uno, then you must know how to change the frequency of these pins.
Now there are many facts about Arduino with which many students are not familiar. One of the facts is this:
“There is a certain default frequency for each PWM pin, which is called when the analogWrite command is used on that pin. And this default frequency can be changed to a value as high as 65Khz and as low as 30Hz by using just one line code“.
PWM frequency change on other Arduino boards
How to change frequency on PWM pins of Arduino Mega
How To Change Frequency On PWM Pins Of Arduino Nano
You can also watch this video for quick reference:
Here is the default frequency of each PWM pin of Arduino UNO:
1) PWM frequency for D3 & D11:
490.20 Hz (The default)
2) For D5 & D6:
976.56 Hz (The default)
3) For D9 & D10:
490.20 Hz (The default)
These frequencies are optimum for low-frequency applications like fading an LED. However, these default frequencies are not suitable for High-frequency circuits. For example, 1Khz is nothing when it comes to an S.M.P.S.
There are many projects in which we require high-frequency pulses. One such project is a Buck Converter. So to achieve a frequency lower or higher than the default one, a one-line code you can use to change it is given below:
One line code for changing PWM frequency on D3 & D11 pins:
TCCR2B = TCCR2B & B11111000 | B00000001; // for PWM frequency of 31372.55 Hz TCCR2B = TCCR2B & B11111000 | B00000010; // 3921.16 Hz TCCR2B = TCCR2B & B11111000 | B00000011; // 980.39 Hz TCCR2B = TCCR2B & B11111000 | B00000100; // (default) TCCR2B = TCCR2B & B11111000 | B00000101; // 245.10 Hz TCCR2B = TCCR2B & B11111000 | B00000110; // 122.55 Hz TCCR2B = TCCR2B & B11111000 | B00000111; // 30.64 HzOne line code for changing PWM frequency on D5 & D6 pins:
TCCR0B = TCCR0B & B11111000 | B00000001; // for PWM frequency of 62500.00 Hz TCCR0B = TCCR0B & B11111000 | B00000010; // 7812.50 Hz TCCR0B = TCCR0B & B11111000 | B00000011; // (default) TCCR0B = TCCR0B & B11111000 | B00000100; // 244.14 Hz TCCR0B = TCCR0B & B11111000 | B00000101; // 61.04 HzOne line code for changing PWM frequency on D9 & D10 pins:
TCCR1B = TCCR1B & B11111000 | B00000001; // set timer 1 divisor to 1 for PWM frequency of 31372.55 Hz TCCR1B = TCCR1B & B11111000 | B00000010; // 3921.16 Hz TCCR1B = TCCR1B & B11111000 | B00000011; // 490.20 Hz (default) TCCR1B = TCCR1B & B11111000 | B00000100; // 122.55 Hz TCCR1B = TCCR1B & B11111000 | B00000101; // 30.64 HzExample
Let’s use the above code to change the frequency on pin D3. The circuit is simulated in proteus software.
Check out: How to add Arduino library to Proteus
Step 1: Two Arduino are selected and placed on the front panel.
Step 2: Digital Pin 3 ( PWM pin) of each Arduino is connected to the oscilloscope.
Step 3: Two separate programs are written for each Arduino. The first one outputs the PWM signal at a default frequency. For the second board, it is set to 31372.55 Hz using the command given above.
Program for Arduino1 – Default frequency on Pin 3
void setup() { pinMode(3,OUTPUT); // put your setup code here, to run once: } void loop() { analogWrite(3,155); // put your main code here, to run repeatedly:}Program for Arduino2 – Changing the default frequency on D3
void setup() { TCCR2B = TCCR2B & B11111000 | B00000001; // for PWM frequency of 31372.55 Hz pinMode(3,OUTPUT); } void loop() { analogWrite(3,155); }Step 4: Run the simulation

As you can see in the image given above, the second board(at the top) outputs the PWM signal at a higher frequency than the first board.
Learn more about Timers and PWM from here
FAQs
What is the PWM frequency of Arduino?
The PWM frequency of Arduino UNO and Nano is 490Hz for pins D3, D9, D10, and D11 and 980Hz for pins D5 and D6.
How to control PWM in Arduino?
To control PWM, the command analogWrite(PWM pin, duty cycle) is used. There are 6 PWM pins on Arduino UNO and Nano- 3,5,6,9,10 and 11. The duty cycle varies between 0 to 255.
Tag » Arduino Pwm Pin 6
-
AnalogWrite() - Arduino Reference
-
Secrets Of Arduino PWM | Arduino Documentation
-
Arduino PWM Tutorial - Arduino Project Hub
-
PWM On Pin 6 And 13 With Arduino Micro - LEDs And Multiplexing
-
PWM Library And Pin 6 Problem - Arduino Forum
-
PWM | Arduino
-
PWM On Pins 5 + 6 - Syntax & Programs - Arduino Forum
-
Frequency Changing Of Pwm Pins Of Arduino Uno - ElectronicWings
-
[PDF] Arduino PWM And Analog Output - Halvorsen.blog
-
How To Change The PWM Frequency Of Arduino - NerdyTechy
-
Read PWM Signal From Pixhawk To Arduino - Stack Overflow
-
[PDF] 1 Basic PWM Properties 2 Using PWM On An Arduino - Sparkfun
-
Maxint-rd/FastPwmPin: Arduino Library To Generate A Fast PWM ...