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)
â
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
- Hardware: ESP32-S3 vision module is installed and powered (recommend at least 5V 2A)
- USB/Driver: Windows shows a USB serial port for the module (often CH34x/CH340)
- Firmware switch: Flash the ESP32-S3 with the 7.4 color recognition firmware/program
- UNO code: Upload the matching UNO program for 7.4 (reads results over I2C)
- 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
- 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:
- ESP32-S3 first: Flash the 7.4 color recognition firmware/program to the vision module
- UNO second: Upload the matching UNO sketch for 7.4 (I2C reads)
- 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