An Arduino UNO board sketch that programs a color sorting machine that can sort Skittles by their color.
C++ Arduino
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
docs
images
.gitattributes
.gitignore
BottomServo.cpp
BottomServo.h
ColorSensor.cpp
ColorSensor.h
ColorView.cpp
ColorView.h
Context.h
LCD.cpp
LCD.h
LICENSE.md
README.md
TopServo.cpp
TopServo.h
c_color.cpp
c_color.h
skittle-color-sorter.ino

README.md

  Skittle Color Sorter

Details of this project can be found on the Skittle Color Sorter project page under:
http://www.CharmySoft.com/app/skittle-sorter.htm

Introduction

Skittle Color Sorter is an Arduino UNO board sketch that programs a color sorting machine that can sort Skittles by their color.
This is originally for our 3rd year course Project in Computer Engineering (BE).

Instructions

This Skittle Color Sorter consists of a Adafruit TCS34725 Color Sensor to measure color values, a Continuous Rotation Servo at the top to keep the Skittles going down, a Standard Servo at the bottom to move the arm to bring the Skittles to a desired place, and a LCD Display to show information like the number of Skittles.

The circuit:

Color Sensor Top Servo Bottom Servo LCD Display
SDA - pin 4 Pin 13 Pin 10 RS - pin 12
SCL - pin 5 Enable - pin 11
Red - pin 7 D4 - pin 5
Green - pin 9 D5 - pin 4
Blue - pin 6 D6 - pin 3
D7 - pin 2
R/W - ground

Schematic

Because the color sensor might report color values differently due to various factors, such as the lighting condition, the distance between the sensor and the object, etc, before this Skittle Color Sorter can work properly for your specific set of Skittles, each color needs to be calibrated.

To use the sketch in calibration mode, set the following macro definitions to true on ColorSensor.cpp.

// Change the following line to enter calibration mode
#define F_CALIBRATING             true         /**< Is calibration in progress */
#define F_CALI_EMPTY_HOLE         true         /**< Is calibrating the empty hole's color */

You need to firstly set both of them to true, this will make the sketch program try and get the average color of the empty hole. Upload the sketch, open the Serial Monitor and let it run for a while, and you will have the average color of when the hole is empty. Update the the color definition of the empty hole on Context.h with your own data.

/** Calibrated Skittle's Colors. All the colors are defined here. This
    macro will later be used to populate some arrays by changing the
    COLOR_DEF to retrive only needed data. */
#define COLORS_DEFINITION \
  /*       | Identifier   | Color Name      | Calibrated Color          | Color View        */\
  COLOR_DEF( RESULT_RED,	"Red Skittle",		C_Color(97, 73, 62, 117),	C_Color(255, 0, 0) ),\
  COLOR_DEF( RESULT_GREEN,	"Green Skittle",	C_Color(58, 106, 54, 148),	C_Color(0, 255, 0) ),\
  COLOR_DEF( RESULT_YELLOW,	"Yellow Skittle",	C_Color(90, 90, 34, 210),	C_Color(128, 255, 0) ),\
  COLOR_DEF( RESULT_PURPLE,	"Purple Skittle",	C_Color(65, 84, 81, 122),	C_Color(128, 192, 32) ),\
  COLOR_DEF( RESULT_ORANGE,	"Orange Skittle",	C_Color(122, 64, 40, 154),	C_Color(255, 255, 0) ),\
  /* Don't forget to exclude these invalid colors in the HAS_COLOR macro function */\
  COLOR_DEF( RESULT_EMPTY,	"Empty hole",		C_Color(66, 89, 71, 170),	C_Color(0, 0, 0) )

Now, you've had the empty hole's color defined. You can now start calibrating other colors. Go back to the calibration mode macro definition on ColorSensor.cpp and change the F_CALI_EMPTY_HOLE to false. This will make the sketch try and get the average color of a specific kind of Skittles, while the empty hole's color will be correctly ignored.

// Change the following line to enter calibration mode
#define F_CALIBRATING             true         /**< Is calibration in progress */
#define F_CALI_EMPTY_HOLE         false         /**< Is calibrating the empty hole's color */

When calibrating a specific color of Skittles, only put that one specific color of Skittles into the machine, and open the Serial Monitor to see the reported average color values. Test at least 10 different Skittles to ensure the calibration accurarcy. When you get the results, replace the rest of the definition with your own calibrated color values.

When calibration is done, comment out the calibration mode flag (or set it to false). Upload the updated sketch, and the Skittle Color Sorter should be up and running.

Licensing

Please see the file named LICENSE.md.

Author

  • Charlie Chen
    contributor of the Arduino sketch code for this project

  • Paul Boyle
    contributor of the hardware frame for this project

  • Paul Lawlor
    contributor of the hardware frame for this project

Contact