← Back to Missions
ADVANCED • 60 MINUTES

Mission 8: Color Tracker 🎨

Make the robot follow colored objects like a puppy!

🎨

🎯 What You'll Learn

🌈 Color Science

How cameras see color using RGB values

🎯 Object Tracking

Following moving targets in real-time

📍 Spatial Awareness

Using X/Y coordinates to navigate

🎮 Reactive AI

Robot responds to visual stimuli instantly

📦 What You Need

🐕 Robot Puppy Mode!

This mission turns the robot into a playful puppy that chases colored toys! Hold up a red ball and watch it follow. Switch to a blue ball and it ignores the red. This is selective attention—the same thing our brains do when we focus on one thing and ignore distractions.

Applications: Sports ball tracking, sorting colored objects in factories, following traffic signals, even helping colorblind people identify colors! 🏀🚦

🛠️ Let's Track Colors!

1

Set HuskyLens to Color Recognition Mode

Press the Function button on the HuskyLens until you see a rainbow/palette icon. The mode name should say "Color Recognition."

🌈 Visual Clue: In this mode, when you point at colored objects, you'll see small boxes appear around them with the dominant color highlighted.
2

Train a Target Color

Hold a bright red object (ball, toy car, piece of construction paper) about 12 inches from the camera. Center it on screen.

Training Process:
1. Keep the red object steady and centered
2. Press and hold the LEARNING button for 2-3 seconds
3. Screen will flash—the HuskyLens has "learned" that color
4. Now it will track anything with that red hue!

Best Colors to Start With:

  • Red: Easy to detect, high contrast
  • Blue: Distinct from most backgrounds
  • Green: Good for "go" signals
  • Yellow: Bright and eye-catching
⚠️ Avoid: White, black, or pastel colors—they're harder to distinguish from backgrounds!
3

Test Color Detection

Move the red object around. The HuskyLens should draw a box around it and track its movement. Try these experiments:

  • Distance test: How far away can it still detect?
  • Speed test: Wave it fast—does it keep up?
  • Angle test: Turn the object—still works?
  • Multiple objects: Show two red things—it tracks both!
📊 What You're Seeing: The box shows the detected color blob. The X/Y numbers are its position on the screen (0-320 horizontal, 0-240 vertical).
4

Code: Basic Color Detection

Let's make the micro:bit respond when it sees the target color:

On Start:
  HuskyLens Initialize I2C
  HuskyLens Set Algorithm [Color Recognition]

Forever:
  HuskyLens Request

  If [HuskyLens Is Learned]:
    // Red object detected!
    Show Icon ♥
    Play Tone 500Hz for 200ms

  Else:
    // No red object in view
    Show Icon •

  Pause 100ms

Upload and test! The robot should show a heart and beep whenever it sees red.

5

Make It Follow the Color!

Now for the magic—steering toward the colored object:

Forever:
  HuskyLens Request

  If [HuskyLens Is Learned]:
    Set [x_pos] to [HuskyLens Get Center X]

    // Object is on LEFT (x < 140)
    If [x_pos] < 140:
      // Turn left to follow
      Set Motors: Left=40, Right=100

    // Object is on RIGHT (x > 180)
    Else If [x_pos] > 180:
      // Turn right to follow
      Set Motors: Left=100, Right=40

    // Object is CENTERED
    Else:
      // Drive straight toward it!
      Set Motors: Left=100, Right=100

  Else:
    // No color detected - stop
    Set Motors: Left=0, Right=0

  Pause 100ms
🎮 Try It: Hold the red object in front of the robot. Move it left and right— watch the robot chase it like a puppy! 🐕
6

Advanced: Distance Control

Let's add smarts—stop if the object gets too close (prevents crashes!):

If [HuskyLens Is Learned]:
  Set [x_pos] to [HuskyLens Get Center X]
  Set [width] to [HuskyLens Get Width]

  // If object is VERY CLOSE (big on screen)
  If [width] > 150:
    Set Motors: Left=0, Right=0 (stop!)
    Show String "Too Close!"

  // If far away, drive toward it
  Else:
    [Same steering code from Step 5]
📏 How It Works: When objects are close, they look bigger on screen. By checking the "width" of the detected blob, we know the approximate distance!
7

Multi-Color Mode (Expert Level!)

The HuskyLens can learn multiple colors and give each an ID! Train it on red (ID1) and blue (ID2), then program different behaviors:

If [HuskyLens Get ID] = 1:
  // Red detected - CHASE IT!
  [Tracking code to follow]

Else If [HuskyLens Get ID] = 2:
  // Blue detected - RUN AWAY!
  Set Motors: Left=-100, Right=-100 (reverse!)
  Pause 1000ms

Game Ideas:

  • Traffic Light: Green = go, Red = stop, Yellow = slow
  • Color Sorting: Push red objects left, blue objects right
  • Hot & Cold: Red = approach, Blue = avoid
  • Simon Says: Only follow the color you announce

🔬 What's Happening Behind the Scenes?

The camera captures images as a grid of pixels. Each pixel has an RGB value (Red, Green, Blue intensity). When you train a color, the AI analyzes the dominant hue in that region and stores it as a reference.

Every frame (30 per second), it scans for pixel clusters matching that hue. It groups nearby matching pixels into "blobs" and calculates the blob's center point (X, Y) and size (width, height). This is called color segmentation.

The Color Detection Pipeline:

  1. 1. Capture Frame: Get image from camera
  2. 2. Convert Color Space: RGB → HSV (Hue, Saturation, Value)
  3. 3. Apply Threshold: Filter pixels matching target hue
  4. 4. Find Blobs: Group connected matching pixels
  5. 5. Calculate Properties: Centroid (X,Y), area, bounding box
  6. 6. Return Data: Send coordinates to micro:bit

Real-World Applications: Sports broadcasts (yellow "first down" line in football), fruit sorting machines (separating ripe from unripe), medical imaging (detecting abnormal tissue colors), and even makeup apps (changing lipstick color)! 🏈🍎💄

🎮 Creative Challenges

🎯 Target Practice

Put colored targets around the room. Program the robot to drive to red first, then blue, then green. Can it do a circuit?

⚽ Robot Soccer

Use a colored ball. Program the robot to push it toward a goal (marked with a different color). First to score wins!

🚦 Traffic Control

Make traffic light cards (green/yellow/red paper). Robot follows green, slows at yellow, stops at red. Teach traffic safety!

🎨 Color Memory Game

Flash colored cards in sequence. Robot must follow them in order. Wrong color = buzzer sound. It's Simon Says!

Mission Success Checklist

🚀 Ready for Microscopic Exploration?

Fantastic! The robot now chases colored objects like a playful puppy! The boys learned about color theory, computer vision segmentation, spatial tracking, and reactive AI—skills used in robotics, AR/VR, and autonomous vehicles!

Next up: We'll attach the microscope module and explore the TINY world! Look at circuits, bugs, leaves, and more at 30x magnification. Science meets robotics! 🔬

Next Mission: Microscope Explorer 🔬 →
← Back to All Missions