This was, initially, a group project with the goal of creating a machine that was capable of actively sorting 30 marbles based on their material composition, wood, plastic, or metal. As the semester progressed, I had to assume full responsibility for the project due to scheduling issues, but I rose to the challenge and I'm extremely satisfied with my work.
A summary of the operation of this system is as follows.
The servos and sensors are controlled by an Arduino Mega, using an algorithm I created, which I go deeper into further down.
The RGB sensor reads red, green, blue, and clear light values, all of which are highly dependent upon ambient light levels in the testing environment. To calibrate the system for different ambient light levels, a calibration curve was developed with RGBC values against overhead lighting as read by a photoresistor.
Calibration curves are be used to find expected values for red, green, blue, and clear, at any given light level, for each of the three materials. These values are compared to measured values to determine the makeup of each marble.
A similar calibration process was carried out for the IR sensor, which operates by emitting IR light towards the measuring chamber and recording the amount reflected by the marble. Theoretically each material should absorb and reflect different amounts of IR light.
A little more detail about the sorting algorithm. To the right, (or above on mobile devices) you can see the output on the arduino's serial monitor output. The measured data is in the first six columns, with the first five being measurements taken off the marbles, the sixth being the ambient light level taken by the photoresistor.
What's happening here is the ambient light level is being used to determine what the expected values for each material should be. These values are then compared to the measured values, and each value that matches counts as a point in that materials score. The material with the highest score is then selected to classify that marble.
The final column indicates what material was selected based on the score. As you can see here, a marble was sorted successfully on their first attempts, three times in a row. In the event a marble cannot be classified on the first attempt, the marble would remain in the chamber until a subsequent measurement is able to classify it.
The actual measurement and classification process is essentially instantaneous. The time it takes for the marble to move down the ramps and between the servos is just a few seconds, and so this system can successfully sort marbles quite fast.
The full program, which was all developed in the Arduino IDE, is available on my GitHub, link to follow.
Here you can see the final CAD model of the whole sorting machine, which I had been working on simultaneously.
You can see the servo gates on either side of the measurement chamber, which is cut out to allow room for the sensors. At the end is the sorting spout, mounted on the final servo.
Positioned in front of and below the spout during testing were three boxes, one for each material.
The wiring for this project was really pretty straight forward. This diagram on the right is what I submitted as a part of my final report, which I made using Fritzing. It is largely accurate except for the RGB sensor wiring, because my exact model of sensor wasn't available as a model in the software so far as I can find.
I powered the servos and RGB sensor off 5V and the IR Diodes and Photoresistor off 3.3V. The three sensors all returned analog values and this is the main error on the wiring diagram on the right, as the RGB sensor shows its output pins connected to digital pins on the Arduino.
The servos are connected to PWM pins on the Arduino and controlled using the servo library.
Behold, my magnificent sorting machine!
Really shotty structure I know, but I was on a tight schedule and cardboard was my only available material at the moment, this was intended to be a three person project after all.
Despite it's aesthetic short comings, the machine actually worked very well. Feeding the system by hand, up to 8-10 marbles at a time, I was able to sort marbles with, with roughly perfect accuracy, at a satisfying pace.
Unfortunately, due to the loose construction, I could not load all 30 marbles at once without jamming the servo gates, effecting the internal lighting, and destroying the accuracy of the measured data.
If I were to take this project any further in the future, I would focus my efforts on improving the structure with a 3D printed, rigid assembly. Additionally, the system should ideally be reoriented vertically to replace the time consuming ramps.
Much more thorough documentation, complete with early concepts, a wiring diagram, and calibration examples, can be in my final report, available for download below. A video showing some of my first successful sorts is also linked at the bottom of this page.
Here it is in action! I'm really sorry about the quiet, flat narration. It was probably about 4am when I recorded this and I was still living in a value quad on campus (small room with four beds in it) at the time.