Simply use an RGB LED with an ARDUINO UNO board

Marc DANIEL

Well-Known Member
Licensed User
An RGB LED is essentially made up of three LEDs—red, green, and blue—captured within a single transparent or diffuse epoxy lens. Each internal LED chip emits light at a specific wavelength corresponding to its color: red typically around 620–630 nm, green around 520–530 nm, and blue around 460–470 nm. These chips are carefully positioned next to each other to ensure their light blends smoothly, allowing the human eye to perceive a combined color rather than three separate colors. This compact integration enables RGB LEDs to produce millions of hues through variable intensity control of the three channels.

RGB_LED.jpg


Structurally, an RGB LED package includes four wires or pins extending from the base. Three of these pins correspond to the color channels: R (red), G (green), and B (blue), while the fourth serves as a common terminal shared between the three LEDs. The common terminal can be connected to either the positive supply voltage or ground, depending on the type of RGB LED.

The programming is completely different depending on the type of RGB LEDs available. The following documents and information pertain to common cathode (GND) RGB LEDs.

RGB LED Connection.jpg


RGB_LED.B4R:
'LGB_LED - Diode à couleurs changeantes
' With Arduino UNO Board

#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region


Sub Process_Globals
    Public Serial1 As Serial
    Private RedLED, GreenLED, BlueLED As Pin
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("Start")
    RedLED.Initialize(11, RedLED.MODE_OUTPUT)
    GreenLED.Initialize(10, GreenLED.MODE_OUTPUT)
    BlueLED.Initialize(9,BlueLED.MODE_OUTPUT)
    Start
End Sub

Sub Start
    For i = 1 To 3
       
        ' Red Color (full red, no green, no blue)
        RedLED.AnalogWrite(255)
        GreenLED.AnalogWrite(0)
        BlueLED.AnalogWrite(0)
        Delay(2000)
   
        ' Green Color (no red, full green, no blue)
        RedLED.AnalogWrite(0)
        GreenLED.AnalogWrite(255)
        BlueLED.AnalogWrite(0)
        Delay(2000)
   
        ' Blue Color (no red, no green, full blue)
        RedLED.AnalogWrite(0)
        GreenLED.AnalogWrite(0)
        BlueLED.AnalogWrite(255)
        Delay(2000)  
       
        ' Cyan
        RedLED.AnalogWrite(0)
        GreenLED.AnalogWrite(255)
        BlueLED.AnalogWrite(255)
        Delay(2000)
       
        ' Yellow
        RedLED.AnalogWrite(255)
        GreenLED.AnalogWrite(255)
        BlueLED.AnalogWrite(0)
        Delay(2000)
       
        ' Violet
        RedLED.AnalogWrite(128)
        GreenLED.AnalogWrite(0)
        BlueLED.AnalogWrite(128)
        Delay(2000)
    Next
   
    RedLED.DigitalWrite(False)
    GreenLED.DigitalWrite(False)
    BlueLED.DigitalWrite(False)
End Sub
 

Attachments

  • RGB_LED.zip
    995 bytes · Views: 77
Last edited:

Marc DANIEL

Well-Known Member
Licensed User
VIDEO (Connection GND-)

RGB color chart

  • Here are some examples of common colors with their RGB codes:
  • Red: (255, 0, 0)
  • Green: (0, 255, 0)
  • Blue: (0, 0, 255)
  • Yellow: (255, 255, 0)
  • Cyan: (0, 255, 255)
  • Magenta: (255, 0, 255)
  • White: (255, 255, 255)
  • Black: (0, 0, 0)
Couleurs.jpg
 
Last edited:

Marc DANIEL

Well-Known Member
Licensed User
However, if you have common anode RGB_LEDs (VCC+), the programming is practically reversed compared to the common cathode RGB_LEDs (GND) discussed previously.

RGB_LED_VCC+.jpg


Common anode VCC+ RGB LED:
'LGB_LED - Diode à couleurs changeantes
'There are two main RGB LED configurations depending on the polarity of their shared terminal
' common anode And common cathode types.
'The programming of these LEDs differs depending on the type of RGB_LEDs available.

'Common anode VCC+  RGB LED
' With Arduino UNO Board

#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region


Sub Process_Globals
    Public Serial1 As Serial
    Private RedLED, GreenLED, BlueLED As Pin
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("Start")
    RedLED.Initialize(11, RedLED.MODE_OUTPUT)
    BlueLED.Initialize(9, BlueLED.MODE_OUTPUT)
    GreenLED.Initialize(10,GreenLED.MODE_OUTPUT)
    Start
End Sub

Sub Start
    For i = 1 To 3
     
        ' Red Color (full red, no green, no blue)
        RedLED.AnalogWrite(0)
        GreenLED.AnalogWrite(255)
        BlueLED.AnalogWrite(255)
        Log("RED")
        Delay(3000)
 
        ' Blue Color (no red, no green, full blue)
        RedLED.AnalogWrite(255)
        GreenLED.AnalogWrite(255)
        BlueLED.AnalogWrite(0)
        Log("BLUE")
        Delay(3000)
 
        ' Green Color (no red, no blue, full green)
        RedLED.AnalogWrite(255)
        GreenLED.AnalogWrite(0)
        BlueLED.AnalogWrite(255)
        Log("GREEN")
        Delay(3000)
     
        ' Cyan
        RedLED.AnalogWrite(255)
        GreenLED.AnalogWrite(0)
        BlueLED.AnalogWrite(0)
        Log("CYAN")
        Delay(3000)
     
        ' Yellow
        RedLED.AnalogWrite(0)
        GreenLED.AnalogWrite(0)
        BlueLED.AnalogWrite(255)
        Log("YELLOW")
        Delay(3000)
     
        ' Purple
        RedLED.AnalogWrite(128)
        GreenLED.AnalogWrite(255)
        BlueLED.AnalogWrite(128)
        Log("PURPLE")
        Delay(3000)
     
        ' White
        RedLED.AnalogWrite(0)
        GreenLED.Analogwrite(0)
        BlueLED.AnalogWrite(0)
        Log("WHITE")
        Delay(3000)
     
    Next
 
    RedLED.DigitalWrite(True)
    GreenLED.DigitalWrite(True)
    BlueLED.DigitalWrite(True)
    Log("No color")
End Sub

RGB_LED2_bb.jpg


To protect your LEDs, it is recommended to connect the white wire to the 3.3V output rather than the 5V output.
 

Attachments

  • RGB_LED2.zip
    1.2 KB · Views: 14
Last edited:
Top