Example Code for micro:bit-IR-controlled Relay Switch

Last revision 2026/01/14

The article guides you through setting up a micro:bit V2 and MBT0042 expansion board to control a relay switch using infrared remote control. It covers hardware and software preparation, including entering the MakeCode programming platform and wiring diagrams, ultimately providing users with the skills to replicate the example code and achieve the desired results.

Hardware Preparation

micro:bit V2, MBT0042 expansion board, mini-infrared remote control, Quantity: 1 each.

Software Preparation

  1. Enter the MakeCode programming platform in browser: https://makecode.microbit.org/
  2. Create a new project and name it.
  3. Load in the program library of xia_mi board: click “setting”, and “expansion” in turn, then paste this link in the search box: https://github.com/DFRobot/pxt-DFRobot_xia_mi_Board.

Other Preparation Work

Infrared remote control and corresponding key value:

IR Remote Controller

Sample Code

MakeCode Program Link: https://makecode.microbit.org/_FEt27cb1qLar

IR

Was this article helpful?

TOP