Introduction: M&M Color Sorter
This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com)
Step 1: Gather Materials:
The following items have links associated with them on possible places to purchase them. There are many other ways to find these items (often less expensive)...Shop wisely!
2 Hex bolts, Stainless steel 18-8, 1/4"-20 x 1/2" (And Accompanying Nuts)
Step 2: 3D Print Parts
I 3D printed four parts for this project.
- The delivery tube is what you drop the M&Ms into to begin the sorting process.
- The spinning disc loads up M&Ms in the 6 holes and carries them from the end of the delivery tube, to the color sensor, and finally to the drop out point.
- The stationary disc has one hole in it, designed to line up with the spinning disc one hole at a time in order to individually sort the M&Ms.
- The slide carries the M&Ms once they have dropped from the enclosure, to the designated color's container.
Step 3: Build Circuit
Step 4: Prepare All Other Parts
- Cut out two pieces from the basswood sheet, each 8 inches long with the full width. Then starting from the top, drill 1/4 inch thread holes 1/2 inch apart down the center of each piece. This allows for personalization on the height of the piece. ( I chose to use the second hole down to mount my project)
- Cut 2, 3 inch long, 1/2 inch wide strips from the balsa wood, these will be attached to the slide.
- Cut 4 strips of velcro from the tape. Mount two strips on the outsides on both the breadboard and the arduino. Then mount the other sides to inside of the two sides of the box. This velcro allows for much easier wiring and debugging later on.
- Bend a strip of brass into a "C" shape, this is important to mount the servo below the enclosure.
- Cut a 2.5 inch piece of a brass strip, and bend the top to wrap around the servo horn. (I would also recommend gluing this piece. The remaining strip should be bent evenly to give the slide the angle that you want. This is another place to adjust the height of your sorter and distance of the containers.
- Spray paint desired pieces black. However, it is important to not paint either of the discs inside the enclosure. The color sensor has to initialize white to read colors properly. Don't forget to paint the nut and bolt!
- Drill holes in enclosure: For battery wires, for bolts on either side, for delivery tube (in the lid), and for drop off point. I also made a small key notch on the side of the drop off point to bring the servo cord up through the enclosure without obstructing the M&M.
- Place velcro strips on the top of the brass connected to the servo, and the underside of the slide (once spray painted).
- Glue the stepper motor armature into the small hole in the spinning disc. Then measure the width of the box, and cut a piece of the basswood that matches that width in length, and is 1 and 1/2 inches in width. Then glue the top of the stepper motor to the center of this piece of basswood.
- Cut a two inch long strip of the brass, and then attach this to the top of the piece of basswood that has the stepper motor on the underside. (This will serve to hang the color sensor over the disc) Then attach a small velcro strip to the underside of this hanging brass, and underside of the color sensor.
- Cut poster board into a 9" by 9" square.
Step 5: Assemble Project
- Glue the stationary disc to the bottom of the enclosure, lined up with the hole that was drilled for the drop off point.
- By holding the piece of basswood, lower the stepper motor and disc into the box, and arrange it so that it hovers slightly over the stationary disc, and then fix the piece by putting hot glue around all of the edges of the basswood to the box.
- Attach "C" shaped brass to the bottom of the enclosure, and mount the servo onto it. It may be helpful to have the slide on the servo at this point to help position it.
- Assemble circuit inside of the enclosure. I found that the piece of wood in the center helped to group and clean up wires inside the enclosure.
- Attach the delivery tube to the lid, through the hole that was drilled for it. This tube needs to barely touch the spinning disc in the enclosure, so the easiest way to position this piece is to hold it over that disc with the lid and then glue it in the position that you find to work.
- Attach velcro strips to the back right of the enclosure, close to the hole that was drilled for the battery wires. The other side of the velcro should be attached to the 9V battery. By feeding the adapter wires through this hole, we can easily snap on and off the power to the project, as well as replace the battery.
- Screw the stands into the sides of the box and fix them with the nut. This is where you can customize your height.
- Glue the bottom of the stands to the poster board, preferably on the edge so that you have room to work with when setting your containers.
- Assemble salt and pepper shakers (without tops) along poster board. Move the back and forth and manually drop M&Ms through in order to find the right places to set the containers. Once you find the right locations. Velcro both the spot on the poster board and the bottom of the container. Once you upload the code, you will have to make slight adjustments to the location of the servo with given colors based on where you put the containers. **Remember, you can still bend the brass that provides the angle for the slide**
- Once you are happy with the code, re position the arduino on its side in the box, make sure that one of the holes on your spinning disc is aligned with the hole on the stationary disc, and screw the top on.
Step 6: Code
First unzip the libraries folder, and import it into your arduino IDE libraries.
There are two codes that you need to use.
One is called Color Read, and this is the one you will need to upload first, in order to debug your program to set the right colors. Simply open up the serial monitor and while placing in your M&M, note the RGB values, and change them in the code corresponding to color of the M&M you put in. Whenever you make a change to the project that affects the color sensor, make sure you re calibrate your colors using this.
The second is your actual project sketch, called MMs Sorter.
The following is a description of how each part of the code works:
- There are several functions that initialize the color sensor and set scaling factor of colors based on its current environment. From here the main loop runs the color sensor, and based on its frequency reading, it will evaluate conditionals to determine which color the M&M is, and therefore where it should be dropped off. Inside each conditional you can see a unique servo location, and then a 1/6 full rotation in order to drop the M&M down the hole and down the slide.
Explanations of the functions:
- TCS_Init(): Maps the pins of the Color sensor and powers on the color sensor
- TSC_FilterColor(int Level01, int Level02): Selects filter color (Red, Green, or Blue)
- TSC_Count(): Increments the array to toggle filters
- TSC_Callback(): Filters without colors one at a time (Precursor to White Balance)
- TSC_WB(): Determines what white is in current environment
- ISR(TIMER2_COMPA_vect): Timer for the servo
- void servoInit(): Setup for servo
- void servoSetPosition(uint16_t highTimeMicroseconds): Function which sets servo to a location
With the top off and the arduino still plugged in to the computer, use your serial monitor to debug any problems. Make any changes to servo position, and color frequencies.
Step 7: Possible Improvements
Incorporate a more powerful stepper motor.
This stepper motor does the job, but it does not have much torque behind it. The project might run more smoothly with more torque.
Incorporate a faster color sensor.
This color sensor needs at least 4 seconds to read the color of an M&M. If you are willing to foot the bill, it might be better to go with a faster color sensor to sort your bag of M&Ms in seconds!
It was my original plan to incorporate a touch sensor to turn sorter on and off, however I found it more simple to go with a hard on and off button. (Go the extra awesome mile!)
Here is some example code with an arduino compatible touch sensor lighting up an LED, and keeping it on until you touch the sensor again.
We have a be nice policy.
Please be positive and constructive.