KY-016 RGB 5mm LED
LED module which contains a red, blue and green LED. These are connected to each other by means of a common cathode.
- Arduino
- Raspberry Pi
- Raspberry Pi Pico
- Micro:Bit
This LED module contains red, blue and green LEDs that are connected via a common cathode. The red LED has a forward voltage of 1.8 V, while the green and blue LEDs each require 2.8 V. All LEDs operate at a forward current of 20 mA. With this module, you can create different colors by adjusting the brightness of the individual LEDs. It is ideal for applications where visual signals or colored displays are required. The common cathode makes it easy to connect and integrate into various projects, whether for decorative lighting, status displays or other creative applications.
Technical Data | |
---|---|
Forward voltage [Red] | 1.8 V |
Forward voltage [Green, Blue] | 2.8 V |
Forward current | 20 mA |
Series resistors:
Different series resistors are required depending on the color being controlled.
Input voltage | Series resistor |
---|---|
red | 180 Ω |
green | 100 Ω |
blue | 100 Ω |
Pin assignment
Arduino | Sensor |
---|---|
Pin 10 | LED Red |
Pin 11 | LED Green |
Pin 12 | LED Blue |
GND | GND |
1. Code example: ON/OFF
This code example shows how the integrated LEDs can be changed alternately, in 3 second cycles, by means of a definable output pin.
int led_red = 10; // Pin for red
int led_green = 11; // Pin for green
int led_blue = 12; // Pin for blue
void setup() {
// Initialization of output pins for the LEDs
pinMode(led_red, OUTPUT);
pinMode(led_green, OUTPUT);
pinMode(led_blue, OUTPUT);
}
// Main program loop
void loop () {
digitalWrite(led_red, HIGH); // red LED is switched on
digitalWrite(led_green, LOW); // green LED is switched off
digitalWrite(led_blue, LOW); // blue LED is switched off
delay(3000); // Wait for 3 seconds
digitalWrite(led_red, LOW); // red LED is switched off
digitalWrite(led_green, HIGH); // green LED is switched on
digitalWrite(led_blue, LOW); // blue LED is switched off
delay(3000); // Wait for 3 seconds
digitalWrite(led_red, LOW); // red LED is switched off
digitalWrite(led_green, LOW); // green LED is switched off
digitalWrite(led_blue, HIGH); // blue LED is switched on
delay(3000); // Wait for 3 seconds
}
2. Code example: PWM
Pulse width modulation [PWM] can be used to regulate the brightness of an LED - in this process, the LED is switched on and off at specific time intervals, with the ratio of the switch-on and switch-off times corresponding to a relative brightness. Due to the inertia of human vision, human eyes interpret such on/off behavior as a change in brightness. More information on this topic can be found in this article by Analog IC Tips.
Several LEDs are integrated in this module - different colors can thus be created by superimposing different brightness levels. This is shown in the following code example.
To load the following code example onto your Arduino, we recommend using the Arduino IDE. In the IDE, you can select the appropriate port and board for your device.
Copy the code below into your IDE. To upload the code to your Arduino, simply click on the upload button.
int led_red = 10; // Pin for red
int led_green = 11; // Pin for green
int led_blue = 12; // Pin for blue
void setup() {
// Initialization of output pins for the LEDs
pinMode(led_red, OUTPUT);
pinMode(led_green, OUTPUT);
pinMode(led_blue, OUTPUT);
}
void loop() {
// Within a For loop, the three LEDs are given different PWM values
// This creates a color gradient in which different colors are created by mixing different
// brightness levels of the two integrated LEDs, different colors are created
for(int i = 255; i > 0; i--) {
analogWrite(led_blue, i);
analogWrite(led_green, 255 - i);
analogWrite(led_red, 128 - i);
delay(10);
}
// In the second For loop, the color gradient is run backwards
for(int i = 0; i < 255; i++) {
analogWrite(led_blue, i);
analogWrite(led_green, 255 - i);
analogWrite(led_red, 128 - i);
delay(10);
}
}
This LED module contains red, blue and green LEDs that are connected via a common cathode. The red LED has a forward voltage of 1.8 V, while the green and blue LEDs each require 2.8 V. All LEDs operate at a forward current of 20 mA. With this module, you can create different colors by adjusting the brightness of the individual LEDs. It is ideal for applications where visual signals or colored displays are required. The common cathode makes it easy to connect and integrate into various projects, whether for decorative lighting, status displays or other creative applications.
Technical Data | |
---|---|
Forward voltage [Red] | 1.8 V |
Forward voltage [Green, Blue] | 2.8 V |
Forward current | 20 mA |
Depending on the input voltage, series resistors are required.
Input voltage | Series resistor |
---|---|
3.3 V [Red] | 180 Ω |
3,3 V [Green] | 100 Ω |
3,3 V [Blue] | 100 Ω |
5 V [Red] | 180 Ω |
5 V [Green] | 100 Ω |
5V [Blue] | 100 Ω |
Pin assignment
Raspberry Pi | Sensor |
---|---|
GPIO 25 [Pin 22] | LED Red |
GPIO 24 [Pin 18] | LED Green |
GPIO 23 [Pin 16] | LED Blue |
GND [Pin 6] | GND |
Code example (ON/OFF)
This code example shows how the integrated LEDs can be changed alternately, in 3 seconds cycles, by means of a definable output pin.
# Required modules are imported and set up
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
# Here the output pin is declared, to which the LEDs are connected.
LED_ROT = 25
LED_GREEN = 24
LED_BLUE = 23
GPIO.setup(LED_ROT, GPIO.OUT, initial= GPIO.LOW)
GPIO.setup(LED_GRUEN, GPIO.OUT, initial= GPIO.LOW)
GPIO.setup(LED_BLUE, GPIO.OUT, initial= GPIO.LOW)
print ("LED test [press CTRL+C to exit test]")
# main program loop
try:
while True:
print("LED RED 3 seconds on")
GPIO.output(LED_ROT,GPIO.HIGH) #LED is turned on
GPIO.output(LED_GRUEN,GPIO.LOW) #LED is switched on
GPIO.output(LED_BLUE,GPIO.LOW) #LED is switched on
time.sleep(3) # wait mode for 4 seconds
print("LED GREEN 3 seconds on")
GPIO.output(LED_ROT,GPIO.LOW) #LED is switched on
GPIO.output(LED_GRUEN,GPIO.HIGH) #LED is switched on
GPIO.output(LED_BLUE,GPIO.LOW) #LED is switched on
time.sleep(3) #wait mode for 3 seconds
print("LED BLUE 3 seconds on")
GPIO.output(LED_ROT,GPIO.LOW) #LED is switched on
GPIO.output(LED_GRUEN,GPIO.LOW) #LED is switched on
GPIO.output(LED_BLUE,GPIO.HIGH) #LED is switched on
time.sleep(3) #wait mode for 3 seconds
# clean up after the program is finished
except KeyboardInterrupt:
GPIO.cleanup()
Code example (PWM)
Pulse width modulation [PWM] can be used to regulate the brightness of an LED - in this process, the LED is switched on and off at specific time intervals, with the ratio of the switch-on and switch-off times corresponding to a relative brightness. Due to the inertia of human vision, human eyes interpret such on/off behavior as a change in brightness. More information on this topic can be found in this article by Analog IC Tips.
Several LEDs are integrated in this module - different colors can thus be created by superimposing different brightness levels. This is shown in the following code example.
# Required modules are imported and set up
import random, time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
# Here we declare the output pin to which the LEDs are connected.
LED_Red = 25
LED_Green = 24
LED_blue = 23
# Set pins to output mode
GPIO.setup(LED_Red, GPIO.OUT)
GPIO.setup(LED_Green, GPIO.OUT)
GPIO.setup(LED_Blue, GPIO.OUT)
Freq = 100 #Hz
# The respective colors are initialized.
RED = GPIO.PWM(LED_Red, Freq)
GREEN = GPIO.PWM(LED_Green, Freq)
BLUE = GPIO.PWM(LED_Blue, Freq)
RED.start(0)
GREEN.start(0)
BLUE.start(0)
# This function generates the actual color
# By means of the respective color variable, the color intensity can be changed
# After the color was set, by means of "time.sleep" the time is defined,
# how long the said color is to be indicated
def LED_Color(Red, Green,Blue, pause):
RED.ChangeDutyCycle(Red)
GREEN.ChangeDutyCycle(Green)
BLUE.ChangeDutyCycle(Blue)
time.sleep(pause)
RED.ChangeDutyCycle(0)
GREEN.ChangeDutyCycle(0)
print ("LED test [press CTRL+C to end test]")
# Main program loop:
# This has the task to create a separate variable for each color
# and by means of a for-loop to run through the color intensity of each single color from 0-100
# By the mixtures of the different brightness levels of the respective colors
# thus a color gradient is created
try:
while True:
for x in range(0,2):
for y in range(0,2):
for z in range(0,2):
print (x,y,z)
for i in range(0,101):
LED_Color((x*i),(y*i),(z*i),.02)
# Clean up after the program is finished
except KeyboardInterrupt:
GPIO.cleanup()
This LED module contains red, blue and green LEDs that are connected via a common cathode. The red LED has a forward voltage of 1.8 V, while the green and blue LEDs each require 2.8 V. All LEDs operate at a forward current of 20 mA. With this module, you can create different colors by adjusting the brightness of the individual LEDs. It is ideal for applications where visual signals or colored displays are required. The common cathode makes it easy to connect and integrate into various projects, whether for decorative lighting, status displays or other creative applications.
Technical Data | |
---|---|
Forward voltage [Red] | 1.8 V |
Forward voltage [Green, Blue] | 2.8 V |
Forward current | 20 mA |
Depending on the input voltage, series resistors are required.
Input voltage | Series resistor |
---|---|
3.3 V [Red] | 180 Ω |
3,3 V [Green] | 100 Ω |
3,3 V [Blue] | 100 Ω |
5 V [Red] | 180 Ω |
5 V [Green] | 100 Ω |
5V [Blue] | 100 Ω |
Pin assignment
Micro:Bit | Sensor |
---|---|
Pin 0 | LED Red |
Pin 1 | LED Green |
Pin 2 | LED Blue |
GND | GND |
Code example
This example turns on the LEDs depending on which button is pressed.
input.onButtonPressed(Button.A, function () {
pins.digitalWritePin(DigitalPin.P2, 1)
pins.digitalWritePin(DigitalPin.P0, 0)
pins.digitalWritePin(DigitalPin.P1, 0)
})
input.onButtonPressed(Button.AB, function () {
pins.digitalWritePin(DigitalPin.P1, 1)
pins.digitalWritePin(DigitalPin.P2, 0)
pins.digitalWritePin(DigitalPin.P0, 0)
})
input.onButtonPressed(Button.B, function () {
pins.digitalWritePin(DigitalPin.P0, 1)
pins.digitalWritePin(DigitalPin.P2, 0)
pins.digitalWritePin(DigitalPin.P1, 0)
})
Sample program download
This LED module contains red, blue and green LEDs that are connected via a common cathode. The red LED has a forward voltage of 1.8 V, while the green and blue LEDs each require 2.8 V. All LEDs operate at a forward current of 20 mA. With this module, you can create different colors by adjusting the brightness of the individual LEDs. It is ideal for applications where visual signals or colored displays are required. The common cathode makes it easy to connect and integrate into various projects, whether for decorative lighting, status displays or other creative applications.
Technical Data | |
---|---|
Forward voltage [Red] | 1.8 V |
Forward voltage [Green, Blue] | 2.8 V |
Forward current | 20 mA |
Depending on the input voltage, series resistors are required.
Input voltage | Series resistor |
---|---|
Red | 180 Ω |
Green | 100 Ω |
Blue | 100 Ω |
Pin assignment
Raspberry Pi Pico | Sensor |
---|---|
GPIO27 | LED Rot |
GPIO28 | LED Grün |
GPIO26 | LED Blau |
GND | GND |
1. Code example: ON/OFF
This code example shows how the integrated LEDs can be changed alternately, every 3 seconds, by means of a definable output pin.
To load the following code example onto your Pico, we recommend using the Thonny IDE. All you have to do first is go to Run > Configure interpreter ... > Interpreter > Which kind of interpreter should Thonny use for running your code? and select MicroPython (Raspberry Pi Pico).
Now copy the code below into your IDE and click on Run.
# Load libraries
from machine import Pin, PWM
from time import sleep
# Initialization of GPIO26, GPIO27 and GPIO28 as output
Green = Pin(28, Pin.OUT)
Red = Pin(27, Pin.OUT)
Blue = Pin(26, Pin.OUT)
while True:
# green light
Green.value(1)
Red.value(0)
Blue.value(0)
sleep(3)
# red light
Green.value(0)
Red.value(1)
Blue.value(0)
sleep(3)
# blue light
Green.value(0)
Red.value(0)
Blue.value(1)
sleep(3)
# Switch off LED
Green.value(0)
Red.value(0)
Blue.value(0)
sleep(3)
# yellow light
Green.value(1)
Red.value(1)
Blue.value(0)
sleep(3)
# turquoise light
Green.value(1)
Red.value(0)
Blue.value(1)
sleep(3)
# pink light
Green.value(0)
Red.value(1)
Blue.value(1)
sleep(3)
# Switch off LED
Green.value(0)
Red.value(0)
Blue.value(0)
sleep(3)
2. Code example: PWM
By means of pulse width modulation [PWM], the brightness of an LED can be regulated - in this process, the LED is switched on and off at specific time intervals, with the ratio of the switch-on and switch-off time corresponding to a relative brightness. Due to the inertia of human vision, human eyes interpret such on/off behavior as a change in brightness. More information on this topic can be found in this article from mikrokontroller.net.
Several LEDs are integrated in this module. By superimposing different brightness levels, different colors can be created. This is shown in the following code example.
To load the following code example onto your Pico, we recommend using the Thonny IDE. All you have to do first is go to Run > Configure interpreter ... > Interpreter > Which kind of interpreter should Thonny use for running your code? and select MicroPython (Raspberry Pi Pico).
Now copy the code below into your IDE and click on Run.
# Load libraries
import machine
import math
# Initialization of GPIO26, GPIO27 and GPIO28 as PWM pin
ledRed = machine.PWM(machine.Pin(27))
ledRed.freq(1000)
ledBlue = machine.PWM(machine.Pin(26))
ledBlue.freq(1000)
ledGreen = machine.PWM(machine.Pin(28))
ledGreen.freq(1000)
# Definition of a 3 digit list
RBG = [0,0,0]
# Function: Color space calculation for red, green and blue
# Green is 120° offset from red
# Blue is 240° offset from red
def sinColour(number):
a = (math.sin(math.radians(number))+1)*32768
b = (math.sin(math.radians(number+120))+1)*32768
c = (math.sin(math.radians(number+240))+1)*32768
RBG = (int(a),int(b),int(c))
return RBG
# Endless loop where the color value for all 3 colors is shifted again and again by 0.01
a = 0
while True:
RBG = sinColour(a)
a += 0.01
if a == 360:
a = 0
ledRed.duty_u16(RBG[0])
ledBlue.duty_u16(RBG[1])
ledGreen.duty_u16(RBG[2])