MakeCode Example: Controlling the Micro:bit LED Matrix

Last revision 2025/12/30

The article illustrates how to use MakeCode to control the Micro:bit LED matrix with a voice recognition module, providing step-by-step instructions for setup, coding, and displaying patterns like smiley faces, sad faces, and hearts on the LED matrix through voice commands.

Introduction to MakeCode

MakeCode is a free and open-source platform designed to create an engaging learning experience for computer science, as well as lay the foundation for actual programming. The web version allows for online programming and firmware downloads. Click here to access the MakeCode web version specifically designed for micro:bit.

Loading the voice recognition plugin on MakeCode

  1. To create a new project in MakeCode web version, click on the "more" button (gear icon) in the top right corner. From the drop-down menu, select "Extensions" to open the extension interface.

  2. Type "https://github.com/DFRobot/pxt-DFRobot_voiceRecognition.git " in the search bar and click on the magnifying glass icon to search. You will see the voiceRecognition plugin (as shown in the image below). Click on it to load the plugin into your project.

    MakeCode插件搜索
  3. In the programming interface, you will see the Voice Recognition (SEN0539) module. Clicking on it will bring up the command blocks.

Controlling the Micro:bit LED Matrix

This example shows how to connect the Voice Recognition module to the Micro:bit board, and then read speech recognition results from the Voice Recognition module. The Micro:bit controls the LED matrix to display smiley faces, sad faces, and hearts.The communication interface between the Voice Recognition (SEN0539) and the Micro:bit uses the I2C interface.

Materials Needed

Hardware wiring diagram

Properly connect the micro:bit motherboard and IO expansion board, and set the communication mode selection switch of the voice recognition module to I2C end according to the diagram below, then connect it to the expansion board.

Sample code

Expected result

To wake up the voice recognition module, say either the fixed wake-up word or the learned wake-up word. To display a smiley face on the LED matrix of the micro:bit, say "Display smiley face". To display a sad face on the micro:bit, say "Display crying face". To display a heart on the micro:bit, say "Display heart". To turn off all LED matrix displays on the micro:bit, say "Turn off dot matrix".

MakeCode module description

Module Explanation
Initialization. It only needs to be executed once and should be placed at the beginning of the main program. The communication mode selection switch for the speech recognition module needs to be set to I2C end.
Adjust the volume of the module. The range of the volume is from 0 to 7, with a larger number representing a higher volume.
Enable or disable the mute mode of the module.
Configure the time in seconds for the module to return to sleep mode after awakening. This time will be refreshed after each successful command recognition.
Retrieve the duration in seconds for the module to return to sleep mode after awakening.
Play the corresponding response for the recognized command word.
Select the Wake-up Word ID.
Retrieve the recognition result from the speech recognition and save it to the recognition result module.
Determine if the speech recognition has recognized the command.
Select the ID of the command word to be learned.
Select a fixed command word ID.
Select the ID of the word to be learned.

Was this article helpful?

TOP