Covid-19
Advertisement

Make Your Very Own Arduino-Based Color Candy Sorting Machine

Need to sort your tablet candies by color? Why not automate the process using Arduino?

If you have ever dreamed of having the ability to sort color tablet candies automatically, then this great machine might just make your day. 

But, before you start, you will need to get your hands on some basic components. Apart from a decent milling machine, various drill bits, and other tools, you will also need the following bits and pieces.

arduino color sorting machine
Source: Interesting Engineering

We have included links to some of the products in case you need to buy them: 

Main components:

Ancillary components:

Once you've collected these together or purchased them in, it is time to crack on and start building your very own Arduino-powered color sorting machine.

arduino color sorter disk
Source: Interesting Engineering

The first step is to take the plywood or MDF board and mark out a 1,9 in (5 cm) radius circle using a pair of compasses. This will form the main color sorting disk.

Now cut out the circle/disk using a mechanical saw or good old fashioned hacksaw. Next, drill a hole right in the center for later mounting to the machine.

Using the compass again mark out a smaller circle about 1,5 in (4 cm) in radius on the board. Using a mathematical protractor to mark out eight points each at 45-degree intervals around the circumference of this smaller circle. 

arduino sorter disk complete
Source: Interesting Engineering

These indicate the position of the color piece receptacles for the color sorting machine disk. Drill a small pilot hole at each of the 45-degree marks on the smaller circle. 

Using the spade drill bit, expand the holes for the receptacle on the inner circle to fit your chosen color candies. Now, sand down all surfaces of the wheel and holes.

You can use a motorized lathe or simply use sandpaper. Spray or hand paint the wheel white (or whatever color you like). 

Next, take the aluminum rod and file, or use a milling machine, to flatten both the cut ends, if applicable. Also mill down the rod to make one end thicker than the other, as shown in the instruction video.

arduino sorter rod
Source: Interesting Engineering

Next, drill a hole in the center to match the diameter of the stepper motor axle -- it will be attached to this later. Also, drill a screw thread as required to snuggly fit the stepper motor axle. 

Do the same to the other wider end -- as shown in the video. Drill a screw thread into this second drill hole as well.

This will need to match the screw size at the center of the previously created perforated disk which will be attached to it.

Drill and thread yet another horizontal hole through the other thinner end of the rod; as also shown in the video. Insert a headless screw of the right diameter into the hole as this will be used to attach to the stepper motor axle. 

arduino color sorter rod
Source: Interesting Engineering

Next, take the MDF board and cut it to the same, or similar, dimensions as shown in the video. Mark out the position of screw holes of the servo motor, and other parts, in the same places as shown in the video.

Now drill the holes, as required. With this stage complete, also spray or hand paint the board white (or any other color) and affix the 3D printed parts, as shown. 

arduino color sorting baseboard
Source: Interesting Engineering

The next step is to take the aluminum profile piece, cut to the right length (if required), and affix to the MDF board between the plastic 3D printed brackets. 

The next stage is to create the lollipop-shaped micro-server holder using either 3D printing or hand cutting a piece of MDF. There are no instructions for this given so you will need to devise it yourself -- it may take some trial and error.

You may want to mock this piece up using cardboard prior to finalizing the design either cutting MDF to size or 3D printing. 

arduino sorter base and pole
The complete MDF board with stepper motor, 3D printed brackets, and profiled aluminum rod, Source: Interesting Engineering

Be sure to ensure the micro-server can fit snuggly and securely, as shown in the video (and below image). Insert the micro-server into the lollipop-shaped piece and the entire assembly to the profiled aluminum bar, as shown.

arduino color sorter servo mount
Source: Interesting Engineering

The next stage is to take the plexiglass and cut it to size and shape as shown in the instruction video. Attached this to the appropriate 3D printed bracket on the profiled aluminum bar. 

Again there are no instructions for this so it may take some trial and error.

arduino color sensor assembly
Source: Interesting Engineering

Now take the color sensor and wire up as instructed. Then affix to the plexiglass assembly, as shown above.

Thread all wiring through the hole on the MDF base next to the stepper motor, and back up through the rectangular-shaped hole on the MDF board too. 

Affix four circular 3D printed pads (or similar) to the base of the MDF board to allow enough room for the wiring to run underneath the board. 

arduino color sorted base
View of the bottom of the MDF board at this stage. Not the wiring entry and exit points and plastic feet, Source: Interesting Engineering

The next stage is to thread the previously prepared aluminum rod onto the stepper motor in the center of the MDF board. Now screw the sorted disk onto the other free end of the assembly, as shown below.

arduino color sorted disk attachment
Attach the sorting disk. Note the position of the color sensor, micro-servo, and other pieces, Source: Interesting Engineering

Next, create a custom PCB design Gerber file, as shown in the video (no file provided by the creator). You can use the services of companies like JLCPCB to print it, or simply use a sandwich board for testing purposes. 

Here is the circuit design:

arduino color sorted circuit
Source: Interesting Engineering
arduino color sorter custom board
Close up of custom created PCB board, Source: Interesting Engineering

Now add the required PCB wire connectors, and solder, as shown in the video. Next, assemble the required components onto the circuit board, like the Arduino Nano, etc.

The next step is one of the most important; the actual code. Here it is in its full glory. Feel free to play around with the parameters to your liking. 

#include 
#define S0 2
#define S1 3
#define S2 4
#define S3 5
#define sensorOut 6
Servo topServo;
Servo bottomServo;
int frequency = 0;
int color=0;
void setup() {
 pinMode(S0, OUTPUT);
 pinMode(S1, OUTPUT);
 pinMode(S2, OUTPUT);
 pinMode(S3, OUTPUT);
 pinMode(sensorOut, INPUT);
 // Setting frequency-scaling to 20%
 digitalWrite(S0, HIGH);
 digitalWrite(S1, LOW);
 topServo.attach(7);
 bottomServo.attach(8);
 Serial.begin(9600);
}
void loop() {
 topServo.write(115);
 delay(500);
 
 for(int i = 115; i > 65; i--) {
 topServo.write(i);
 delay(2);
 }
 delay(500);
 
 color = readColor();
 delay(10); 
 switch (color) {
 case 1:
 bottomServo.write(50);
 break;
 case 2:
 bottomServo.write(75);
 break;
 case 3:
 bottomServo.write(100);
 break;
 case 4:
 bottomServo.write(125);
 break;
 case 5:
 bottomServo.write(150);
 break;
 case 6:
 bottomServo.write(175);
 break;
 
 case 0:
 break;
 }
 delay(300);
 
 for(int i = 65; i > 29; i--) {
 topServo.write(i);
 delay(2);
 } 
 delay(200);
 
 for(int i = 29; i < 115; i++) {
 topServo.write(i);
 delay(2);
 }
 color=0;
}
// Custom Function - readColor()
int readColor() {
 // Setting red filtered photodiodes to be read
 digitalWrite(S2, LOW);
 digitalWrite(S3, LOW);
 // Reading the output frequency
 frequency = pulseIn(sensorOut, LOW);
 int R = frequency;
 // Printing the value on the serial monitor
 Serial.print("R= ");//printing name
 Serial.print(frequency);//printing RED color frequency
 Serial.print(" ");
 delay(50);
 // Setting Green filtered photodiodes to be read
 digitalWrite(S2, HIGH);
 digitalWrite(S3, HIGH);
 // Reading the output frequency
 frequency = pulseIn(sensorOut, LOW);
 int G = frequency;
 // Printing the value on the serial monitor
 Serial.print("G= ");//printing name
 Serial.print(frequency);//printing RED color frequency
 Serial.print(" ");
 delay(50);
 // Setting Blue filtered photodiodes to be read
 digitalWrite(S2, LOW);
 digitalWrite(S3, HIGH);
 // Reading the output frequency
 frequency = pulseIn(sensorOut, LOW);
 int B = frequency;
 // Printing the value on the serial monitor
 Serial.print("B= ");//printing name
 Serial.print(frequency);//printing RED color frequency
 Serial.println(" ");
 delay(50);
 if(R<45 & R>32 & G<65 & G>55){
 color = 1; // Red
 }
 if(G<55 & G>43 & B<47 &B>35){
 color = 2; // Orange
 }
 if(R<53 & R>40 & G<53 & G>40){
 color = 3; // Green
 }
 if(R<38 & R>24 & G<44 & G>30){
 color = 4; // Yellow
 }
 if(R<56 & R>46 & G<65 & G>55){
 color = 5; // Brown
 }
 if (G<58 & G>45 & B<40 &B>26){
 color = 6; // Blue
 }
 return color; 
}

Once you are happy with the code, and it has compiled successfully, simply upload it to the Nano. 

The next step is to create the On/Off switch and main circuit housing. Take the 3D printed box and attach the micro fan as instructed. 

color sorted arduino box
Main circuit housing and fan assembly, Source: Interesting Engineering

Feed the wiring from the main color sorter assembly, and wire up/solder as required. Also, wire in the main On/Off switch and main power input assembly to the PCB board.

See the video for details on this critical stage.

arduino color sorter circuit
The wired up custom PCB board with components inside 3D printed box assembly, Source: Interesting Engineering

Next, add and hinge the box closer doors, as shown. You may need some small lengths of wire or cut a paperclip into appropriately sized lengths for this.

The next stage is to create the colored object sorting ramp. This will affix to the micro-server assembly. 

As no instructions are provided you might want to mock this piece up first in cardboard and either 3D print later or hand-make out of plastic-card or similar material. 

arduino color sorter ramp
The completed sorted ramp, Source: Interesting Engineering

Next, attach the ramp to the micro-servo. You can now place the four paper cups, or similar receptacles, arranged as shown in the video and below.

These will receive the sorted colored objects from the ramp. 

arduino color sorter cups and ramp
Source: Interesting Engineering

The next step is to cut a length of plastic tubing to the desired size to make the colored object hopper. This will need to have a slightly larger diameter to the colored objects, like Cadbury Gems, and receptacles on the sorting disk. 

Use the final 3D printed bracket to hold a supporting arm to the profiled aluminum rod and place the hopper tube in place above the disk. This will likely take some trial and error to get right (see the red arrows indicating the required parts below).

arduino color sorter hopper assembly
Final colored object hopper assembly marked with red arrows, Source: Interesting Engineering

Now all that is left to do is to fill the hopper with your desired tablet candies, connect the power and fire it up. 

Watch in amazement as your carefully crafted Arduino code and machine work in perfect symphony to sort the candies into separate cups.

Why not reward yourself by eating some, perhaps all, of them at your leisure!

Interesting Engineering is a participant of the Amazon Services LLC Associates Program and various other affiliate programs, and as such there might be affiliate links to the products in this article. By clicking the links and shopping at partner sites, you do not only get the materials you need but also are supporting our website.

Advertisement
Follow Us on

Stay on top of the latest engineering news

Just enter your email and we’ll take care of the rest:

By subscribing, you agree to our Terms of Use and Privacy Policy. You may unsubscribe at any time.