Authors Nur Zulaikhah Nadzri, Yusman Yusof and Aiman Khair Samsol Hairi
Universiti Kuala Lumpur Malaysia France Institute, Malaysia.
Abstract
This paper describes an automatic candy-sorting prototype that uses an artificial neural network (ANN) to recognise colour. A TCS3200 colour sensor records red, green and blue channel values as each candy moves from a feeding tube to the sensing position. An Arduino Nano communicates with a Python-based classification system through a serial connection and controls the sorting mechanism. The predicted colour determines the angle of a servo-driven slider, which directs the candy into the corresponding container. The reported dataset contains 300 samples, with 210 used for training and 90 for testing. The confusion matrix records 88 correct classifications, equivalent to approximately 97.8% test accuracy. The prototype demonstrates the use of a learned classifier in a small hardware application. Its reported performance applies to the tested samples and does not establish accuracy across other candy brands or operating conditions.
Keywords Candy sorting machine, colour classification, TCS3200, artificial neural network, Arduino Nano
1. Introduction
Sorting machines separate objects according to properties such as colour, shape or size. Automation can reduce repetitive manual work and improve the consistency of a sorting process. Colour-based analysis also has applications in quality assessment and sensing. For example, colourimetric sensor arrays have been investigated for soft-drink analysis [1], while sensor-based packaging has been studied for monitoring fish spoilage [2]. These applications provide context for automated sensing, although they use different measurement arrangements from the candy sorter described here.
The TCS3200 colour sensor is used in this prototype to obtain measurements associated with red, green and blue channels. A conventional classifier could compare those values with manually selected thresholds. However, overlapping measurements can make fixed rules difficult to define. An ANN offers an alternative by learning a relationship between labelled measurements and output categories [3]. It still requires representative training data, appropriate preprocessing and evaluation; it does not learn a reliable classification task without human preparation or validation.
The project has two objectives:
- Explore the use of an ANN in a simple hardware application that can provide an introductory example of connecting a learned classifier to a physical mechanism.
- Investigate learned colour classification as an alternative to a manually defined sequence of threshold comparisons.
The input objects are button-shaped, colour-coated chocolate candies. The evaluated categories are yellow, green and blue, matching the labels in the reported test matrix. Other colours may occur in commercial packets, but they are not additional evaluated classes in this study. The following sections describe the sensing arrangement, mechanical design, software workflow and reported classification results.
2. Literature Review
2.1 Automated Sorting
Previous studies have investigated robotic arms for colour-based object sorting [4,5]. Shah and Pandey [6] also describe a concept for an automated sorting arm. A robotic arm uses connected links and joints to position an end effector, allowing an object to be picked up and moved to a selected destination. Such systems illustrate how detection, classification and actuation can be organised as separate stages.
Figure 1 summarises the related sorting workflow discussed in the source manuscript. An object is detected, a control signal is generated, and the object is picked up and scanned before being placed at the appropriate position. This is a general illustration of a robotic sorting sequence, rather than the mechanism used in the candy prototype.

Figure 1. Related robotic sorting workflow illustrated in the source manuscript.
In the described detection arrangement, an ultrasonic sensor mounted on a servo motor scans for an object. The detected position can be expressed in polar coordinates and converted into commands for the actuators. The robot then picks up the object and moves it according to its identified attributes. In contrast, the candy sorter uses a fixed feeding tube and a rotating slider, so it does not require a robotic arm to pick up individual candies.
A compact candy sorter can separate the feeding, sensing and routing operations. The feeder presents one candy at the sensing position; the colour measurement is then classified, and the routing mechanism moves to the corresponding outlet. Keeping those stages coordinated is essential because even a correct colour prediction will produce an incorrect physical result if a candy is released before the slider reaches its intended position.
The choice of sensing method depends on the task. A camera-based system can extract information about shape, size and surface appearance, while a dedicated colour sensor provides a simpler set of channel measurements. This prototype focuses on colour discrimination with a TCS3200 sensor. Its reported test does not compare that arrangement directly with camera-based sorting or establish that an ANN is more accurate than every conventional alternative.
2.2 Artificial Neural Networks
Neural networks can approximate relationships between input features and output categories. In colour recognition, the inputs may be sensor-channel values or features extracted from an image. Paulraj et al. [7] investigated a neural-network model for determining banana ripeness from colour information. Figure 2 illustrates the image-processing sequence discussed in that context. Camera position, illumination and sensor sensitivity can influence the measurements and therefore need consideration when preparing a dataset.

Figure 2. Image-based banana-ripeness workflow discussed in relation to [7].
The illustrated sequence captures and resizes an image, extracts RGB components, rescales the image and constructs histogram features. A neural network then classifies ripeness from those features. This provides a useful distinction between feature preparation and classification. The candy sorter follows the same broad principle of presenting measurements to a trained model, but obtains its colour inputs from a TCS3200 sensor rather than a camera.
Neural-network applications also include eggplant classification [8] and a proposed grading system for fallen rice [9]. Other references address dental-prosthesis colour evaluation [10], fungi identification [11], vehicle colour recognition [12], vehicle detection using colour and depth images [13], and optical-sensor calibration [14]. These examples show the range of classification tasks in which learned models have been investigated. They do not provide interchangeable performance figures, because their datasets, inputs and objectives differ.
For the present application, the relevant question is whether measured colour values can be mapped consistently to the three candy categories. A model should be assessed on samples excluded from training. The physical sorter must then translate the predicted category into a repeatable actuator position. Classification quality and mechanical routing quality are related parts of the system, but should be evaluated separately when diagnosing errors.
3. Methodology
3.1 System Block Diagram
Figure 3 shows three functional parts: input, processing and output. The TCS3200 sensor supplies the colour measurements. The Arduino Nano acts as the hardware controller, while Python is used for the neural-network training and classification workflow. The Arduino and the Python system communicate through a serial connection. The prediction is returned to the control process so that the servo motor can route the candy. This description distinguishes the microcontroller’s control role from the computer-based learning stage; the manuscript does not demonstrate that network training takes place on the Nano itself.

Figure 3. Sensor, Arduino, Python and servo-motor system blocks.

Figure 4. Candy-sorting control sequence.
A candy enters the feeding tube and moves downward under gravity. Motor 1 positions it beneath the colour sensor. The recorded channel values are classified by the ANN, after which motor 2 turns the slider to the selected outlet. The flowchart assigns approximately 90° to yellow, 130° to green and 175° to blue. Motor 1 then releases the candy onto the slider so that it reaches the corresponding container. The sequence is repeated for the next candy. These values are servo angles, correcting the missing degree symbols in the original text.
3.2 Mechanical Design
Figure 5 presents the isometric and front-view sketches, and Figure 6 shows the assembled prototype and wiring. The main control board and colour sensor are housed within a rectangular casing. A feeding tube delivers candies to the sensing mechanism. The motor-driven slider changes the discharge direction, and three round containers collect the sorted candies. This arrangement keeps the colour measurement and outlet selection within a compact structure.


Figure 5. Isometric and front-view design sketches.

Figure 6. Prototype assembly and wiring.
3.3 Software Development and Data Collection
The software links the colour measurements to predicted categories and then to motor commands. The ANN learns from labelled examples of sensor readings. Figure 7 shows the reported workflow: collect the dataset, load the file, divide the data, train the model, make predictions and save the model for use with the serial interface. Testing data are passed through the trained model to assess predictions on samples that were not used to fit it.

Figure 7. ANN training, testing and serial-interface workflow.
RGB-channel readings are collected from the colour sensor and recorded in an Excel file. The manuscript reports 100 samples for each of three categories, giving 300 samples in total. The evaluated categories are yellow, green and blue, as confirmed by Figure 10. Figure 8 shows the spreadsheet format containing three measurement columns and a class label. The channel values are sensor measurements used as model inputs; they should not automatically be interpreted as calibrated display-colour values. Additional representative data could support improvement, but a larger dataset alone does not guarantee greater accuracy.

Figure 8. Example sensor readings and class labels recorded in a spreadsheet.
4. Results and Discussion
The reported dataset was divided into 210 training samples and 90 testing samples. Predictions for the testing samples were compared with their known labels using a confusion matrix. Correct classifications appear on the main diagonal, while off-diagonal entries show disagreements. Figure 9 gives the binary layout for reference; the three-colour experiment uses the multiclass matrix in Figure 10.
| Prediction | Actual positive | Actual negative |
|---|---|---|
| Positive | True positive (TP) | False positive (FP) |
| Negative | False negative (FN) | True negative (TN) |
In Figure 10, columns represent actual candy colours and rows represent predicted colours. The categories are yellow, green and blue. The matrix contains 26 correct yellow predictions, 24 correct green predictions and 38 correct blue predictions. One actual blue sample was predicted as green, and one actual green sample was predicted as blue.

Figure 10. Original three-colour test confusion matrix.
The diagonal therefore contains 26 + 24 + 38 = 88 correct predictions from 90 test samples. For this multiclass task, accuracy is the sum of the diagonal entries divided by the total number of samples: 88/90 = 0.9777…, or approximately 97.8%. The original 97.7% figure truncated this value. A binary true-positive/true-negative formula is unnecessary for calculating the overall accuracy of this three-class matrix.
The authors suggest that changes in candy appearance during exposure to air may have contributed to the two errors. This is a possible explanation rather than a cause established by the reported test. Differences in lighting, presentation or sensor readings would also need controlled investigation. The small test set supports a prototype demonstration, but does not establish performance across different brands, coating conditions or operating environments.
The manuscript does not specify the complete network architecture, training hyperparameters or a repeated evaluation protocol. Consequently, the result should be read as the reported outcome of this prototype test, rather than a fully reproducible benchmark or proof of superiority over a threshold-based sorter. Future comparisons should hold the dataset and physical operating conditions constant.
5. Conclusion
The prototype combines a TCS3200 sensor, Arduino Nano, Python-based ANN workflow and servo-driven slider to sort candies into three colour categories. Its reported confusion matrix records 88 correct predictions from 90 test samples, corresponding to approximately 97.8% accuracy. This demonstrates the feasibility of connecting a learned colour classifier to a small physical sorting mechanism under the tested conditions.
Further development could include additional candy brands, more representative measurements and more than three colours. Such extensions require retraining and independent testing because different coatings and operating conditions can change the sensor readings. Future work should also document the model architecture and evaluate classification and mechanical routing separately. Adaptation to fruit or vegetable sorting would require a new dataset and assessment appropriate to those objects.
References
[1] C. Zhang and K. S. Suslick, “Colorimetric Sensor Array for Soft Drink Analysis,” Journal of Agricultural and Food Chemistry, 55, pp. 237–242, 2007. DOI: 10.1021/jf0624695.
[2] A. Pacquit et al., “Development of a smart packaging for the monitoring of fish spoilage,” Food Chemistry, 102, pp. 466–470, 2007.
[3] G. V Sangamnerkar and K. K. Bhoyar, “A Neural Network Color Classifier in HSV Color Space,” Int. J. Eng. Res. Appl., no. April, 2014.
[4] Y. Jia, G. Yang, and J. Saniie, “Real-Time Color-Based Sorting Robotic Arm System,” in IEEE International Conference on Electro Information Technology (EIT), 2017, pp. 354–358.
[5] R. Szabó, “Automated Colored Object Sorting Application for Robotic Arms,” in 10th International Symposium on Electronics and Telecommunications, 2012, pp. 1–4.
[6] R. Shah and A. B. Pandey, “Concept for Automated Sorting Robotic Arm,” in Procedia Manuf., vol. 20, no. 2017, pp. 400–405, 2018.
[7] M. P. Paulraj, C. R. Hema, R. Pranesh Krishnan and Siti Sofiah Mohd Radzi, “Color Recognition Algorithm using a Neural Network Model in Determining the Ripeness of a Banana,” International Conference on Man-Machine Systems (ICoMMS), 11–13 October 2009.
[8] Y. Saito, T. Hatanaka, K. Uosaki and K. Shigeto, “Eggplant Classification Using Artificial Neural Network,” Proceedings of the International Joint Conference on Neural Networks, pp. 1013–1018, 2003.
[9] F. Takeda et al., “A Proposal of Grading System for Fallen Rice Using Neural Network,” Proceedings of the International Joint Conference on Neural Networks, pp. 709–714, 2002. DOI: 10.1109/IJCNN.2002.1005560.
[10] K. Ueki, H. Wakamatsu, and Y. Hagiwara, “Evaluation of Dental Prosthesis Colors Using a Neural Network,” in 2020 IEEE 5th International Conference on Signal and Image Processing (ICSIP), 2020, pp. 210–214.
[11] M. Wulandari, E. M. Kusumaningtyas, and A. R. Barakbah, “Identification of Poisonous Fungi Basidiomycota Macro Based on Mobile Device Using Neural Network,” in 2018 International Electronics Symposium on Knowledge Creation and Intelligent Computing (IES-KCIC), 2018, pp. 146–151.
[12] K. Kim, P. Kim, K. Lim, Y. Chung, Y. Song, S. I. Lee, and D. Choi, “Vehicle Color Recognition via Representative Color Region Extraction and Convolutional Neural Network,” in 2018 Tenth International Conference on Ubiquitous and Future Networks (ICUFN), 2018, pp. 89–94.
[13] W. Dong, Z. Yang, W. Ling, Z. Yonghui, L. Ting, and Q. Xiaoliang, “Research on vehicle detection algorithm based on convolutional neural network and combining color and depth images,” in 2019 2nd International Conference on Information Systems and Computer Aided Education (ICISCAE), 2019, pp. 274–277.
[14] S. Ueno and O. Sakai, “Low-Cost Color-Sensitive Optical Sensor and Its Calibration by Neural Network,” in 2019 IEEE 8th Global Conference on Consumer Electronics (GCCE), 2019, pp. 1156–1157.
Cite This Work
To export a reference to this article please select a referencing stye below:
Academic Master Education Team is a group of academic editors and subject specialists responsible for producing structured, research-backed essays across multiple disciplines. Each article is developed following Academic Master’s Editorial Policy and supported by credible academic references. The team ensures clarity, citation accuracy, and adherence to ethical academic writing standards
Content reviewed under Academic Master Editorial Policy.
- Editorial Staff
- Editorial Staff
- Editorial Staff

