RUSHAEROSPACE | MECHANICAL | SOFTWARE ENGINEERING

MECHATRONICS / EMBEDDED AI

Coin Sorting Machine using ML & AI

A working mechatronics prototype that recognizes LKR 1, 2, 5, and 10 coins using dual-camera vision and EfficientNet-B0, then sorts them with servo-driven mechanisms.

Sri Lankan coin denominations
4
Real-world training images
3,000+
Pixels per model input
224 × 224
Presentation render based on the original coin-sorter prototype, showing the transparent feeding tube and four collection bins
Presentation render based on the supplied prototype photograph. Original source media is retained below.

Tools & methods

  • Raspberry Pi 4B
  • USB webcams
  • Python
  • OpenCV
  • TensorFlow / Keras
  • TensorFlow Lite
  • EfficientNet-B0
  • pigpio
  • SolidWorks

Project overview

We developed an automated coin sorting system for Sri Lankan LKR 1, 2, 5, and 10 coins as Group 12's ME 5212 project at the University of Ruhuna. The prototype brings together mechanical handling, computer vision, embedded inference, and servo actuation.

The aim was to replace denomination decisions based only on size and weight with image-based classification using coin appearance, surface texture, color, and embossed features. A Raspberry Pi 4B connects recognition to the physical sorter.

Aims and objectives · report pp. 4–5 ↗

My contribution & the team

I trained the machine learning model, developed Raspberry Pi/Python code with Janith Rukshan, and contributed to fabrication with the full team. The report's role table distinguishes these responsibilities from the mechanical design, electronics design, and initial camera configuration.

Project responsibilities · Table 3, report p. 28
Work areaContributors
Model trainingSudeera Perera
Raspberry Pi / Python codingSudeera Perera; Janith Rukshan
Solid model designAkhila Dhananjaya; Shaveen Rodrigo
Circuit designJanith Rukshan; Akhila Dhananjaya
Initial ESP32 camera configurationShaveen Rodrigo
FabricationAll four team members
Personal role and achievements · report pp. 28–30 ↗

Mechanical design & sorting sequence

The mechanism separates coin feeding, imaging, rotation, and routing. A container and vertical tube align the coins; the pusher and holder control the coin's position before release. A carrying rotator exposes the second side, and a directing slider sends the classified coin toward its collection bin.

  1. Load bulk coins into the container and arrange them vertically.
  2. Capture the first side of the bottom coin using camera 1.
  3. Push the coin into the carrying rotator.
  4. Rotate the carrier halfway and capture the other side with camera 2.
  5. Rotate and release the coin into the directing slider.
  6. Position the slider for the denomination's bin.
Report flowchart showing bulk feeding, two-sided imaging, coin rotation, and slider-based bin selection
Figure 2: Process flow chart · report p. 11.

SolidWorks supported the mechanical design. The team manually cut and assembled accessible materials because precision 3D printing was outside the project budget.

Process flow and hardware · report p. 11 ↗

Dataset & machine learning

The team collected more than 3,000 images of LKR 1, 2, 5, and 10 coins. Coins sourced from a bus driver supplied real circulation wear, dirt, scratches, and reflections. Images covered different lighting conditions; rotation, scaling, and brightness or contrast adjustments expanded the training data.

EfficientNet-B0 provided the classification architecture. The report describes TensorFlow/Keras training on Google Colab with GPU acceleration, using the Adam optimizer and categorical cross-entropy loss. The trained model was converted to TensorFlow Lite for inference on the Raspberry Pi.

Model development is recorded in the report's Liner screenshots, including dataset classes, loss curves, validation accuracy, and class-wise scores.

Model architecture and training · report p. 12 ↗ Dataset collection and augmentation · report p. 30 ↗

Image processing & inference

The report describes OpenCV preprocessing with grayscale conversion, Gaussian smoothing, Canny edges, contour detection, and color segmentation. These techniques support coin boundaries, shape, texture, and surface-feature analysis.

The included runtime snippet captures from two USB webcams at device indices 0 and 2. Its prediction function converts an OpenCV frame from BGR to RGB, resizes it to 224 × 224 pixels, creates a float32 batch, invokes the TensorFlow Lite interpreter, and selects the class using the largest output score.

Implementation details shown in the report code
ComponentRecorded configuration
Model input1 × 224 × 224 × 3
Image representationRGB; float32 batch
Camera acquisitioncv2.VideoCapture(0) and cv2.VideoCapture(2)
Predicted classargmax of the output scores
Displayed confidenceLargest output score × 100
Python code excerpts · report p. 14 ↗

Electronics & servo control

A Raspberry Pi 4B runs the recognition and control sequence. Two USB webcams provide images, and three servo-control outputs connect software decisions to the coin handling mechanism. The code uses pigpio for pulse-width control; it also lists NumPy, OpenCV, Pillow, TensorFlow Lite, and gpiozero imports.

Servo outputs defined in the report code
Output constantGPIO pin
MOTOR118
MOTOR223
MOTOR324

The helper maps a commanded angle to a servo pulse width and pauses after movement. In the prototype, camera capture, mechanical positioning, and actuation timing had to work together so the identified coin reached the intended bin.

Raspberry Pi connected to a breadboard, USB cameras, and servo wiring inside the fabricated sorter
Figure 4: Electronics of the fabricated machine · report p. 23.
Control code · report p. 14 ↗

Results & prototype validation

The final report records a completed, working prototype that classifies denominations and uses servo-controlled routing to place coins in their bins. It includes physical build photographs and sample classifications for all four denominations.

Model-development results displayed in the report
Metric or evidenceReported value / scope
Validation accuracy100.0% in the displayed model training run
Accuracy, macro and weighted precision / recall / F1100.00% in the displayed score panel
Sample outputsLKR 1, 2, 5, and 10 predictions shown
Physical outcomeFabricated sorter and connected electronics documented
EfficientNet training interface showing decreasing training and validation loss and 100.0 percent validation accuracy
Model training screenshot · report p. 20. This is a model-development result.
Model score panel showing accuracy, macro and weighted precision, recall, F1, and class-wise precision
Recorded model scores · report p. 20. Values describe the displayed model run.

The report does not specify the validation-set size or split, coins per minute, or a counted end-to-end sorting success rate. The displayed 100% model scores therefore describe that development run, rather than a measured reliability figure for the whole machine.

Model training and scores · report p. 20 ↗ Prototype discussion · report pp. 24–27 ↗

Engineering challenges & solutions

Budget, camera compatibility, image quality, and mechanical durability shaped the final implementation. The team adapted the build through procurement, testing, and redesign.

Problems and solutions documented in the final report
ChallengeResponse
Limited access to a Raspberry PiBorrowed a board from a University of Moratuwa engineering student.
ESP32 cameras did not operate reliably during setupReplaced them with two USB webcams borrowed from the department with the Head of Department’s support.
Time-consuming collection of varied coin imagesUsed real circulation coins and augmented the captured dataset.
Manually fabricated components and weakened adhesive jointsRebuilt affected components, reinforced bonds, changed some materials, and adjusted alignment.
Capture and processing delays; occasional coin misalignmentCalibrated timing and alignment; identified faster acquisition and more precise guides as future improvements.

The final USB-camera arrangement enabled the project to proceed, with capture delay remaining a tradeoff. Worn coins, reflections, and inconsistent positioning reinforced the need to develop the visual model and physical handling together.

Limitations · report p. 27 ↗ Problems and solutions · report pp. 29–30 ↗

Future development & applications

The prototype demonstrates a foundation for small-scale coin handling in banking, vending, retail, and self-service systems. The report proposes several next steps:

  • Improve acquisition with Raspberry Pi cameras and refine coin positioning with more precise fabricated or 3D-printed parts.
  • Optimize inference or evaluate a more capable embedded processing platform.
  • Expand the dataset for additional denominations and currencies.
  • Add a GUI for denominations, coin totals, and sorting statistics.
  • Explore IoT monitoring, transaction integration, and continuous feeding with a modular conveyor.

These are proposed extensions to the completed prototype; the report's demonstrated scope remains the four-denomination sorter.

Future work · report pp. 32–33 ↗

System at a glance

An overview of the documented project scope.

  1. 01Feed & align
  2. 02Image first side
  3. 03Push & rotate
  4. 04Image second side
  5. 05Classify denomination
  6. 06Direct to bin

Images, videos & documents

Front view of the fabricated coin sorter with its vertical frame, coin tube, two cameras, and four collection bins
The fabricated prototype · Figure 3, final report, printed page 22.
Final project report · ME 5212 · Group 12 (PDF) Document ↗

Project resources

The final report is the primary record for the design, implementation, role allocation, figures, and results shown on this page.