Raspberry Pi RGB LED

From Xojo Documentation

An RGB LED is an LED that lets you independently control its red, green and blue elements.


  • 4 jumper wires
  • 3 10k resistors

Wire the Circuit

An RGB LED has 4 pins. The longest pin (#3 on the LED) is the "cathode" pin that should be wired to ground. The other pins are as follows:

  • Pin #1: Green
  • Pin #2: Blue
  • Pin #3: Cathode/Gnd
  • Pin #4: Red

You will need to put resistors between the RGB LED pins and the wires that connect to the GPIO pins. The specific resistor you'll need varies depending on the type of RGB LED and its power requirements. 10k resistors seemed to work fine with the RGB LED used in this example.

This chart shows the RGB LED pin to GPIO pin mappings:

Create the Xojo App

You'll use the open-source Xojo GPIO library to control the RGB LED. This code will randomly change the color of the LED:


// These are the pins to which you wired the RGB LED
Const kRedPin = 21
Const kBluePin = 20
Const kGreenPin = 16

Dim led As New GPIO.RGBLED(kRedPin, kGreenPin, kBluePin)

// Display random colors
For i As Integer = 1 To 100
led.SetColor(Xojo.Math.RandomInt(0, 255), _
Xojo.Math.RandomInt(0, 255), _
Xojo.Math.RandomInt(0, 255))


// turn everything off

Build the app for Linux ARM and transfer it to the Raspberry Pi to run it.