Lesson 19

Color Recognition (Hiwonder 7.4)

Use the ESP32-S3 Vision Module to Recognize Red/Blue and React

🎯 Learning Objectives

🎨 Section 1: What This Program Does

In Hiwonder 7.4, the miniAuto uses the ESP32-S3 vision module to recognize red and blue blocks. When a color is detected, the robot reacts and the RGB LED shows the matching color.

Expected Outcomes

Safety Note (from Hiwonder)

Important: Remove the Bluetooth module before uploading code to avoid serial port conflicts.

🧠 Section 2: Reading Color IDs (Concept)

The ESP32-S3 processes the image and exposes results over I2C. The Arduino reads a small buffer/array. If a color is detected, the corresponding slot will contain a color ID. If nothing is detected, the value is usually 255.

Pseudo-Logic

// Read detection results into a buffer
readColorBuffer(buffer);

if (buffer[0] == 1) {
  // red
  setRgb(RED);
  beep(1);
  rockForwardBackward();
} else if (buffer[2] == 3) {
  // blue
  setRgb(BLUE);
  beep(2);
  rockLeftRight();
} else {
  setRgb(WHITE);
}

🔧 Hands-On Activity: Color Reaction Demo

Test the robot’s reactions with real red and blue blocks.

Checklist

Materials Needed:

  • miniAuto with ESP32-S3 vision module installed
  • Red block and blue block
  • Simple background (reduce clutter behind the blocks)

Step-by-Step Instructions:

  1. Flash firmware: Upload the ESP32-S3 color recognition program and the UNO program
  2. Red test: Place red block in view; confirm red LED + 1 beep + forward/back rock
  3. Blue test: Place blue block in view; confirm blue LED + 2 beeps + left/right rock
  4. Nothing test: Remove blocks; confirm white LED
💡 Pro Tip: Start with simple testing and gradually add more complex behaviors as you see it working!

📋 Assessment & Homework

Programming Challenges

  1. LED Feedback: Change the “no detection” LED from white to a slow breathing effect
  2. Timing: Reduce false triggers by requiring the same color to be detected for N frames
  3. New color: If you adjust HSV thresholds, add a third color and a third behavior

Research Assignment

Topic: HSV Thresholding

Explain why HSV is often easier than RGB for color detection, and how lighting/background affects accuracy.

Practical Exercises

  • Try detection in bright light vs dim light and note changes
  • Try detection with cluttered background vs solid background and note changes
  • Optional: Use the HSV tool in the appendix to adjust thresholds for your own colored object
← Lesson 18: Live Camera Feed 📚 Semester Overview Next: Lesson 20 →