Home CodeSensor Kits Microbit and KY-029 Dual Color LED

Microbit and KY-029 Dual Color LED

by shedboy71

In this article, we connect a KY-029 Dual Color LED to our Microbit – we will use Makecode and show the JaavScript and Python output as well

The KY-029 Dual Color LED module can emit red and green light. Its basically a smaller size but similar function to the Ky-011

Operating Voltage 2.3-2.6V for green, 1.9-2.2V for red
Working Current 20mA
Color Red + Green
Wavelength 571nm + 625nm
Luminous Intensity 20~40mcd,  60~80mcd

Depending on the input voltage, series resistors are recommended.

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

Parts Required

Name Link
Microbit
37 in one sensor kit
Connecting cables

 

Schematic/Connection

Microbit SENSOR
Pin 2 LED Red
Pin 1 LED Green
GND GND

Example

All of these are from the Microsoft Makecode site

MakeCode

Python

def on_button_pressed_a():
    pins.digital_write_pin(DigitalPin.P1, 1)
    pins.digital_write_pin(DigitalPin.P2, 0)
input.on_button_pressed(Button.A, on_button_pressed_a)

def on_button_pressed_b():
    pins.digital_write_pin(DigitalPin.P1, 0)
    pins.digital_write_pin(DigitalPin.P2, 1)
input.on_button_pressed(Button.B, on_button_pressed_b)

 

JavaScript

input.onButtonPressed(Button.A, function () {
    pins.digitalWritePin(DigitalPin.P1, 1)
    pins.digitalWritePin(DigitalPin.P2, 0)
})
input.onButtonPressed(Button.B, function () {
    pins.digitalWritePin(DigitalPin.P1, 0)
    pins.digitalWritePin(DigitalPin.P2, 1)
})

 

Output

Press the A button then the B button on the microbit

As an exercise can you add the ability if button A and B are both pressed the red and green are both switched off

Links

https://github.com/getelectronics/Microbitlearning/tree/master/37%20Sensor%20Kit/KY-029%202%20Color%20LED

 

 

You may also like

Leave a Comment