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
- SEN0305 HuskyLens K210 AI Machine Vision Sensor x1
- MBT0039 micro:bit Board x1
- DFR0518 micro:bit expansion board x1
- FIT0773 Gravity: 4Pin I2C/UART Sensor Cable for Arduino(Included with SEN0305) x1
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 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
-
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.

-
Enter
huskylensin 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.
-
In the programming page, you can see the Huskylens module.

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.

Sample Code

Result
-
Upload the above codes to the micro: bit board.
-
Refer to the previous chapter which explaining the face recognition function(chapter 7.1), let your HuskyLens learn a face, such as your face.
-
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?
