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

Technical data

Vf [typ] 2.0V-2.5V
If 20mA

The designations (Vf and If) refer to the forward voltage and forward current of the light emitting diode.

series resistors:

Depending on the input voltage, series resistors are required.

The designation (Rf) here refers to the required series resistor in front of the light emitting diode based on the applied voltage.

Rf (3.3V) [Red] 120Ω
Rf (3,3V) [Green] 120Ω

[e.g. when used with ARM CPU core based microcontrollers like Raspberry-Pi]

Rf (5V) [Red] 220Ω
Rf (5V) [Green] 220Ω

[e.g. when used with Atmel Atmega based microcontrollers like Arduino]

Pin assignment

Code example Arduino

Pin assignment Arduino

Arduino Sensor
Pin 10 LED GREEN
Pin 11 LED RED
Ground 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.

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

Example program ON/OFF Download:

KY011-Arduino-ON-OFF.zip

Code example PWM

By means of pulse-width modulation [PWM], the brightness of an LED can be regulated - in doing so, the LED is switched on and off in certain time intervals, where the ratio of the switch-on and switch-off time corresponds to a relative brightness - due to the inertia of human vision, the human eyes interpret such a switch-on/switch-off behavior as a change in brightness. More information on this topic can be found in this article from mikrokontroller.net.

There are several LEDs integrated in this module - so by superimposing different brightness levels, different colors can be created. This is shown in the following code example.

int Led_Red = 10;
int Led_Green = 11;
 
int val;
 
void setup () {
  // Initialize output pins for the LEDs
  pinMode (Led_Red, OUTPUT); 
  pinMode (Led_Green, OUTPUT); 
}
void loop () {
   // Within a For loop, different PWM values are passed to the two 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_Green, val);
      analogWrite (Led_Red, 255-val);
      delay (15);
   }
   // In the second For loop the color gradient is scrolled backwards
   for (val = 0; val <255; val++)
      {
      analogWrite (Led_Green, val);
      analogWrite (Led_Red, 255-val);
      delay (15);
   }
}

Sample PWM program download

KY011-Arduino-PWM.zip

Code example Raspberry Pi

Pin assignment Raspberry Pi

Raspberry Pi Sensor
GPIO 23 [Pin 16] LED GREEN
GPIO 24 [Pin 18] LED RED
Ground [Pin 6] 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.

# 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 = 24
LED_GRUEN = 23
GPIO.setup(LED_ROT, GPIO.OUT, initial= GPIO.LOW)
GPIO.setup(LED_GRUEN, GPIO.OUT, initial= GPIO.LOW)
   
print "LED test [press CTRL+C to end 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
            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
            time.sleep(3) #wait mode for another two seconds during which the LED is off then
   
# clean up after the program has been terminated
except KeyboardInterrupt:
        GPIO.cleanup()

Example program ON/OFF download

KY011-RPi-ON-OFF.zip

To start with the command:

sudo python3 KY009.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 certain time intervals, where the ratio of the switch-on and switch-off time corresponds to a relative brightness - due to the inertia of human vision, human eyes interpret such switch-on/switch-off behavior as a change in brightness. More information on this topic can be found in this article from mikrokontroller.net.

There are several LEDs integrated in this module - so by superimposing different brightness levels, different colors can be created. This is shown in the following code example. In the Raspberry Pi there is only one hardware PWM channel unrestricted to the GPIO pins, so in this example we use software PWM.

# 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 = 24
LED_Green = 23
  
# Set pins to output mode
GPIO.setup(LED_Red, GPIO.OUT) 
GPIO.setup(LED_Green, GPIO.OUT)
  
Freq = 100 #Hz
  
# The respective colors are initialized.
RED = GPIO.PWM(LED_Red, Freq) 
GREEN = GPIO.PWM(LED_Green, Freq)
RED.start(0)  
GRUEN.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, pause):
    RED.ChangeDutyCycle(Red)
    GREEN.ChangeDutyCycle(Green)
    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 single 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):
                print (x,y)
                for i in range(0,101):
                    LED_Color((x*i),(y*i),.02)
  
# clean up after the program is finished
except KeyboardInterrupt:
        GPIO.cleanup()

Example program download

KY011-RPi-PWM.zip

To start with the command:

sudo python3 KY009-PWM.py

Code example Micro:Bit

Pinout Micro:Bit:

Micro:Bit Sensor
Pin 1 LED GREEN
Pin 2 LED RED
Ground GND

This is a MakeCode example for Micro:Bit which essentially does the same as the examples of the other two variants. However, this example is closer to the Raspberry Pi example than the Arduino example.

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

Sample program download

microbit-KY-011.zip