Thursday 11 February 2016

What is Pulse Width Modulation (PWM)

Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means. Digital control is used to create a square wave, a signal switched between on and off. This on-off pattern can simulate voltages in between full on (5 Volts) and off (0 Volts) by changing the portion of the time the signal spends on versus the time that the signal spends off. The duration of "on time" is called the pulse width. To get varying analog values, you change, or modulate, that pulse width. If you repeat this on-off pattern fast enough with an LED for example, the result is as if the signal is a steady voltage between 0 and 5v controlling the brightness of the LED.


Fig- Pulse Width Modulation
In arduino uno, we have six pwm channels viz pin no. 3,5,6,9,10 and 11.

A sample program for rgb led:

  const int red=9,green=11,blue=10;    // read only variable

  void setup()                         // this loop will run only once
  {
      pinMode(red,OUTPUT);
      pinMode(green,OUTPUT);
      pinMode(blue,OUTPUT);
  }

  void loop()                          // infinite loop
   {
      analogWrite(green,255);          // 100% duty cycle
      analogWrite(red,127);            // 50% duty cycle
      analogWrite(blue,191);           // 75% duty cycle
   }

Fritzing sketch

PWM helps in saving power consumption

Stay tuned for more upates !!!

No comments:

Post a Comment