Microbit and KY-011 Dual Color LED

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

The KY-011 Dual Color LED module can emit red and green light. You can adjust the intensity of each color using an Arduino PWM pin or simply switch the LED on/off.

Operating Voltage 2.0v ~ 2.5v
Working Current 10mA
Color Red + Green
Beam Angle 150
Wavelength 571nm + 644nm
Luminosity Intensity (MCD) 20-40; 40-80

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-011%202%20Color%20LED

 

 

Leave a Comment

This div height required for enabling the sticky sidebar
Ad Clicks : Ad Views : Ad Clicks : Ad Views :