UNIHIKER K10 Lesson 8: Create an AI-Powered Campus Gatekeeper with Facial Recognition
Explore this AI Campus Gatekeeper where students build a facial recognition gatekeeper using UNIHIKER K10! Designed to align with CSTA, NGSS, and UK computing standards, this project teaches machine learning fundamentals, ethical AI, and hardware integration—perfect for middle school to high school STEM classes. Includes step-by-step coding (Mind+), hands-on activities, and discussions on real-world AI applications in security systems.

Objectives
Design an AI campus gatekeeper using the face detection feature of the UNIHIKER K10, capable of recognizing different campus visitors’ identities and providing appropriate responses.

Knowledge Goals
1. Understand the basic principles of facial recognition technology.
2. Master the methods of learning, recognizing, and forgetting faces with the UNIHIKER K10.
3. Master the programming required to implement facial recognition using the UNIHIKER K10.
Materials List
Hardware List:

Software: Mind+ Graphical Programming Software (Minimum Version Requirement: V1.8.1 RC1.0)

Basic Mind+ Software Usage
1. Open Mind+ and switch to offline mode.

2. Load UNIHIKER K10
Based on the previous steps, then click on "Extensions" find the "UNIHIKER K10" module under the "Board" and click to add it. After clicking "Back" you can find the UNIHIKER K10 in the "Command Area" and complete the loading of UNIHIKER K10.

3. Connect UNIHIKER K10
First of all, you need to use a USB cable to connect the UNIHIKER K10 to the computer.

Then, after clicking Connect Device, click COM7-UNIHIKER K10 to connect.

Note: The device name of different UNIHIKER K10 may vary, but all end with K10.
On Windows 10/11, the UNIHIKER K10 is driver-free. However, for Windows 7, manual driver installation is required: https://www.unihiker.com/wiki/K10/faq/#high-frequency-problem
Hands-on practice
Let’s get started with today’s lesson tasks. We will begin with face learning and gradually master how to recognize different faces on the UNIHIKER K10 and provide corresponding feedback based on the identity of the individuals.
Task 1: Learn Faces
In this part, we will use the camera to learn different faces and obtain face IDs, simulating the process of registering faces for the AI gatekeeper.
Task 2: Recognize Faces
Here, we will recognize faces that appear in front of the camera, compare them with the previously learned faces, and provide corresponding feedback, simulating the recognition process of the AI gatekeeper.
Task 3: Forget Faces
In this task, we will learn how to forget previously learned faces, simulating the process of updating the face database for the AI gatekeeper.
Task 1: Learn Faces
1. Hardware Setup
Confirm that the UNIHIKER K10 is connected to the computer via a USB cable, and a servo is connected to the P0 pin to simulate the access control gate.

2. Software Preparation
Make sure that Mind+ is open, the preset code appears in Python graphical mode, and the UNIHIKER K10 is successfully loaded. You can now start writing the project program.

3. Write the program
STEP1: Call the Face Detection Command
First, we need to use the "enable camera show" command to show the camera feed on the UNIHIKER K10 screen.

After turning on the camera, we locate the "switch mode face detection" command to switch the camera to face detection mode.

STEP2: Learn Faces
We need to use a variable called "learn face" to indicate whether face learning is to be performed. The initial value is 0. When the value is 1, it indicates that face learning should take place. When the value is 0 and a face is detected, it means face recognition will occur. The flow of this process is shown in the flowchart below.

The UNIHIKER K10 has already provided us with a pre-packaged block for the "learn face" command, located under the AI module. Simply drag it into the script area to enable face learning.

To control the "learn face" variable, we use an event callback function. When button A is pressed, the value of the "learn face" variable is set to 1, initiating the face learning process, and the white light is turned on. After waiting for 2 seconds, the learning is complete, the variable is reset to 0, the light is turned off, and a message “Face learning complet” is displayed. This way, we have completed the conditional check for whether face learning should occur. The function for recognizing faces will be covered in the next part of the tutorial.

4. Program Execution
STEP1: Check and ensure the UNIHIKER K10 is connected to Mind+. Make sure the IP address is displayed in the “Menu Bar” section, indicating that the connection is established.

STEP2: Click the “Upload” button in the upper-right corner of the interface.

STEP3: Program Execution. The camera feed will appear, and when button A is pressed, the RGB light will turn yellow to indicate that face learning is in progress. After two seconds, the light will turn off, and a message will be displayed to indicate that face learning is complete.

Task 2: Recognize Faces
In the previous task, we completed the conditions for learning and recognizing faces. Now, in this task, we will implement the "Face Recognition" function, which involves recognizing faces and providing corresponding feedback based on the recognition result.
1. Write the program
STEP1: Recognize Faces
The UNIHIKER K10 provides a "recognize face" command. We will use this command to perform face recognition. After the recognition is complete, we will use the "recognized face id" command to store the recognized face ID in a variable called “ID”. We will also display the recognized face ID on the UNIHIKER K10’s screen.

Note: For more details on the recognize face command, please refer to the Knowledge Hub.
STEP2: Set Feedback Actions
When recognizing a face, if the face has not been learned, the RGB light will turn red, and the message “Sorry, you do not have access” will be displayed. The UNIHIKER K10 screen will show the face ID as -1, and the simulated servo will remain closed. After 2 seconds, the RGB light will turn off.
If the recognized face has been learned, the RGB light will turn green, and the message “Dear student, welcome back to school” will be displayed. The UNIHIKER K10 screen will show the face ID as 1. The simulated servo will first rise, and then close after 2 seconds. The RGB light will then turn off after 2 seconds.

STEP3: Distinguish Role-based Greetings
In a school, in addition to students, there are also teachers, principals, and other roles. The greeting after face recognition should be different depending on the role. Therefore, we set different greetings for each role. The recognized face ID will be used for distinction:
• ID 1: Student
• ID 2: Teacher
• ID 3: Principal
The corresponding greeting sentences are as follows:

To set different greetings for different roles based on the face ID, we can use conditional statements. The program setup would look like this:

2. Program Execution
STEP1: Connect the UNIHIKER K10.
STEP2: Click the “Upload” button in the upper-right corner of the interface.
STEP3:
• If the recognized face is not learned, turn on the red light, display the warning message, and keep the gate closed.
• If the recognized face is learned, turn on the green light, display the welcome message, and open the gate.

Task 3: Forget Faces
1. Write the Program
We will use an event callback function to complete the “Forget Face” event. When the B button is pressed, the program will use the command Forget All Face IDs to forget all the learned faces. The blue indicator light will turn on to show the action. After 1 second, the light will turn off. The related program instructions would be:

2. Program Execution
Click Upload, press the B key to turn on the blue light for 1 second, then turn it off. Afterward, test with a previously learned face, and the face ID will show as -1, indicating that the learned face has been successfully forgotten.

The complete program for the AI campus gatekeeper is shown in the following image.

Knowledge Hub
1. What is face recognition
Face recognition is a biometric technology used for identifying individuals based on their facial features. It involves capturing images or video streams containing faces through a camera or webcam, automatically detecting and tracking the faces within the image, and then recognizing the detected faces through a series of related technologies. It is often referred to as face detection or facial recognition.
In simple terms, face recognition is the process of identifying the person behind a face image. It addresses the question of “whose face is this?”
Face recognition typically involves the following four steps:
(1) Face detection: The process of locating the face within an image (i.e., determining if it’s a face).
(2) Face preprocessing: Enhancing the image of the face to make it clearer.
(3) Collecting and learning faces: Capturing and preprocessing the detected faces, then learning and memorizing them.
(4) Face recognition: Finding which face in the previously collected and learned faces most closely matches the face to be recognized.
The first three steps serve as the preparation for the final step of face recognition. When designing a program for face recognition, we first collect and preprocess the detected faces to create a set of face images; then, we train these images to form a face model. Finally, during recognition, new image data is captured and fed into the generated face model, which outputs the recognized face result.
2. Learn Face Command

3. Face Recognition Command

4. Forget Face Command

Want this lesson in your classroom? Download the files for a full AI curriculum aligned with CSTA, NGSS, and EU DigComp standards.
[Get UNIHIKER K10 here]
Want to keep learning? Continue your learning journey with our other lessons.
Lesson1: Build a Light-Responsive Virtual Pet Dog
Lesson2: Design a Whack-a-Mole Arcade Game
Lesson3: Build Portable Walkman-Style Music Player (KS3/CSTA/DigComp)
Lesson4: Design Smart RFID Unmanned Supermarket
Lesson5: Build IoT Smart Greenhouse Monitoring System
Lesson6: Build a Voice-Controlled Smart Home Assistant
Lesson7: Build a Face Recognition AI Camera for Christmas Projects
Lesson9: Create an Automatic Cat Feeder with Cat Face Detection
