In this article, we connect an KY-009 RGB LED to a Raspberry Pi Pico, any Rp2040 type board will be suitable. We actually tested this with a Cytron Maker Pi Pico
The KY-009 RGB LED module can emit red and green light. You can adjust the intensity of each color using a Pico PWM pin or simply switch the LED on/off using standard GPIO.
We will use Micropython for these examples but of course you can use the Arduino IDE as well if you have Raspberry Pi Pico support enabled
The sensor looks like this
Operating Voltage | 5V max Red 1.8V ~2.4V Green 2.8V ~ 3.6V Blue 2.8V ~ 3.6V |
Forward Current | 20mA ~ 30mA |
Operating Temperature | -25°C to 85°C [-13°F ~ 185°F] |
Board Diemsions | 18.5mm x 15mm [0.728in x 0.591in] |
Series resistors are recommended, about 120 ohms should be just fine.
Series resistor (3.3 V) [Red] | 180 Ω |
Series resistor (3,3 V) [Green] | 100 Ω |
Series resistor (3,3 V) [Blue] | 100 Ω |
Parts Required
You can connect to the module using dupont style jumper wire.
Name | Link | |
Raspberry Pi Pico | ||
37 in one sensor kit | ||
Connecting cables |
Schematic/Connection
Pico | SENSOR |
---|---|
GPIO0 | R |
GPIO1 | G |
GPIO2 | B |
GND | – |
Code Examples
Basic example in thonny
from machine import Pin, PWM from time import sleep # Initialization of GPIO0, GPIO1 and GPIO2 as outputs Red = Pin(0, Pin.OUT) Green = Pin(1, Pin.OUT) Blue = Pin(2, Pin.OUT) # individual LED colors def singleLeds(): Red.value(1) Green.value(0) Blue.value(0) sleep(3) Red.value(0) Green.value(1) Blue.value(0) sleep(3) Red.value(0) Green.value(0) Blue.value(1) sleep(3) Red.value(0) Green.value(0) Blue.value(0) # mix the leds to make new colors. def multiLeds(): 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: singleLeds() sleep(3) multiLeds()
pwm example
REPL Output
N/A
Links
https://github.com/getelectronics/rp2040learning/tree/main/Sensor%20Kit/KY-009_SMD_RGB