Lesson 2 - AI Exploration: Face Detection
Students learn how to detect human faces and program the micro:bit to show a pattern when it detects a human face.
I can explain what face detection is.
I can summarize what makes face detection easier.
I can write pseudocode to plan my program.
1. Engage: What Is a Smart Gate?
We need a smarter way to run the farm: a gate that knows when someone is coming—no button needed. The technology behind it is called face detection.
Key Question
What is face detection?

Definition: Face detection is a computer vision technique that enables a program to detect human faces and locate them within images or video streams.
Let’s make a smart gate bell with face detection!
2. Explore: How Does the Camera "See" a Person?
First, make the hardware connection:

Once the hardware is connected, press the mode button to switch the AI camera to “face detection” mode. The topright LED shows which mode the camera is currently in, while the bottomright LED lights up to indicate whether a face has been detected.

Activity 1
• Build and install the hardware following the Building Instruction.

• Test and complete the table:
| Action | Does it work? |
| In a dark classroom. In a light classroom. | |
| Show the side face. Show the straight face. | |
| Stand one arm's length away from the camera. Stand 3 meters away from the camera. | |
| Cover your eyes. Cover your mouth. | |
| Using a photo of a face. |
Key Question
What conditions make face detection easy? What makes it hard?
Lighting
Orientation of face
Scale of face
Occlusion
3. Engineer: Build the Face-Detecting Bell
Part 1: Plan the Algorithm
Key Question
What should our smart bell do?
Let's describe how this algorithm should work.

This is our program's pseudocode, which is the important part of our program.
Part 2: Rebuild the Code
Go to MakeCode and add the required Extensions.
![]() | Click Extensions |
![]() | Type boson and search |
![]() | Click the extension and go back to the coding page |
Rebuild the code.

Download the program and check the effect.
Walk in front of the camera → The “√” should show.
Walk away → The “×” should show.
4. Experience & Challenge: Build Your Smart Gate
Experience: choose your favorite bell music
Activity 2
• Guide students to explore the Music category to make the smart gate ring when it sees a face.

• Students can choose their favorite Music block or combine them to customize their program.
Challenge: Improve your smart bell
Run your program, and what do you notice?
Key Question
What will happen if you keep standing in front of the camera?
If you keep showing your face to the camera, the music loops rapidly, which is noisy and annoying.
Activity 3
• Challenge students to add the pause (ms) block in the program to wait a moment after the bell rings.
• Change the pause time to 1 second and 5 seconds. What is the difference?

5. See also: How does AI learn to detect?
Key Question
How does AI learn to detect faces?
It wasn't born with that ability. It had to learn—just like you learn to recognize things!
How does it work?
Step 1: Look at lots of pictures.
The AI was shown millions of pictures—some with faces, some without.
Step 2: Find the patterns
Over time, it discovered that face pictures always share something in common—like two dark spots on top (eyes), a line in the middle (nose), and another line below (mouth).
Step 3: Practice and fix mistakes
Every time it made a wrong guess, it adjusted itself—a little bit at a time—until it got better and better.
This is called Machine Learning. AI doesn't learn from a manual. It learns from data—lots and lots of it!












