Identification and Control System for Colored Pill Assortment

Hello Everyone,

I'm a College student and for my capstone project I have decided to create a control system that will assort pills by colour.

This system detects the colour of a small, pill-like object (a skittle) and with this information activates a corresponding actuator (gate) and ultimately sorts the skittles by colour in different baskets. I am posting here looking for guidance in coding and potential ideas that would assist in the fruition of this project. I am totally new to Arduino with a medium-level background in coding.

I have decided to use the Arduino Uno along with the TCS3200 3Pin Color Recognition Sensor Module as components so far.

Thank you for all your help!

Is this just a proof of concept project, or are you looking to build something that could be a real product?
Servos like those used in model aircraft will allow you move a gate. In the real world pneumatic actuators would be used, but that's a whole different ball game.

MrJKF:
I am posting here looking for guidance in coding and potential ideas that would assist in the fruition of this project

Break your learning into small parts. Write a short program to figure out how the colour sensor can be used - and how effective it is. Write another short program to learn about the control of your gates.

It will be much easier to get help here if you have a short program that just focuses on one thing.

You may find some useful stuff in Planning and Implementing a Program

...R

Thank you for all your responses!

mikb55:
Is this just a proof of concept project, or are you looking to build something that could be a real product?

I am going to be building this, I will be creating a fully working pill assorting system.

Robin2:
Break your learning into small parts. Write a short program to figure out how the colour sensor can be used - and how effective it is. Write another short program to learn about the control of your gates.

It will be much easier to get help here if you have a short program that just focuses on one thing.

You may find some useful stuff in Planning and Implementing a Program

...R

Thank you for your idea, I'll check out the link. I don't have much experience in programming, I know the fundamentals but I usually struggle with the start-up process

To anyone else perusing this thread, does anyone have any examples of how I would code a program to take an input from the colour sensor (some if else statement) and have the program input a "command" to a servo/gate?

mikb55:
Is this just a proof of concept project, or are you looking to build something that could be a real product?
Servos like those used in model aircraft will allow you move a gate. In the real world pneumatic actuators would be used, but that's a whole different ball game.

Surely, this is just an academic exercise?

In reality, wouldn't all pills coming off a production line be exactly the same colour and composition?

I'm a College student and for my capstone project...

What's your major?

I am totally new to Arduino with a medium-level background in coding...

...I don't have much experience in programming...

To anyone else perusing this thread, does anyone have any examples of how I would code a program to take an input from the colour sensor (some if else statement) and have the program input a "command" to a servo/gate?

If-statements are probably the key...*

The [u]Button Example[/u] reads the state of a button and turns on an LED. If you can read a button, you can (probably) read a color sensor, and if you can turn-on an LED, you can turn-on a solenoid or motor. (The solenoid/motor will require some electronics unless you're using a servo motor with the electronics built-in.)

I recommend you read-through the [u]Arduino Language Reference[/u] and look at some of the examples. If you understand basic programming concepts, the programming should be fairly easy.

It could get a more complex depending on what you need for a user interface.

, I know the fundamentals but I usually struggle with the start-up process.

The biggest mistake beginning programmers make is to try and write the whole program at once. Start with something like the Button Example, and "develop" your program by adding one or two lines at a time. Add a line or two of code and test (and debug if necessary) before proceeding. Send-out messages to the Serial Monitor so you can "watch" variables, or see what your program is doing.

Of course professional programmers write more than one or two lines at once, but nobody sits down and writes the whole program without testing along the way. (And of course, most pros are working on larger programs.)

This also takes a bit of practice & skill... You can't just start at the top and work down... The program has to "make sense" to the compiler and the compiler has to see a "complete program". For example, if you delete the last half (or just the last few lines) of a program, you'll usually get LOTs of errors.

* The two most important concepts in programming are conditional execution (if statements, etc.) and loops (doing something over-and-over, usually until some condition is reached).

JohnLincoln:
Surely, this is just an academic exercise?

Yes, this is my academic capstone project where i must design and create a process control system. The "pills" I would be using in this experiment would be skittles. I use the term pill as a professional label for my project proposal.
So, no this will not be a product used by an form of professional industry, it is more of a an evaluation of the skills I have learned in the program to date.

Thank you for your response DVDdoug!

DVDdoug:
What's your major?

I am enrolled in the Electrical Engineering Technology and Controls Systems Program.

Thank you everyone for the wealth of knowledge I will use it to the best of my ability and keep this thread updated with results! If there is more you would like to share feel free!

For separating purposes the industry often uses compressed air, its mechanically less complex than gates or traps, maybe you have a look in that direction also. Controlling a vent is basically the same as a relais.

Get ready to kick yourself MrJKF, ... maybe.

Leds can detect as well as emit light. And one result of that is that colored bulb leds (red, green, blue, etc, can be used to detect colored light.

It works well enough that one man invented a liquid analyzer that uses them to measure light absorbed when passing through the liquid. Different liquids made different profiles and the device has many such stored.

Also be prepared for fun with colors. What looks yellow to humans may be red and green mixed or it may be yellow. Regardless of color detector, you may need to establish profiles for your skittles!

Learn the do many things at once lesson. It will make life easier. Properly done, you will need less code and debugging will be easier.

Many things at once --- Input is a Thing. Every input should have its own piece of code inside of loop(). The input sections should update variables regularly and other code reads them. The input code doesn't run because some other code needs data, it just runs all the time (every iteration of loop()) or at regular intervals dependably.
Contact button/switch code, for example, needs to watch not just for pin state change but the noise generated for 2 or more ms that can appear to be dozens of button presses. And doing that right takes up almost no cpu time. The code watches pin state for changes and it turns that into button state for process and/or output code to read, abstracting data into meaning which is easier for the rest of the sketch to use.
It should run a step every time that loop() goes around which should take less than 1 millisecond. 1 ms = 16000 cpu cycles on a 16MHz Arduino can do a lot when nothing waits which is how you make many things run "at the same time", they all get a turn to take just 1 step then loop() for the next, etc.

Processing is a Thing. That's the Think Code. State machines usually live there. Input changes usually drive this code and it often drives the Output Code.

Output is a Thing. From serial printing to motor running, it's Output and you can make it smart so it doesn't burn up a relay or overflow serial monitor with text or handle different hardware and/or buses.

Many Things at Once and they all run as separate pieces. An Output Thing can be replaced with a different but similar Output Thing without disturbing the rest of the code either at all or more than minimally. Same with Input Things. Your Code Things can be more easily reused if you don't give in to the temptation to merge/specialize Input/Process/Output.

Hope any of that helps. Hope you have a few days to spend messing with other people's code examples. :slight_smile: It's a great fast-track to cutting your own coding teeth.

GoForSmoke:
Learn the do many things at once lesson. It will make life easier. Properly done, you will need less code and debugging will be easier.

These links give substance to that
Several Things at a Time
Planning and Implementing a Program

...R

That has substance and the 1st address in my signature space gives a complete commonsense lesson with code on the subject as well, and it's fairy well covered elsewhere on the web. But it takes practice and we all have different views about the importance of different things on our own experience.

not sure why no one pointed out that sorting colored M&M candies is old hat.

slow version :

slow

faster

I think a lot of the slow aspect is to move the part and have large bins.
if I was to do this, I would use long skinny bins and move the arm a much shorter distance.
you could have chutes that run to larger bins.

on the last video, I think the color sensor is on the marble that is next in line. it has a long time to sit while the piston is activated.

Thank you all for your help! It is greatly appreciated, I think I now have all the resources I need, I will post an update on the program and design when it is complete.

This is a great community, with awesome people!

Hello Everyone,

As an update I have decided upon using 3 servo motors and a color sensor in order to create my process.

Imagine with me, if you will, one servo motor will be at the top of the "chute" pulling skittles(M&Ms) from the dispenser and allowing the color sensor to read them.

The other two servo motors will have "doors" or flanges connected to them and are programmed to divert the object to its respective bin when prompted by the corresponding color reading from the sensor.

I have a code currently that reads in the color in RGB values and lights up a corresponding light.

My questions that I come to you all with are:

When programming 3 servo motors, do you have to attach(in the program) the servo to the pin you want to access and then write the reaction code underneath?
(Basically, is this how I declare the servo motor i am about to write to each time?)
e.g.

//i want to tell the servo at pin 5 to increment to a certain point and then come back.

myServo.attach(5)
~code~

//now i want to tell my servo at pin 6 to react when it sees a blue M&M and my servo at pin 7 to react when it sees a red M&M

if(blue ~code~)
myServo.attach(6)
~code~

if(red ~code~)
myServo.attach(7)
~code~

Look at the knob example in the IDE examples (File, Examples, Servo). The knob example shows how to include the Servo library, create a servo object, attach the servo and write movement commands to the servo. For multiple servos, create a servo object for each servo and, in setup() attach each one to a different pin. Then you can write position commands to each servo by name.

Ah, beautiful! Thank you very much.

I might be asking a few more questions as the programming comes along. Thank you for your time.