Increasing arduino PWM pins

Last Updated on March 16, 2024

If we need more PWM pins in arduino board,  then we can convert digital arbitrary pin to PWM pin by using wiring library (softPWM library).

digital-pwm-pin-new

By using this softPWM library we can generate up to 20 PWM channels with the single hardware timer (Timer 2). We can create separate fade rates for on and off pulse.



Arduino Code

 

#include <SoftPWM.h>

void setup()
{
  SoftPWMBegin();
  
  SoftPWMSet(13, 0);

  SoftPWMSetFadeTime(13, 1000, 1000);
}

void loop()
{
  SoftPWMSet(13, 255);
  delay(1000);
  SoftPWMSet(13, 0);
  delay(1000);
}

 

You can get softPWM library here

(Note: refer library page before using servo)




Prototype

digital-pin-to-pwm-new       digitalpin-pwm-new

Leave a Reply

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