Back to Final Project
Electronics & Firmware
The control system centers on a Seeed XIAO ESP32-C3, TCS34725 color sensor (I²C), and two SG90 servos — Servo1 feeds the turntable, Servo2 directs sorted beads. Firmware evolved from serial sensor tests (Week 9) to full sorting with optional Wi-Fi web control (Week 11).
Core components
- Controller: XIAO ESP32-C3 — main MCU (USB-C, Wi-Fi, I²C)
- Input-TCS34725 — RGB color sensor (SDA GPIO6, SCL GPIO7)
- Output Device: SG90 Servo1 (GPIO2) — turntable feed: 0° → 180° → 0°
- Output Device: SG90 Servo2 (GPIO3) — sort chute: RED 30°, GREEN 60°, YELLOW 90°
- Power Supply: 5 V external supply for servos (common ground with MCU)
Custom PCB
Designed in KiCad to break out XIAO, sensor header, servo connectors, and power.
System integration logic
State flow: idle → read color → set Servo2 angle → feed bead with Servo1 → repeat. A machineRunning boolean gates automatic cycles when enabled from the web UI.
Circuit simulation
The circuit simulation was done in Cirkit designer IDE.
Firmware — color detection & sorting (excerpt),all the code is in the repository
From Week 11 Wi-Fi + servo control sketch:
bool machineRunning = false;
String currentColor = "NONE";
String detectColor() {
uint16_t r, g, b, c;
tcs.getRawData(&r, &g, &b, &c);
if (c < 100) return "NONE";
float rf = (float)r / c, gf = (float)g / c, bf = (float)b / c;
if (rf > 0.45 && rf > gf && rf > bf) return "RED";
if (gf > 0.40 && gf > rf && gf > bf) return "GREEN";
if (rf > 0.30 && gf > 0.30 && bf < 0.20) return "YELLOW";
return "UNKNOWN";
}
void sortBean(String color) {
if (color == "RED") servo2.write(30);
else if (color == "GREEN") servo2.write(60);
else if (color == "YELLOW") servo2.write(90);
else return;
delay(500);
}
Source files in repository
- Wi-Fi control code — ESP32 embedded Wi-Fi to control the machine
- ESP32_motor.ino — motor / servo tests
- DeviceControl_week15.ino — device control experiments
- Full
machineRunning+ WebServer code — Week 11 documentation - Integration state machine — Week 16 documentation
Wi-Fi web control demo
Wiring notes
- I²C: TCS34725 VCC → 5 V, GND → GND, SDA/SCL → GPIO6/GPIO7
- Do not power servos from the XIAO 3.3 V pin — use 5 V supply with shared ground
- Keep sensor cable short; shield from direct ambient light with printed shroud
Related weekly assignments
Work on this final project is documented across these weeks:
- Week 1 — project motivation and first sketches
- Week 2 — CAD exploration (Fusion 360)
- Week 3 — laser-cut chassis
- Week 5 — 3D printing tests
- Week 6 — custom PCB design (KiCad)
- Week 9 — TCS34725 color sensor input
- Week 11 — Wi-Fi web control &
machineRunningfirmware - Week 16 — system integration plan & sketches
- Week 18 — applications & implications proposal
- Week 19 — dissemination & project status