Example Code for micro:bit-Face Recognition(MakeCode)

Last revision 2026/01/20

This article explains how to connect HuskyLens to the micro: bit board for face recognition using MakeCode, detailing the hardware and software setup, wiring instructions, and sample code to ensure a successful implementation where the micro: bit displays a smiling or crying face based on recognition results.

This chapter demonstrates how to connect HuskyLens to the micro: bit board, then the micro: bit board reads the face recognition results from HuskyLens. If HuskyLens recognizes you (the learned face), the dot-matrix screen of the micro: bit displays a smiling face, otherwise it displays a crying face.

The communication protocol between HuskyLens and micro: bit is I2C.

Hardware Preparation

Wiring Diagram

The following picture is only for reference when wiring. The R and T pins of HuskyLens (their functions are SCL and SDA here) are connected to the SCL (P19) and SDA (P20) pins of the micro: bit respectively. The communication protocol between HuskyLens and micro: bit is I2C.

A micro: bit expansion board is recommended for simplify wiring.

Huskylens_Wiring_Diagarm_Microbit

HuskyLens consumes heavy current, up to 3.3V 320mA or more. The mciro: bit board is not enough to supply power. Therefore, external power supply is required. You can connect the external power supply to the external power connector of the micro: bit expansion board, or the HuskyLens USB connector.*

Software Preparation

Load HuskyLens Extension

  1. Create a new project in MakeCode web version, and then click the "More..." button (gear icon) at the top right and select "Extensions" from its drop-down menu to open the extension page.

    Makecode_Load_Extensions

  2. Enter huskylens in the search bar, then click the search button (the magnifying glass button on the right of the search bar) , you will see the HuskyLens extensions. Then click it to load the HuskyLens extension into the MakeCode.

    Makecode_Search_Extensions

  3. In the programming page, you can see the Huskylens module.

    MakeCode_With_HuskyLensExtension

HuskyLens Protocol Setting

You need to set the protocol type of HuskyLens. The protocol should be I2C. Of course, your can adopt the auto detect protocol, which is easy-to-use and convenient.

HuskyLens_Protocol_Setting_I2C

Sample Code

Makecode_Face_Recognition_Sample_Code

Result

  1. Upload the above codes to the micro: bit board.

  2. Refer to the previous chapter which explaining the face recognition function(chapter 7.1), let your HuskyLens learn a face, such as your face.

  3. When HuskyLens recognizes your face, the dot-matrix screen on the micro: bit board will show a smiling face. If it were not your face, or no face appeared, it would display a crying face.

Was this article helpful?

TOP