Example Code for micro:bit-MakeCode Programming

On the micro:bit development board, program with graphical building blocks to enable the sensor to detect the presence of a face, recognize gesture types, and display the results on the device, which is suitable for fun interactive projects with micro:bit.

Hardware Preparation

Software Preparation

Other Preparation Work

  • Open the Programming Platform: Enter the MakeCode official website in the browser, click "New Project" and name it (e.g., "Face and Gesture Detection").
  • Load the Sensor Library:
    • Click "Settings" in the upper right corner → "Extensions", paste the link in the search box: https://github.com/DFRobot/pxt-DFRobotGestureFaceDetection, and load the extension library.
  • Graphical Programming: Drag modules from the left building block area (such as "Get Number of Faces", "Get Face X Coordinate") to form a program (refer to the example diagram).

Sample Code

Result

  • Click "Download" to save the program to the computer and transfer it to the micro:bit development board;
  • Connect the sensor to the micro:bit, open the "Show data" window, and you can see the real-time detection results (such as "Number of faces: 1", "Gesture: 2 (OK gesture)").

Other Supplementary Information

  • In the Mind+ and MakeCode graphical programming environments, the sensor only supports the I2C communication mode and does not support the UART mode for the time being. Please switch the sensor's communication mode switch to the I2C side to ensure proper use.
  • For supported gestures and corresponding information, refer to the "Detailed Explanation of Core Functions" section above in the Wiki.
  • If no data is output, check whether the device connection is secure and whether the extension library is added correctly.

Was this article helpful?

TOP