Microbit and KY-010 light barrier module
In this article, we connect a KY-010 light barrier module to our Microbit – we will use Makecode and show the JavaScript and Python output as well
The KY-010 light barrier module / photo interrupter module is a 3-pin module that brings its signal pin HIGH when an object blocks light from traveling between its emitter and sensor.
Parts Required
Name | Link | |
Microbit |
|
|
37 in one sensor kit | ||
Connecting cables |
Schematic/Connection
MICRO:BIT | SENSOR |
---|---|
0 | Signal |
3,3 V | +V |
GND | GND |
Example
All of these are from the Microsoft Makecode site
MakeCode
Python
pins.set_pull(DigitalPin.P0, PinPullMode.PULL_UP) def on_forever(): if pins.digital_read_pin(DigitalPin.P0) == 1: basic.show_icon(IconNames.NO) else: basic.show_icon(IconNames.YES) basic.pause(1000) basic.forever(on_forever)
JavaScript
pins.setPull(DigitalPin.P0, PinPullMode.PullUp) basic.forever(function on_forever() { if (pins.digitalReadPin(DigitalPin.P0) == 1) { basic.showIcon(IconNames.No) } else { basic.showIcon(IconNames.Yes) } basic.pause(1000) })