Lesson 19
Color Recognition (Hiwonder 7.4)
Use the ESP32-S3 Vision Module to Recognize Red/Blue and React
🎯 Learning Objectives
- Understand the “two brains” setup: ESP32-S3 vision module does detection, Arduino reads results over I2C
- Recognize red and blue blocks and trigger different robot behaviors
- Learn what a “color ID array” is and how to interpret it (255 = nothing detected)
- Use the RGB LED and buzzer for feedback
- Follow safe upload workflow notes (remove Bluetooth module to avoid serial conflicts)
🎨 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
- Red detected: RGB turns red, buzzer beeps once, robot rocks forward/back
- Blue detected: RGB turns blue, buzzer beeps twice, robot rocks left/right
- Nothing detected: RGB turns white
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:
- Flash firmware: Upload the ESP32-S3 color recognition program and the UNO program
- Red test: Place red block in view; confirm red LED + 1 beep + forward/back rock
- Blue test: Place blue block in view; confirm blue LED + 2 beeps + left/right rock
- 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
- LED Feedback: Change the “no detection” LED from white to a slow breathing effect
- Timing: Reduce false triggers by requiring the same color to be detected for N frames
- 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