This is the SMD RGB LED Common Cathode Module, These module has 3 separate LEDs the Red, Green and Blue which can be individually driven by applying a voltage to the appropriate module pin this example code is uses the Arduino analogWrite(PWM) function to cycle through the full possible output colors this smd led module is capable of producing a rainbow color scheme.
NOTE: This module does not include current limiting resistor and therefore you should not connect this module directly to the Arduino DIO pins. This allows the module to be used with a range of supply voltages but you must drive the LED via an appropriate current limiting resistor otherwise it will be unusable.
Required Components
Ar du ino UNO/MEGA/NANO/PRO
SMD RGB LED Module Board / Common 5mm or 3mm RGB Led)
3x Resistors
1x Solder Less Bread Board
Jumper Wires
Wiring Diagram
Arduino Sketch Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#define BLUE_LED_DIO 11 /* Select the DIO for driving the BLUE LED */ #define RED_LED_DIO 9 /* Select the DIO for driving the RED LED */ #define GREEN_LED_DIO 10 /* Select the DIO for driving the GREEN LED */ /* Initialise serial and DIO */ void setup() { /* Configure the DIO pins used by the analogWrite PWM function */ pinMode(BLUE_LED_DIO, OUTPUT); pinMode(RED_LED_DIO, OUTPUT); pinMode(GREEN_LED_DIO, OUTPUT); } /* Main program loop */ void loop() { int k; /* Slowly reduce the red LED's intensity and at the same time increase the green LED's intensity */ for (k = 0; k <=255; k++) { analogWrite(RED_LED_DIO,255 - k); analogWrite(GREEN_LED_DIO, k); delay(10); } /* Slowly reduce the green LED's intensity and at the same time increase the blue LED's intensity */ for (k = 0; k <=255; k++) { analogWrite(GREEN_LED_DIO,255 - k); analogWrite(BLUE_LED_DIO, k); delay(10); } /* Slowly reduce the blue LED's intensity and at the same time increase the red LED's intensity */ for (k = 0; k <=255; k++) { analogWrite(BLUE_LED_DIO,255 - k); analogWrite(RED_LED_DIO, k); delay(10); } } |
Pingback:Wiring the 14CORE 37 Sensors for Arduino & Raspberry Pi | 14Core.com