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)
PCB schematic sketch Final PCB layout XIAO ESP32 symbol XIAO ESP32 symbol

Custom PCB

Designed in KiCad to break out XIAO, sensor header, servo connectors, and power.

PCB schematic sketch Final PCB layout XIAO ESP32 symbol

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.

Smartphone to ESP32 control flowchart

Circuit simulation

The circuit simulation was done in Cirkit designer IDE.

Wokwi simulation

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 web control demo

Smartphone web UI Serial monitor output Serial monitor output Serial monitor output

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 & machineRunning firmware
  • Week 16 — system integration plan & sketches
  • Week 18 — applications & implications proposal
  • Week 19 — dissemination & project status