SMD 3Color LED Module(KY-009)
This is an LED module that controls Red, Blue, Green primary colors with values from 0 to 255.
It is similar to a 3-color LED model.
Specifications
- Operating Voltage: 5V
- Operating Current: 20mA ~ 30mA
Example Usage Hardware (excluding cables and breadboard)
- Arduino board
- SMD 3Color LED Module
- Push button
- Jumper cables
Connection
Use pins D9, D10, D11 for PWM output for analog output.
Arduino | SMD 3Color LED Module | PUSH Button |
GND | - | connected |
D12 | connected | |
D11 | R | |
D10 | G | |
D9 | B |
Example Code
This is an example where the LED color changes every time the button is pressed.
#define btn1 12
#define red 11
#define green 10
#define blue 9
int btnFlg1 = 0;
int btn1Chk() {
if (digitalRead(btn1) == 0) {
btnFlg1 = 1;
return 0;
}
if (btnFlg1 == 1) {
btnFlg1 = 0;
return 1;
}
return 0;
}
int state = 0;
void setup() {
pinMode(btn1, INPUT_PULLUP);
}
void loop() {
if (btn1Chk()) {
switch (state) {
case 0:
analogWrite(red, 255);
break;
case 1:
analogWrite(red, 0);
analogWrite(green, 255);
break;
case 2:
analogWrite(green, 0);
analogWrite(blue, 255);
break;
case 3:
analogWrite(red, 255);
analogWrite(green, 255);
analogWrite(blue, 0);
break;
case 4:
analogWrite(red, 255);
analogWrite(green, 0);
analogWrite(blue, 255);
break;
case 5:
analogWrite(red, 0);
analogWrite(green, 255);
analogWrite(blue, 255);
break;
case 6:
analogWrite(red, 255);
analogWrite(green, 255);
analogWrite(blue, 255);
break;
case 7:
analogWrite(red, 0);
analogWrite(green, 0);
analogWrite(blue, 0);
break;
default:
break;
}
state++;
if (state > 7) state = 0;
}
delay(10);
}
Execution Result
Please check the working video at the link.