Arduino Color Sorter Project - HowToMechatronics
Arduino Color Sorter Project - HowToMechatronics
WHAT'S NEW? DIY VENDING MACHINE - ARDUINO BASED MECHATRONICS PROJECT FOLLOW ME ON:
8
Shares
Home Projects
In this article I will show you how you can make an Arduino Color Sorter. You can watch the following video
or read the written article below.
L AT E S T
DIY VENDING MACHINE – ARDUINO BASED
MECHATRONICS PROJECT
Dejan Nedelkovski
Design
POPULAR
All we need for this Arduino project is one color sensor (TCS3200) and
two hobbyist servo motors, which makes this project quite simple but
yet very fun to build it. In the rst place, using the Solidworks 3D
modeling software I made the design of the color sorter and here’s its
Arduino Radar Project
working principle:
Dejan Nedelkovski 333
Initially, the colored skittles which are held in the charger drop into the platform attached on the top
servo motor.
Then the servo motor rotates and brings the skittle to the color sensor which detects its color.
F O L LO W M E !
After that the bottom servo motor rotates to the particular position and then the top servo motor
rotates again till the skittle drop into the guide rail.
Here you can download the 3D model, as well as, the drawings with all dimensions needed for building this
Arduino project.
Arduino Project - Color Sorting Machine 3D Model Assembly Solidworks Files 2.01 MB
Download
Arduino Project - Color Sorting Machine 3D Model Assembly STEP File 1.81 MB How To Mechatronics
Download
Once I got all the parts ready, I started assembling them. First I assembled the outer parts using a glue gun.
Then using all-purpose glue I glued the two servo motors on their platforms and attached them to the
assembly.
After that again using a glue I attached the guide rail on the bottom servo motor as well as the support and
the platform needed for the top servo motor.
Next, I inserted a switch and a power jack for powering the Arduino with a 5V adapter and on the third
platform I inserted the color sensor.
You can get the components needed for this Arduino Project from links below:
*Please note: These are a liate links. I may make a commission if you buy the components through these links.
I would appreciate your support in this way!
At this point, rst we need to program the Arduino and then nish the assembly. Here’s the Arduino Code:
So, we need to include the “Servo.h” library, de ne the pins to which the color sensor will be connected,
create the servo objects and declare some variables needed for the program. In the setup section we need
to de ne the pins as Outputs and Inputs, set the frequency-scaling for the color sensor, de ne the servo
pins and start the serial communication for printing the results of the color read on the serial monitor.
In the loop section, our program starts with moving the top servo
motor to the position of the skittle charger. Note that this value of 115
suits to my parts and my servo motor, so you should adjust this value
as well as the following values for the servo motors according to your
build.
Next using the “for” loop we will rotate and bring the skittle to the position of the color sensor. We are
using a “for” loop so that we can control the speed of the rotation by changing the delay time in loop.
Next, after half a second delay, using the custom made function, readColor() we will read the color of the
skittle. Here’s the code of the custom function. Using the four control pins and the frequency output pin of
the color sensor we read color of the skittle. The sensor reads 3 di erent values for each skittle, Red, Green
and Blue and according to these values we tell what the actual color is. For more details how the TCS3200
color sensor works you can check my previous detailed tutorial about it.
Here are the RGB values that I got from the sensor for each skittle. Note that these values can vary because
the sensors isn’t always accurate. Therefore, using these “if” statements we allow the sensor an error of
around +-5 of the tested value for the particular color. So for example if we have a Red skittle, the rst “if”
statement will be true and the variable “color” will get the value 1. So that’s what the readColor() custom
function does and after that using a “switch-case” statement we rotate the bottom servo to the particular
position. At the end we further rotate the top servo motor until the skittle drops into the guide rail and
again send it back to the initial position so that the process can repeated.
After uploading the code I secured the Arduino Board using a glue gun.
Then using a transparent plastic bottle I made the charger and together with the top part glued it to
assembly and nished the project.
China's Largest PCB Prototype Manufacturer, 290,000+ Customers & 8,000+ Online Orders Per Day
10 PCBs Price: $2 for 2-layer, $15 for 4-layer, $74 for 6-layer
Arduino Arduino Project Color Sensor Color Sorter Color Sorting Machine
R E L AT E D P O S T S
ARDUINO TOUCH SCREEN MUSIC PLAYER AND ALARM MECHATRONICS FINAL YEAR PROJECT
CLOCK PROJECT Dejan Nedelkovski 54
Dejan Nedelkovski 29
HOW TO MAKE A COMPASS USING ARDUINO AND DIY VENDING MACHINE – ARDUINO BASED
PROCESSING IDE MECHATRONICS PROJECT
Dejan Nedelkovski 14 Dejan Nedelkovski
66 RESPONSES
I’m just wondering how the arduino is powered. So the code is uploaded to the arduino
from the computer, but then it is unplugged and powered with an adapter? Is this then
just plugged into a wall outlet?
REPLY
REPLY
Arduino Blog – This Arduino machine will sort your Skittles by color July 20, 2016
[…] do it for you? As part of a recent tutorial, Dejan Nedelkovski has built what we calls
the “Arduino Color Sorter” using a TCS3200 color sensor, two hobbyist servo motors, and
an Arduino […]
REPLY
Hi, I was just wondering how you connected the GND and 5V from all three components
directly to the Arduino Nano without having to use a breadboard or a shield. Since there
is only one pin for 5V and two pins for GND and you have 3 components.
REPLY
Thanks!
I have soldered together 4 jumper wires.
REPLY
Can you by chance send me the les in a pdf form my computer cant open the slddrw
le with out buying a 5 dollar app.
REPLY
The drawing les are in a .rar les which is quite common le format
which can be easily opened or/and extracted, even online. I hope you
can nd a way to open it.
REPLY
hello master , I want to ask what the switch and power jack used
REPLY
Please recheck the article, I have add links so you can see what switch
and power jack can be used.
REPLY
sir, your ideas was brilliant. i want to develop this project for my nal year project (FYP) .
Can you guide me more on this project ? i think i want to add sound after the sorting for
the development. hope to hear from u soon
-malaysia-
REPLY
Thanks. Well I think the video and the article it self covers everything
you need in order to make this project, you got the 3D model,
drawings, circuit schematics and source code.
REPLY
Hello sir, i am really inspired by your doing. Anyway i just want to know since you are
using Arduino Nano, will it work the same way if i use Arduino Uno? I need a lot of
guidance. Thanks
REPLY
REPLY
REPLY
Solidworks.
REPLY
Hi Dejan,
You did a great project. I am trying to use the TCS3200 Color sensor with 4-led on the
board directly (no legs … the sensor has round shape …please see this link:(LINK
REMOVED). I have noticed that the reading of colors varies a lot while testing the sketch
in arduino. Does it means that these led around should be closed to the sensor ship to
get accurate values as on your project, or shall I buy one as on your project ?
Kindly advise ,
Regards,
Nabil
REPLY
Yes, the readinds are that much stable, the same case was with mine
sensor. Though, the closer the sensor is to the color the better.
REPLY
REPLY
REPLY
Hi sir
How to adjust the value in Top servo motor rotates and brings the skittle to the color
sensor which detects its color.
REPLY
REPLY
I bought the TCS230 TCS3200 color sensor above. So it arrived today. But the color
sensor doesnt’t t on the berboard. the square on the berboard is small to put the
sensor. How do you put it into berboard?
the square size of the berboard is 2.5cm X 1.3cm.
but the size of the color sensor is 3cm X 1.3cm.
REPLY
Well simply increase the berboard whole and the sensor will t.
REPLY
REPLY
Normal ones…
REPLY
i am done with model and the project is working well. just the color sensor is getting
confuse :/
i have set the frequencies as per my color sensor . but still the bottom servo rotates at
di erent angle for same color
what should i do ?
REPLY
Well the sensor isn’t stable and makes errors when reading. Plus its
readings depends on several factors like obviously the color you are
reading but also the ambient lighting as well. So if it’s darker you will
probably get di erent readings compared if you are using the same
color object and test it on daylight.
In order to make it working you must test the color readings for each
object and according to your readings adjust the R, G and B that are
found values at the bottom of the code.
REPLY
hi..İt is great project! I did this but bottom servo not working.
REPLY
REPLY
hello , i´ve tried to replicate your project but my servos just wont move, and i´ve been
using di erent power supplies even a 5v-2A power supply but it doesnt work,
could you tell me what power supply did you use to power your electronics???
any advice you can give me??’
REPLY
What kind of motor are us using? Did your try to swap the two
motors? Is it working that way?
REPLY
Hi. I followed your instructions and code but the two servos are not running. what might
be the reason?
REPLY
It can be anything. Can you try to be more speci c. Also double check
your connection.
REPLY
I try same project and copy your code into my Mega2560. I have following the schematic
diagram. But, my bottom servo not working. Whats wrong?
Thank you
REPLY
Thanks. What kind of servo motor are you using? Double check your
connection.
REPLY
Hi, and Thanks for the inspiration for my next project. Just waiting on the delivery of my
TCS3200 sensor now.
While reading and understanding your code I’ve spotted 2 typo errors (which don’t a ect
the functionality, of course, just my initial understanding of how it works). In lines 116
and 128 you repeat the comment “// printing RED color frequency” but those lines
should say GREEN and BLUE respectively.
REPLY
Hai sir.For this project we have to connect arduino board by usb and with power adapter
or not.
REPLY
REPLY
Hi, please help me, when I try to put blue item on the color sensor, it gives out green
color
REPLY
You must manually adjust the sensor values to match the real color.
REPLY
can i use SG90 9g servo motor for both positions?? by using thin(very light) plywood…!!!!!!
REPLY
REPLY
Hi,
For the if statements at the bottom of your code, why do you only use two of the colors
(i.e.
if(R32 & G55){
color = 1; // Red
}) -> only red and green are used. Why don’t you use red, green, and blue in each of the
statements?
Thanks,
REPLY
Hi, that’s because the sensor outputs were not that precise and
accurate and I was getting very similar values, close to each other, for
each R, G and B. So in order to better separate, or recognize the colors
I made the “if” statements in such a way to use only two colors for
de ning the colors I needed.
REPLY
Hello! How to manually adjust the sensor values to match the colors? Thanks for the
answer
ps great project!
REPLY
Print the values you are getting into the Serial monitor and then adjust
them in the readColor() custom function.
REPLY
Hey there.
I built the whole model and got the same exact pieces as you but… My TCS3200 has red
leds on the board, not white ones.
Also, the values it reads are all around 15000 for each color (R, G or B).
Any idea on why this happens?
REPLY
Hi there, well you probably have a di erent version of the module, but
it should be a problem, you can make it work. You just have to adjust
the values for each color in the “if” statements in the readColor()
custom function.
REPLY
Hello, I have one question – while trying to setup everything as explained here, I can’t get
my sensor motor to rotate based on colour change. It simply stays non moving. Motor is
ne, replacing it with working one yields same result. Do you have any hint as to what
could be the issue? Thanks.
REPLY
Hello, the problem is probably that the values you are getting from
your color sensor doesn’t match with my values. First you must see
what values you are getting from your color sensor for a particular
color, and then adjust these values in the readColor() custom function,
where the last “if” statements are.
REPLY
Hello Dejan,
This is a really good project but I have a problem. One of the servomotors moves at the
same directions repeatedly but the bottom servomotor doesn’t move at all. What should
I do?
REPLY
You are not getting the same values for the colors as mine, so you
should adjust them.
REPLY
Hey man, i have a little (huge) problem, when i try to upload the program it says
“`readColor` was not declared in this scope” i don´t know why it happens and i checked
the whole program but it´s the same as this page´s.
I´m so bad with Arduino so i hope you can help me to solve it.
REPLY
You have a typo in the code, you probably haven’t copied it properly.
REPLY
nice project…the dimensions are in mm i guess..i was confused with the scale 1:5 in the
diagrams..
REPLY
hi sir
I’m sorry if i can’t write in well
i wanna ask something, can this arduino with color sensor to read average color in 2 sec
for “telling” what is this based on color
like a red color in apple, because apple not really red color. I think if we take an average
value in few sec, this arduino can tell this an apple, ect
if you can help me please contact me, cause I’m interested from yours idea
REPLY
Sure it can be used for such a purpose. But it depends what will you
compare the red apples to. For example if you compare them to green
apples it would be probably be easy to distinguish the colors.
REPLY
L E A V E A R E P LY
Comment
Name* Email*
Website
S U B MIT
H O W T O M E C H AT R O N I C S F O L L O W H O W T O M E C H AT R O N I C S O N DISCLOSURE
SOCIAL MEDIA
HowToMechatronics is an education website in the HowToMechatronics is a participant in the Amazon
area of Mechanical, Electrical and Computer Services LLC Associates Program, an a liate
Engineering. Tutorials, Tips, Tricks, How It Works, advertising program designed to provide a means
Projects, Examples, Source Codes, Download les for sites to earn advertising fees by advertising and
and much more can be found here. linking to Amazon.com