PWM In Arduino - ElectronicWings
Maybe your like
Pulse Width Modulation (PWM) is a technique by which width of a pulse is varied while keeping the frequency of the wave constant. It is a method for generating an analog signal using a digital source.

A PWM signal consists of two main components that define its behaviour: a duty cycle and a frequency.
What is the Duty Cycle of SignalA period of a pulse consists of an ON cycle (5V) and an OFF cycle (0V). The fraction for which the signal is ON over a period is known as a duty cycle.

E.g. A pulse with a period of 10ms will remain ON (high) for 2ms.Therefore, duty cycle will be
D = 2ms / 10ms = 20%
Through PWM technique, we can control the power delivered to the load by using ON-OFF signal. The PWM signals can be used to control the speed of DC motors and to change the intensity of the LED.
Pulse Width Modulated signals with different duty cycle are shown below

The frequency of a signal determines how fast the PWM completes a cycle (i.e. 1000 Hz would be 1000 cycles per second) which means how fast it switches between ON (high) and OFF (low) states. By repeating this ON-OFF pattern at a fast-enough rate, and with a certain duty cycle, the output will appear to behave like a constant voltage analog signal when providing power to devices.
Example: If we want to create a 2V analog signal for a given digital source that can be either high (on) at 5V, or low (off) at 0V, we can use PWM with a duty cycle of 40%. It will provide output 5V for 40% of the time. If the digital signal is cycled fast enough, then the voltage seen at the output appears to be the average voltage. If the digital low is 0V (which is usually the case) then the average voltage can be calculated by taking the digital high voltage multiplied by the duty cycle, or 5V x 0.4 = 2V.
Now, let's see PWM in Arduino.
PWM Pins of Arduino UnoArduino Uno has 6 8-bit PWM channels. The pins with symbol ‘~’ represents that it has PWM support. These PWM pins are shown in below image.

analogWrite (pin, duty cycle)
It is used to generate PWM or output analog value to a specified PWM channel.
pin – pin on which we want to generate pwm or analog signal.
duty cycle – it lies in between 0 (0%, always off) – 255 (100%, always on).
e.g. analogWrite (3, 127) //generates pwm of 50% duty cycleLED Fading using Arduino PWMLet’s create small application in which led will fade continuously. This led fading application used for decoration in functions and festivals.
LED Interfacing to Arduino Uno
Let’s build an application in which we will control the brightness of led using Arduino by varying potentiometer knob. So, when we rotate knob of potentiometer, ADC of Arduino will read this analog signal. Then we will generate PWM signal proportional to the analog signal.
Interfacing Diagram
For more implementation, you can visit
- Control Speed of DC motor using Arduino
- Servo motor control through Potentiometer using Arduino
Tag » Arduino Code Pwm Output
-
Arduino PWM Tutorial - Arduino Project Hub
-
Basics Of PWM (Pulse Width Modulation) | Arduino Documentation
-
Secrets Of Arduino PWM | Arduino Documentation
-
AnalogWrite() - Arduino Reference
-
Arduino PWM : Generate Fix And Variable Frequency Duty Cycle ...
-
PWM In Arduino-Pulse Width Modulation - YouTube
-
ESP32 PWM With Arduino IDE (Analog Output)
-
[PDF] 1 Basic PWM Properties 2 Using PWM On An Arduino - Sparkfun
-
[PDF] Arduino PWM And Analog Output - Halvorsen.blog
-
PWM In Arduino - Tutorialspoint
-
Arduino - Pulse Width Modulation - Tutorialspoint
-
Arduino PWM Output And Its Uses - The Definitive Guide - Technobyte
-
Arduino PWM: Pulse Width Modulation In Arduino
-
Arduino Tutorial => Control A DC Motor Through The Serial Port...