Pulse Width Modulation {Tutorial 15}
Pulse Width Modulation(PWM) is a digital technology that uses the amount of power delivered to a device that can be changed. It generates analogue signals by using a digital source. For example, LED brightness is controlled using Pulse Width Modulation(PWM)
Duty Cycle in PWM
The duty cycle of the PWM signal refers to the ratio of the time that the signal is in a high(on) state over the total time it takes to complete one cycle. It is commonly expressed as a percentage or a ratio.
The Arduino supports PWM on yourboard - pins 3, 4,5,9,10 and 11) at 500Hz. (500 times a second.)
You can give it a value between 0 and 255. 0 means that it is never 5V. 255 mean is always 5V depending on your board type. To make this work you have call analogWrite() with the value. The ratio of“ON” time to total time is called the “duty cycle”. A PWM outputthatisONhalf the time is said to have a duty cycle of 50%.
Example
To control the brightness of an LED with Arduino with the PWM technique check program below
analogWrite() Function Syntax:
analogWrite ( pin , value ) ;
The value representing the duty cycle, and the number is between 0(off) and 255(on).
int ledPin = 9; // LED connected to digital pin 9
void setup() {
pinMode(ledPin, OUTPUT); // sets the pin as output
}
void loop() {
analogWrite(ledPin, 255); //set duty cycle to always on
}
More Pulse Width Modulation examples will be seen in project examples
Comments
Post a Comment