• Arduino
  • Raspberry Pi
  • Raspberry Pi Pico
  • Micro:Bit

LED module which contains a red, blue and green LED. These are connected to each other by means of a common cathode.

Technical data

Forward voltage [Red] 1.8 V
Forward voltage [Green, Blue] 2.8 V
Forward current 20 mA

Series resistors:

Depending on the input voltage, series resistors are required.

Series resistor (3.3 V) [Red] 180 Ω
Series resistor (3,3 V) [Green] 100 Ω
Series resistor (3,3 V) [Blue] 100 Ω
Series resistor (5 V) [Red] 180 Ω
Series resistor (5 V) [Green] 100 Ω
Series resistor (5V) [Blue] 100 Ω

Pin assignment

Code example Arduino

Pin assignment Arduino

Arduino Sensor
Pin 10 LED Red
Pin 11 LED Green
Pin 12 LED Blue
GND GND

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;
int Led_Green = 11;
int Led_Blue = 12;
  
void setup ()
{
  // Initialize output pins for the LEDs
  pinMode (Led_Red, OUTPUT); 
  pinMode (Led_Green, OUTPUT);
  pinMode (Led_Blue, OUTPUT); 
}
  
void loop () //Main program loop
{
  digitalWrite (Led_Red, HIGH); // LED is switched on
  digitalWrite (Led_Green, LOW); // LED is switched on
  digitalWrite (Led_Blue, LOW); // LED is switched on
  delay (3000); // Wait mode for 3 seconds
  
  digitalWrite (Led_Red, LOW); // LED is switched on
  digitalWrite (Led_Green, HIGH); // LED is switched on
  digitalWrite (Led_Blue, LOW); // LED is switched on
  delay (3000); // Waiting mode for another three seconds in which the LEDs are then switched over
   
  digitalWrite (Led_Red, LOW); // LED is switched on
  digitalWrite (Led_Green, LOW); // LED is switched on
  digitalWrite (Led_Blue, HIGH); // LED is switched on
  delay (3000); // Wait mode for another three seconds in which the LEDs are then switched over
}

Example program ON/OFF Download:

KY016-Arduino-ON-OFF.zip

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.

int Led_Red = 10;
int Led_Green = 11;
int Led_Blue = 12;
 
int val;
 
void setup () {
  // Initialize output pins for the LEDs
  pinMode (Led_Red, OUTPUT); 
  pinMode (Led_Green, OUTPUT); 
  pinMode (Led_Blue, OUTPUT); 
}
void loop () {
   // Within a For loop, different PWM values are passed to the three LEDs.
   // This creates a color gradient in which the mixing of different 
   // brightness levels of the two integrated LEDs, different colors are created
   for (val = 255; val> 0; val--)
      {
       analogWrite (Led_Blue, val);
       analogWrite (Led_Green, 255-val);
       analogWrite (Led_Red, 128-val);
       delay (1);
   }
   // In the second for-loop the color gradient will be processed backwards
   for (val = 0; val <255; val++)
      {
      analogWrite (Led_Blue, val);
      analogWrite (Led_Green, 255-val);
      analogWrite (Led_Red, 128-val);
      delay (1);
   }
}

Sample program download

KY016-Arduino-PWM.zip

LED module which contains a red, blue and green LED. These are connected to each other by means of a common cathode.

Technical data

Forward voltage [Red] 1.8 V
Forward voltage [Green, Blue] 2.8 V
Forward current 20 mA

Series resistors:

Depending on the input voltage, series resistors are required.

Series resistor (3.3 V) [Red] 180 Ω
Series resistor (3,3 V) [Green] 100 Ω
Series resistor (3,3 V) [Blue] 100 Ω
Series resistor (5 V) [Red] 180 Ω
Series resistor (5 V) [Green] 100 Ω
Series resistor (5 V) [Blue] 100 Ω

Pin assignment

Code example Raspberry Pi

Pin assignment Raspberry Pi

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()

Example program ON/OFF download

KY016-RPi-ON-OFF.zip

To start with the command:

sudo python KY016-RPi.py

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()

Example program download

KY016-RPi-PWM.zip

To start with the command:

sudo python3 KY016-PWM.py

LED module which contains a red, blue and green LED. These are connected to each other by means of a common cathode.

Technical data

Forward voltage [Red] 1.8 V
Forward voltage [Green, Blue] 2.8 V
Forward current 20 mA

Series resistors:

Depending on the input voltage, series resistors are required.

Series resistor (3.3 V) [Red] 180 Ω
Series resistor (3,3 V) [Green] 100 Ω
Series resistor (3,3 V) [Blue] 100 Ω
Series resistor (5 V) [Red] 180 Ω
Series resistor (5 V) [Green] 100 Ω
Series resistor (5 V) [Blue] 100 Ω

Pin assignment

Code example Micro:Bit

Pinout Micro:Bit:

Micro:Bit Sensor
Pin 0 LED Red
Pin 1 LED Green
Pin 2 LED Blue
GND GND

This example turns on the LEDs depending on which button is pressed.

Sample program download

microbit-KY-016.zip

LED module which contains a red, blue and green LED. These are connected to each other by means of a common cathode.

Technical data

Forward voltage [Red] 1.8 V
Forward voltage [Green, Blue] 2.8 V
Forward current 20 mA

Series resistors:

Depending on the input voltage, series resistors are required.

Series resistor (3.3 V) [Red] 180 Ω
Series resistor (3,3 V) [Green] 100 Ω
Series resistor (3,3 V) [Blue] 100 Ω
Series resistor (5 V) [Red] 180 Ω
Series resistor (5 V) [Green] 100 Ω
Series resistor (5V) [Blue] 100 Ω

Pin assignment

Code example Raspberry Pi Pico

Pin assignment Raspberry Pi Pico

Raspberry Pi Pico Sensor
GPIO27 LED Rot
GPIO28 LED Grün
GPIO26 LED Blau
GND GND

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.

# 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)

# Function: The individual available colors of the LED are switched on and off one after the other
def solo():
    Green.value(1)
    Red.value(0)
    Blue.value(0)
    sleep(3)
    Green.value(0)
    Red.value(1)
    Blue.value(0)
    sleep(3)
    Green.value(0)
    Red.value(0)
    Blue.value(1)
    sleep(3)
    Green.value(0)
    Red.value(0)
    Blue.value(0)

# Function: The individual available colors of the LED are switched simultaneously one after the other to create mixed colors.
def mix():
    Green.value(1)
    Red.value(1)
    Blue.value(0)
    sleep(3)
    Green.value(1)
    Red.value(0)
    Blue.value(1)
    sleep(3)
    Green.value(0)
    Red.value(1)
    Blue.value(1)
    sleep(3)
    Green.value(0)
    Red.value(0)
    Blue.value(0)
    
while True:
    solo()
    sleep(3)
    mix()

Example program ON/OFF Download:

KY016-Pico-ON-OFF.zip

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.

# 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])

Example program PWM download

KY016-Pico-PWM.zip