LEARN.PARALLAX.COM
Published on LEARN.PARALLAX.COM (https://learn.parallax.com)
Home > Gatekeeper Robot (MakeCode)

Gatekeeper Robot (MakeCode)

What it’s about

Build a cyber:bot project that uses face recognition to decide when to let someone “pass.” The HUSKYLENS AI camera identifies faces it has previously learned, and the cyber:bot performs a specific motion sequence whenever it sees a recognized individual. This kind of interaction mirrors access-control concepts used in robotics and automated systems, where a device responds only to approved or known inputs.

Face recognition is widely used in modern technology—from unlocking a smartphone to managing access to secure rooms or equipment. In robotics, combining computer vision with movement allows machines to interact intelligently with people and their environment. In this tutorial, you will load a saved face-recognition model from the HUSKYLENS, watch how it identifies different trained face IDs, and control the cyber:bot robot’s maneuvers in real time based on what the camera sees. The result is a simple but powerful demonstration of how AI can guide robotic behavior.

What you need to get started

These activities assume that you have already completed the earlier cyber:bot tutorials in sequence. Make sure you have finished through the Navigation and Circuits lessons before beginning this one.

Before running the script for this for this app, you must train the HUSKYLENS to recognize several faces and save the results using the Logo + A method. Follow the steps in Remember Training Data with a microSD Card (Python) to store the learned faces into model slot 1 on the HUSKYLENS microSD card.

For this these activities, you will need:

  • A fully assembled and tested cyber:bot robot

  • A HUSKYLENS AI camera with its I2C cable and microSD card

  • At least three trained face samples stored in model slot 1

After you finish

Once you complete this tutorial, you will be ready to explore more advanced AI-guided navigation activities. You may choose to expand the Robot Gatekeeper into a full access-control demonstration, experiment with other HUSKYLENS algorithms such as color or tag recognition, or combine face detection with line following or obstacle avoidance for more complex robotic behaviors.

Parts & Wiring: Gatekeeper Robot (MakeCode)

In this activity, you’ll use your cyber:bot and HUSKYLENS AI camera to recognize faces and make the robot move in response. Once a face ID is detected, the cyber:bot performs a turning maneuver sequence, pauses, and then reverses direction. You’ll learn how to control motion based on what the HUSKYLENS sees and practice using both AI vision and navigation modules together.

✓ Before starting, review the Remember Training Data with a microSD Card (Python) chapter. Train the HUSKYLENS to recognize three faces and save them to model slot 1 using the Logo + A method. This ensures that the robot can recall its learned faces when the script runs.

Parts List

  • cyber:bot robot with micro:bit

  • HUSKYLENS AI Vision Sensor

  • 4-pin I2C cable

  • Two continuous rotation servos

  • 6 V battery pack

Schematic/Wiring, Assembly

✓ Connect the HUSKYLENS module to the cyber:bot’s I2C header (SDA → P5, SCL → P4, power, and ground).
✓ Mount the HUSKYLENS on the cyber:bot’s front bracket so it can see forward.
✓ Ensure servos are connected to the cyber:bot pins as usual for left and right drive motors.
✓ Power the system using the 6 V battery pack.

Script: Gatekeeper Robot (MakeCode)

This script makes the cyber:bot react when it sees a recognized face ID from the HUSKYLENS. Each ID is stored in the camera’s internal model so the robot can distinguish between faces you’ve trained.

✓ Open microbit_huskylens_proejct.hex or any of your previous working cyber:bot-HUSKYLENS scripts.
✓ Update the script to match the one shown below.
✓ Click Save to save a copy of your script.
✓ Click Send to micro:bit to load the script into the cyber:bot robot’s micro:bit.

Tests: Gatekeeper (MakeCode)

✓ Flash the script to the cyber:bot.
✓ Point the HUSKYLENS toward a face that was previously trained and stored in model slot 1.
✓ When the trained face is detected, the robot should:
 • Display a check mark (Image.YES).
 • Perform a turning maneuver.
 • Return to its starting direction.
✓ If the face disappears, the robot stops and shows an X.
✓ If no faces are visible, the robot shows the sleeping face icon.

Note: The script loads model 1 from the HUSKYLENS SD card. Make sure a trained face model is stored before running the program.

Try This

In this activity extension, you’ll experiment with different algorithms and movement patterns to see how changing visual detection or motor control affects performance. You’re working toward understanding how to use the same motion logic across different HUSKYLENS modes. Expect to see changes in responsiveness or accuracy depending on which algorithm you select.

✓ Change switch_algorithm(“face”) to “color” or “tag” and observe how detection and motion change.
✓ Modify the speeds in motion.maneuver(-75, -25, 2000) to widen or tighten the robot’s turns.
✓ Add sound feedback with music.play(music.BA_DING) when a face is detected.

How It Works: Gatekeeper (MakeCode)

Did You Know

About Motion Control

The motion.maneuver(left_speed, right_speed, duration) command runs both wheel servos simultaneously for a specific time. Negative speeds reverse direction, allowing curved or in-place turns.

About HUSKYLENS Models

The HUSKYLENS can store up to six models on its microSD card. Each model can contain multiple learned faces, colors, or tags that can be recalled in later programs.

How It Works

This activity combines two modules—HUSKYLENS vision and cyber:bot navigation—to create an interactive behavior loop. Most setup and I2C initialization steps were introduced in earlier activities. Here, the focus is on loading and acting upon stored training data.

The switch_algorithm(“face”) command places the HUSKYLENS in face-recognition mode, and manage_model(“load”, 1) recalls the previously saved face model from the SD card. This allows the camera to recognize faces learned in an earlier session.

switch_algorithm("face")
manage_model("load", 1)

The code below checks for button presses so you can cycle through trained face IDs. This part adds flexibility, letting you test recognition of multiple people.

if button_a.is_pressed():
current_id += 1
if current_id > 5: current_id = 1

The most important new logic appears in the request_data() loop. This section fetches visual results from the HUSKYLENS, checks whether a specific ID is visible, and triggers movement accordingly. When a match is found, the cyber:bot displays a check mark, performs a left-then-right turning sequence, and restores the displayed ID. If no faces are detected, it stops and shows an idle icon.

if is_visible(current_id, "block"):
display.show(Image.YES)
motion.maneuver(-75, -25, 2000)
sleep(6000)
motion.maneuver(75, 25, 2000)

Your Turn: Gatekeeper (MakeCode)

Your Turn

In this modification, you’ll make the cyber#bot drive toward the recognized face instead of turning in place. You’re working toward a “follow-the-face” behavior, where movement is triggered by recognition and halted when the face disappears.

Update Your Script

✓ Replace both motion.maneuver() lines with motion.maneuver(50, 50, 1000) to move forward.
✓ Add an else: condition that stops the robot if the face is lost.
✓ Observe how quickly it reacts when the camera can no longer see the target.

Questions, Exercises, & Projects: Gatekeeper (MakeCode)

Questions

  1. What does switch_algorithm(“face”) do?

  2. Why does the script load model 1 before starting detection?

  3. What happens when you press button A or B during operation?

Exercises

  1. Add code so the cyber#bot flashes the LED display rapidly when a face is detected.

  2. Modify the code so the robot performs only one turning cycle before stopping until a button is pressed again.

Projects

  1. Create a “Greet the Recognized Face” project. When the HUSKYLENS detects a known face, the cyber:bot should move forward, stop, display a heart, and play a tone. When the face disappears, it should show an X and back up slightly.

  2. Design a “Face Patrol” project where the robot scans for known faces and performs a short spin when none are detected.

Solutions: Gatekeeper (MakeCode)

Questions

  1. Answer: The switch_algorithm(“face”) command changes the HUSKYLENS to face-recognition mode.

  2. Answer: Model 1 contains previously trained faces saved on the SD card; loading it recalls those faces.

  3. Answer: Buttons A and B cycle through which face ID the cyber#bot is tracking.

Exercises

  1. Answer: Use a loop that alternates display.show(Image.YES) and display.clear() to flash the display quickly.

  2. Answer: Add a counter or Boolean flag that prevents repeated turning until a button press resets it.

Projects

  1. Answer: Combine motion.maneuver(50, 50, 1000), display.show(Image.HEART), and music.play(music.POWER_UP) inside the detection block.

  2. Answer: Use a timer to call motion.maneuver(75, -75, 1500) when no faces are detected, then return to scanning.

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024


Source URL:https://learn.parallax.com/courses/gatekeeper-robot-makecode/
Links