In this section, I will describe the RGB LED Module, the connection between this module and Arduino board and the code for Arduino to make use this module.
In the previous article, we discussed about the RGB LED SMD module. Today, we have the module which has the same functionality of the SMD module. The difference is the structure of the module. This module has a through-hole technology (THT) instead of surface-mound device (SMD), and has a bigger in size and built-in resistors included in the module.
LED is usually the component to be used to begin programming in Arduino. In fact, we use the Blink code example to display the blinking built-in LED of Arduino on pin 13 or the external LED that you provided on that pin. LED stands for Light Emitting Diode. RGB stands for Red, Green and Blue, pertaining to 3 primary colors used by RGB, so it could emit different colors. In the given picture below, You will see each pin corresponds for RGB, and the common is GND, which is the common cathode.
Connect the pin R of the module to pin 11 of Arduino , pin G to pin 10, and pin B to pin 9, and GND pin to GND pin of Arduino.
Note: Make sure the pin 11, 10 and 9 are labeled PWM pins, which has the ~ sign with them. If not, then move to other pins of your Arduino, and change the code pin values below.
In the code, we set the pin 9, 10 and 11 as outputs for red, green and blue pins. There's a custom function named color_rgb, where it has 3 parameters to accept red, green and blue argument values. These values represents the brightness of the LEDs where the minimum value is 0 and the maximum value is 255. In the loop example, we call the color_rgb() function to set the values so it would display the desired colors for every 100 milliseconds.
Upload and check the RGB LED module if it displays different colors every 100 milliseconds.