Example Code for micro:bit-Music Mirror

Last revision 2026/01/14

This article offers a detailed guide on integrating micro:bit with HuskyLens for a music mirror project, explaining hardware setup, software configuration, and coding to enable face recognition and musical responses.

Hardware Preparation

  • HuskyLens: 1
  • micro:bit: 1
  • IO Extender for micro:bit v20: 1

Software Preparation

Search https://github.com/DFRobot/pxt-DFRobot_HuskyLens or "HusktLens", then click on the search button, you will see the HuskyLens plugin, and then click to add it.
search

Wiring Diagram

HuskyLens needs to be connected to the specific interface. The HuskyLens interface uses a 5V voltage supply to ensure stable operation, as shown in the figure:

interface

Other Preparation Work

  1. Ports and Buttons
    ports and buttons
    2.The communication interface between HuskyLens and micro:bit is I2C interface. How to set the HuskyLens communication mode to I2C? First dial the function button to find the general settings, then long press the function button to enter the secondary menu of general settings. Dial the function button to find Protocol type and press the function button to enter the protocol type menu. Find I2C, click the function button to select, and then choose "Save and Return". Then HuskyLens is set I2C communication mode.

general settings

Sample Code

As shown below:

screenshot

Program Link:
https://makecode.microbit.org/_T8EgAK60AEat

Result

HuskyLens will play "ode" and display a smile face on the micro:bit when recognizing the learned face, while play "funk" and display a crying face when the face is unlearned.

Additional Information

  1. Dial the “function button” to the left until “face recognition” is displayed at the top of the screen.

    demo1

  2. Point HUSKYLENS at the area with faces on it. When a face is detected, it will be automatically selected by a white frame with words "Face" on the screen.

    Demo2

  3. Point the “+” symbol at a face, short press the "learning button" to learn the face. If the same face is detected by HuskyLens, a blue frame with words "Face: ID1" will be displayed on the screen,which indicates that HuskyLens has learned the face before and can recognize it now.

demo3

Was this article helpful?

TOP