Example Code for Arduino-Purple RGB LED Control

Last revision 2026/01/24

This article provides a comprehensive guide on controlling a 3528 RGB LED with Arduino, focusing on achieving purple lighting effects using specific PWM values and sample code.

Wiring Diagram

DFR0239 RGB LED Breakout (3528) Connection Diagram

Other Preparation Work

As 3528 is a common anode component,the PWM value formula: PWM=255-RGB.
For example: Purple(128,0,128)

Sample Code

int r=128;
int g=0;
int b=128; //purple

void setup()
{
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(12,OUTPUT);
}
void loop()
{
  digitalWrite(12,HIGH);    //Power 5V
  analogWrite(11,(255-r));
  analogWrite(10,(255-g));
  analogWrite(9,(255-b));
}

Was this article helpful?

TOP