834
The KY-009 RGB LED Module can emits a range of colour by mixing red, green and blue. The amount of each primary color is adjusted using the PWM pins on an Arduino.
The KY-009 RGB Full Color LED SMD Module consists of a 5050 SMD LED
Connection
You need to use resistors to prevent burnout, here are some recommended values
KY-009 | Resistor | Arduino |
R | 180Ω resistor | Pin 9 |
G | 110Ω resistor | Pin 10 |
B | 110Ω resistor | Pin 11 |
– | GND |
Code
[codesyntax lang=”cpp”]
int redpin = 11; //select the pin for the red LED
int bluepin =10; // select the pin for the blue LED
int greenpin = 9;// select the pin for the green LED
int val;
void setup() {
pinMode(redpin, OUTPUT);
pinMode(bluepin, OUTPUT);
pinMode(greenpin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
for(val = 255; val > 0; val--)
{
analogWrite(redpin, val); //set PWM value for red
analogWrite(bluepin, 255 - val); //set PWM value for blue
analogWrite(greenpin, 128 - val); //set PWM value for green
Serial.println(val); //print current value
delay(1);
}
for(val = 0; val < 255; val++)
{
analogWrite(redpin, val);
analogWrite(bluepin, 255 - val);
analogWrite(greenpin, 128 - val);
Serial.println(val);
delay(1);
}
}
[/codesyntax]
Links
37 in 1 box Sensor Kit For Arduino Starters brand in stock