Stduino learning - 3 color LED module

What are you developing?
Post Reply
jacobli
Posts: 42
Joined: Fri Jun 11, 2021 3:40 am

Stduino learning - 3 color LED module

Post by jacobli »

Description
Tri-color LED module made of a full-color LED, through the PWM voltage input of the three pins R, G, B can adjust the intensity of the three base colors (red/blue/green) so as to achieve the full-color color mixing effect. R, G, B correspond to the control of red, green, blue three LED pins.
1.2.jpg
1.2.jpg (39.62 KiB) Viewed 1811 times
Experimental purpose
LED to achieve from green to red, from red to blue, from blue to green.

Equipment
Four-legged three-color LED light module, breadboard, Stduino Uno/Nano, DuPont wire

Circuit connection
1.1.png
1.1.png (83.12 KiB) Viewed 1811 times
The LED tricolor light module generally has four pins, of which "-" is connected to GND.
The other three are connected to the pins on the Stduino Uno board that are capable of PWM output (i.e. the pins with wavy lines after the pin number).
Here A4 is connected to the red LED pins, A5 to the green LED pins, and A6 to the blue LED pins.

code

Code: Select all

int RedLED = A4;
int GreenLED =A5;
int BlueLED = A6;

void setup()
{
  pinMode(RedLED,OUTPUT);
  pinMode(GreenLED,OUTPUT);
  pinMode(BlueLED,OUTPUT);
}

void setColor(int red,int green,int blue)
{
  analogWrite(RedLED,red);
  analogWrite(GreenLED,green);
  analogWrite(BlueLED,blue);
}

void loop()
{
  int i,j;
  //Green to red gradient
  for(i=0,j=255;i<256;i++)
  {
    setColor(i,j,0);
    delay(4);
    j--;
  }
  //Red to blue gradient
  for(i=0,j=255;i<256;i++)
  {
    setColor(j,0,i);
    delay(4);
    j--;
  }
  //Blue to green gradient
  for(i=0,j=255;i<256;i++)
  {
    setColor(0,i,j);
    delay(4);
    j--;
  }   
}
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Stduino learning - 3 color LED module

Post by mrburnette »

Note:

Your LED module (appears) to have 3x 150 Ohm resistors for limiting the current. Unfortunately, with the same voltage applied simultaneously to G, R, and B, the LED will not produce white light. Not so important in just fading the colors one-to-another, but certainly something everyone needs to be made aware.

The above is due to (largely) the Voltage Drop (forward Vd) of the LED junction.

Image

A second reason for the difference is that the R, G, B LEDs do not produce the same intensity for a finite current.

You can work around these issues with changing resistances (thus current) but the Blue LED is problematic with a 3.3 Volt system because the Vd is rather large and the junction will unlikely be driven efficiently.

Suggest using FET drivers for the LEDs, Vcc of 5V for LEDs, and separate resistors determined by experimentation. Remember, the human eye processes color intensity non-linearly.

Image
jacobli
Posts: 42
Joined: Fri Jun 11, 2021 3:40 am

Re: Stduino learning - 3 color LED module

Post by jacobli »

What you say makes perfect sense, thanks for the correction!
I'll try it as you said!
Post Reply

Return to “Projects”