Skip to the content
2 layersJONICA, the printed circuit board in 3D

A project made mostly in python to classifie color caps using OpenCV

Copper layers
2
Thickness
1.6 mm
Parts
59
Nets
105
Pads
272
Tracks, vias
90, 0
Routed
Yes
KiCad
KiCad 5 (file 20171130)
Created
16 Dec 2019
Updated
31 May 2026

Overview

JONICA is an open-source printed circuit board by mhechavarria, from the mhechavarria/color-caps-classifier repository on GitHub. It is a 2-layer board with 59 parts on 105 nets, routed with 90 tracks and 0 vias.

It is built around the ARDUINO UNO R3, LM324 and LM358, with the CNY70, L7805 and ULN2003A among its other parts. Its parts include 31 resistors, 9 connectors, 8 ICs, 4 transistors and 2 capacitors. It belongs with the AVR (ATmega, ATtiny) boards of this library.

Main components

7

README

README.md

JONICA — Color Caps Classifier

A mechatronic machine that classifies soda-bottle caps by color from a camera feed and physically sorts them into per-color outputs in real time. It combines computer vision (OpenCV on a Raspberry Pi), finite-state-machine firmware on an Arduino / ATmega328P, custom PCBs, and 3D-printed mechanical parts.

University engineering-competition project — Escuela de Ingeniería Electrónica, Facultad de Ciencias Exactas, Ingeniería y Agrimensura (FCEIA), Universidad Nacional de Rosario. The brief (set by the course): build a device that uses webcam images to classify caps by color and separate the red ones — minimum red/green/blue, with extra credit for yellow/orange/grey — designed to be scalable to an industrial setting in speed and throughput.

📹 Demo video: https://drive.google.com/open?id=1r29vyWqCW7NpwiLaEyCusYoAQh5E9Sr1


How it works

text
Hopper ─► paddle presents a cap under the camera + LEDs
        ─► Raspberry Pi (OpenCV, HSV) classifies the color
        ─► color code sent over serial / RS485
        ─► ATmega328P queues it (circular buffer) and drives stepper-actuated levers
        ─► cap is routed in free-fall to the matching output
   (CNY70 reflective sensors track each cap's passage along the way)

The caps are sorted in free-fall — a deliberate choice for speed. Levers driven by stepper motors deflect each falling cap into the right path.

Architecture

Three subsystems integrated into one machine:

1. Vision — Raspberry Pi 3 + PiCamera (Python / OpenCV)

  • HSV color segmentation with per-color cv2.inRange masks (blue, green, yellow, orange, red). Red is matched across two hue ranges to handle the hue wrap-around at 0/180°.
  • Gaussian blur + bilateral filtering to denoise while preserving edges.
  • A calibration tool (calibracion.py) with live HSV trackbars to tune each color band.
  • LED illumination at the capture point for consistent lighting.

2. Control firmware — Arduino / ATmega328P (C/C++)

  • Three finite state machines (one per stepper) plus FSMs for serial reception and cap selection — cooperative, non-blocking design.
  • A4988 micro-stepping drivers (4 in total) for the NEMA 17 steppers; step pulses generated from a Timer1 ISR (1 ms tick).
  • A circular buffer queues detected caps so classification and actuation can run decoupled without losing or mis-routing caps.
  • CNY70 reflective optical sensors detect cap passage (with debounce logic).
  • Timeout handling resets state if a cap is lost mid-cycle.

3. Electronics & mechanics

  • Custom PCBs designed in KiCad and Eagle: CNY70 sensor boards and motor/Pololu shields (Circuito/, Sensor IR/, Shield pololu/).
  • RS485 (MAX485) multipoint bus between the Pi and the Arduino(s): it adapts UART voltage levels, adds noise immunity, and — being multipoint — lets the system scale (one ATmega328P per motor as bus slaves, Raspberry Pi as master) to handle more colors/outputs.
  • Mechanical design in SolidWorks, 3D-printed (Creality CR-10): the classification paddle (which also mounts the camera, LEDs, and its motor), selector levers, motor mounts, and a Raspberry Pi case (Modelos v4/, Caño para seleccionar tapas/). Wooden frame, hopper, and output tube.

Hardware

PartRole
Raspberry Pi 3 Model B + PiCameraImage capture, OpenCV classification, master controller
Arduino UNO / Nano (ATmega328P)Real-time motor control + sensor handling
3× NEMA 17 stepper motorsPaddle rotation + cap-selection levers
4× A4988 stepper driversMicro-stepping motor drive
CNY70 reflective optical sensorsCap-passage detection
MAX485 transceiverRS485 serial link (Pi ↔ Arduino)
LED illumination + PC DC power supplyLighting + system power

Design decisions (from the project report)

  • Free-fall sorting chosen over an arm/turntable classifier (those were too slow/bulky).
  • Stepper motors + levers chosen over servos (too slow) and pneumatic valves (too expensive).
  • RS485 multipoint chosen so the architecture scales to more bins without a redesign.

Repository layout

PathContents
SRC/Cleaned-up source: vision (calibracion.py, script-picam-foto.py) + FSM motor firmware (nuevo_motores/)
JONICA Rasp/Raspberry Pi scripts (PiCamera capture, color selection, demos)
Script/Earlier vision-script iterations + test assets
programa motores/Arduino firmware iterations (v1–v14), RS485 transmitter, sensor/comm modules
Motor_paso_a_paso.ino/, Prueba_motor_unipolar/Stepper-motor test sketches
Circuito/KiCad PCB projects (v1, v2, shield) + Gerbers / G-code
Sensor IR/, Shield pololu/Eagle PCB designs
Modelos v4/, Caño para seleccionar tapas/SolidWorks CAD, STL, and slicer G-code for the printed/mechanical parts
INFORME/Project reports (Spanish) + state-machine and schematic diagrams

Running the vision module

On a Raspberry Pi (or any machine with a camera) with Python 3 and OpenCV:

bash
pip install opencv-python numpy pyserial
# On a Raspberry Pi, also: picamera + RPi.GPIO

python3 SRC/calibracion.py   # tune the HSV ranges for your caps/lighting
python3 Script/script.py     # send color commands to the Arduino over /dev/ttyAMA0 @ 9600

The code reflects its competition-time state (Spanish comments, some hardcoded paths, multiple preserved iterations). It's published as a hardware/software portfolio reference, not a packaged product.

Team

Jonatan Arroyo · Tomás Ayi · Paula Diaz · Mariano Echavarría — Ingeniería Electrónica, UNR.

Parts

59
QtyValueFootprintReferences
710kResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR1, R16, R18, R20, R21, R22, R23
41k5Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR11, R13, R24, R26
43.9Resistor_THT:R_Axial_DIN0614_L14.3mm_D5.7mm_P5.08mm_VerticalR28, R29, R30, R31
44k7Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR12, R14, R25, R27
4IRLZ44NPackage_TO_SOT_THT:TO-220-3_VerticalQ1, Q2, Q3, Q4
31k6Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR8, R9, R10
3220Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR2, R3, R4
339kResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR5, R6, R7
347kResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR15, R17, R19
3CNY70Circuito:CNY70U6, U7, U8
2Pololu_Breakout_A4988Modules:Pololu_Breakout-16_15.2x20.3mmA1, A2
2Pololu_Breakout_A4988Module:Pololu_Breakout-16_15.2x20.3mmA4, A5
1100nFCapacitor_THT:C_Disc_D3.0mm_W1.6mm_P2.50mmC2
1330nFCapacitor_THT:C_Disc_D3.0mm_W1.6mm_P2.50mmC1
174LS08Package_DIP:DIP-14_W7.62mm_LongPadsU4
1Arduino_UNO_R3Module:Arduino_UNO_R3A3
1L7805Package_TO_SOT_THT:TO-220-3_VerticalU2
1LM324Package_DIP:DIP-14_W7.62mm_LongPadsU3
1LM358Package_DIP:DIP-8_W7.62mm_LongPadsU1
1M0-MOSFETTerminalBlock:TerminalBlock_bornier-4_P5.08mmJ2
1M0-POLOLUTerminalBlock:TerminalBlock_bornier-4_P5.08mmJ7
1M1TerminalBlock:TerminalBlock_bornier-4_P5.08mmJ4
1M2TerminalBlock:TerminalBlock_bornier-4_P5.08mmJ5
1M3TerminalBlock:TerminalBlock_bornier-4_P5.08mmJ6
1SENSOR1Connectors_Terminal_Blocks:TerminalBlock_bornier-3_P5.08mmJ9
1SENSOR2Connectors_Terminal_Blocks:TerminalBlock_bornier-3_P5.08mmJ8
1SENSOR3Connectors_Terminal_Blocks:TerminalBlock_bornier-3_P5.08mmJ1
1UARTConnectors_Terminal_Blocks:TerminalBlock_bornier-2_P5.08mmJ3
1ULN2003APackage_DIP:DIP-16_W7.62mm_LongPadsU5

More from mhechavarria/color-caps-classifier

2
  • 2 layersJONICA, the printed circuit board in 3D

    JONICA

    mhechavarria/color-caps-classifier

    A project made mostly in python to classifie color caps using OpenCV

    16 parts
  • 2 layersCircuito v2, the printed circuit board in 3D

    Circuito v2

    mhechavarria/color-caps-classifier

    A project made mostly in python to classifie color caps using OpenCV

    9 parts

Similar boards

  • 2 layers135.6 × 85.3 mmPCB Banc, the printed circuit board in 3D

    PCB Banc

    amine0561/PCB_Banc_Automatis-

    135 parts
  • 2 layers101.6 × 107.9 mmSistdig, the printed circuit board in 3D

    Sistdig

    dinge321/motor_pcb

    This is a pcb for a 6V motor project using an unspecified microcontroler with the driver L293D

    21 parts
  • 2 layers55 × 485 mmFg lampe, the printed circuit board in 3D

    Fg lampe

    devtal-de/fg_lampe

    181 parts1
  • 2 layers99.5 × 99.5 mmCarico elettronico, the printed circuit board in 3D

    Carico elettronico

    dario0603/electronic_load

    Un progetto open-source per la progettazione e simulazione di un Carico Elettronico Bipolare (Electronic Load), ideato per il test e la caratterizzazione di alimentatori, batterie e circuiti di potenza.

    92 parts
  • 2 layers41.3 × 31.2 mmLevitator, the printed circuit board in 3D

    Levitator

    QuartzAl/Projects-showcase

    Main repository where I keep all of my project showcases related to Electrical Engineering These include PCB designs, electronic circuits, code snippets, and more.

    13 parts
  • 2 layers316 × 49 mmLine sensor, the printed circuit board in 3D

    Line sensor

    Technariumas/smalsiukas

    The conversion of a forklift truck to a line following robot.

    70 partsApache-2.0
  • 2 layers821.3 × 499.1 mmSeguidordelineasV2.1, the printed circuit board in 3D

    SeguidordelineasV2.1

    aguuzzo/GZX

    Este proyecto implementa un robot seguidor de líneas basado en un Arduino Nano, 6 sensores CNY70, motores Pololu y un driver de motores.

    248 parts1

Questions

What parts does the JONICA use?

59 parts, built around the ARDUINO UNO R3, LM324, LM358 and CNY70. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the JONICA KiCad files?

From the mhechavarria/color-caps-classifier repository on GitHub, at the commit this page was made from: the board is Circuito/Circuito v1/JONICA.kicad_pcb. PCBKit opens the board in the browser, with nothing to install.

Can I use the JONICA design in my own project?

Its repository states no licence, so its author keeps all rights: ask mhechavarria before reusing the design.