Lesson 19

Color Recognition (Hiwonder 7.4)

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

🎯 Learning Objectives

✅ Before You Start (Plug-and-Play After Lesson 18)

Lesson 18 proved the camera and hotspot work. For Lesson 19, you will switch the ESP32-S3 from “live feed” firmware (7.3) to “color recognition” firmware (7.4). After you do this, the live-stream page behavior may change—that’s expected.

Readiness Checklist

  1. Hardware: ESP32-S3 vision module is installed and powered (recommend at least 5V 2A)
  2. USB/Driver: Windows shows a USB serial port for the module (often CH34x/CH340)
  3. Firmware switch: Flash the ESP32-S3 with the 7.4 color recognition firmware/program
  4. UNO code: Upload the matching UNO program for 7.4 (reads results over I2C)
  5. Test objects: You have a clear red object and a clear blue object
Troubleshooting shortcut: If the camera feed used to work in Lesson 18 but now doesn’t, you probably changed firmware. That’s normal—continue with the 7.4 setup. If you ever need the live feed again, reflash the 7.3 image_transmit firmware.

🎨 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. ESP32-S3 first: Flash the 7.4 color recognition firmware/program to the vision module
  2. UNO second: Upload the matching UNO sketch for 7.4 (I2C reads)
  3. Red test: Place red block in view; confirm red LED + 1 beep + forward/back rock
  4. Blue test: Place blue block in view; confirm blue LED + 2 beeps + left/right rock
  5. 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 →