Introduction: Arduino Skittle Sorter Machine
This simple Skittle sorting machine is powered by an Arduino Nano, two servos and a colour sensing module. It's crafted using 3mm thick cardboard. We provide printable A4 templates for you to print and stick to the cardboard making it easy to cut out yourself.
Check out our full video tutorial here:
Supplies
You can purchase the kit which contains all the supplies here!
Head over to Electromaker to download the A4 printable templates and code:
https://www.electromaker.io/project/view/arduino-skittle-sorting-machine
Step 1: Using the Templates
We can start by printing the six A4 templates and gluing them to the cardboard sheets.
Once this is done and the glue has dried you can begin to cut-out the shapes. Don't forget to cut out as precisely as you can as this is a mechanical project and the parts need to fit together well.
I used both scissors and a craft knife for this. Take great care with both tools as if misused they can cause some harm to yourself.
Once you have cut out the shapes you will notice that some of the parts have a hashed out area inside them. These areas need to be cut out from inside the shapes.
Step 2: Building the Hopper
We can start by printing the six A4 templates and gluing them to the cardboard sheets.
Once this is done and the glue has dried you can begin to cut-out the shapes. Don't forget to cut out as precisely as you can as this is a mechanical project and the parts need to fit together well.
I used both scissors and a craft knife for this. Take great care with both tools as if misused they can cause some harm to yourself.
Once you have cut out the shapes you will notice that some of the parts have a hashed out area inside them. These areas need to be cut out from inside the shapes.
Step 3: Building the Hopper
Each panel which you have cut out has a small number written in grey on it to help with its identification.
For this step you will need the four panels numbered 1, panel number 2, and the two rectangles numbered 3.
Take two of the number 1 panels and glue them together along their long edges so one end butts up against the face of another. These can then be connected to the square base panel number 2 which sits inside the corner of the other two panels.
Continue by adding another of the large side panels.
We can then add both the panel number 3's to the base to act as a funnel. I found it easiest to place these in position and then add drops of superglue where they make contact with the other panels and then hold in position for a few seconds as the glue sets.
To finish the hopper assembly for now you can add the final side panel into place.
Step 4: Make Room for the Axle
Before we start work on the next set of panels you should turn the hopper assembly upside down and make a small cross through the marked dot on the underside. This will allow us to insert the axle of the wheel at a later step.
Building the wheel
To create the wheel which will progress our Skittles through the machine one by one you will need the two panels. These are numbered 27 and number 28.
Glue one of the 27 numbered discs to the panel number 28 back to back so that the two black faces of each are facing outwards.
Take a great deal of care to ensure that the wheels and notches are well aligned before the glue dries.
Once they have dried you can then glue the remaining number 27 disc onto of the other number 27 (this is to increase the thickness of a wheel). This should leave us with a sandwich of three panels with two black faces.
Attaching servo horn to the wheel
We can now open our first electrical component which is the 360 degree servo. In the bag it comes in should be a selection of small white servo 'horns'. We want to use the small cross shaped one.
This needs to be recessed into the centre of the cardboard wheel on one side. To do this position the horn in the centre and carefully mark its rough outline. I scored a small mark with the craft knife.
Remove one layer of cardboard material after this, and glue the horn into place.
Adding the axle to the wheel
For the axle on the wheel you can use either a cocktail stick or cotton bud. Whichever you choose needs to be trimmed down to about 15mm in length.
This then needs to be inserted about halfway into our wheel (opposite side to the servo horn) and glued into place. I first used a tool to make a hole in the centre of the desk, added some glue and then positioned the cotton bud stem into place. It is important to ensure that the axle remains perpendicular to the wheel as the glue dries.
Step 5: Adding Legs to Our Hopper
There are two panels numbered 4 which form the legs of the hopper. The hopper itself is glued to these with its rear panel towards the non-curved edge and its base sat on the thick black line above the cutout. Ensure that the cut-out in the base of the hopper is orientated as shown in the below image.
The opposite panel is fitted in the same fashion.
Fitting the wheel
Use a small dab of glue to glue the continuous servo to the servo horn whilst ensuring that the glue does not interfere with its operation.
Once dried this can be inserted from below the hopper.
The axle is inserted into the small cross cut we made in the base of the hopper earlier. You may need to slightly open the legs of the assembly to get the wheel into position. This is OK but be careful not to actually crease the cardboard by causing it to fold.
The panel numbered 26 is then slide in from the left with the slot passing either side of the servos axles and the cutout towards the front of our machine.
This is followed by the two panels numbered 26 which interlock with the large legs we have already added holding the servo in position. The one with two additional notches in the bottom is seated towards the back of the machine.
Apply some dabs of glue to hold the legs in place taking care not to prevent our wheel from turning freely.
To check everything is as it should be so far, slowly rotate the wheel by hand and you should see the cut outs in the wheel and panel below sign up at some stage of its rotation.
Finishing the legs
We can now add the base panel to this half of the assembly. The base panel is number 7. Before we glue our assembly on top of this make sure that the wire for the servo is passing through one of the two notches in the spacers we added in the previous step.
This can then be positioned on the base (with the cutout hole in the base towards the front curved end of our hopper) and glued into place.
Assembling the chute
That's the work on the top half complete for now. Let's turn our attention to the chute. For this you will need all the panel numbers 10 through to 14 inclusive.
The bottom longest edge of the three triangle are fitted along the square shaped panel numbered 11 with one alongside either side and one through the centre.
This is then all attached to one end of panel 12.
Glue the two long side panels of the chute on to the edges of the large panel with their angled end towards the wider end of our 'wedge'.
The final panel, number 13, forms a cap at the top end of the chute against the angled ends of our sides.
Use some glue to attach a servo horn to the underside of our chute as centrally as you can on the square panel.
This is what the finished chute should look like:
Step 6: Building the Base
The first panels you need for the base are numbered 8, 16, and 19 (x2).
Glue the two panel 19's to panel 8. It is the longer edge of the panel 19 which should be attached, and the one with an additional cutout (for the Arduino USB port later) should be on the right hand side.
Panel number 16 is glued onto the front edge of these two panels. Make sure that the number printed on the black square is facing outwards and is the correct way up for reading as his marks where we will be attaching our other 180 degree servo later.
Panel 17 is added horizontally above this one.
Panel 18 sits behind this. Ensure the the cut out for our servo is orientated as shown with the arrow in the image below:
Ensure that you keep the sides pulled in as this dries.
Panel 15 is then attached onto of this with the cutout towards the front of our machine.
Step 7:
Step 8: Add the Second Servo
Take the 180 degree servo and glue it over the black box on panel 16 with its wire exiting to the left (when viewed from the front.).
The servos wires and connector can then be threaded through the hole in the back panel.
Joining the two halves
The two main half assemblies can now be joined together using glue. Make sure that they are well aligned paying particular attention to the hole between the two stages of the machine.
Add the funnel
There are two panels numbered 21 which should be glued into place between the wheel and hole beneath to act as a funnel directing the skittle through the base.
Panel number 20 then sits in front of these to enclose the area.
Mount for colour sensor
Panel six is fitted lightly between the the two side panels above the wheel. When I say lightly I mean that the panel should not be exerting downward pressure on the wheel causing it to become pinched. The wheel needs to remain free to move without too much friction.
The cutout in this panel should be positioned on the left hand side towards the hopper as shown in the image below.
Step 9: Assembling the Sorted Skittle Pots
The last of our cardboard craft work requires us to assemble the five pots which the skittle will be sorted into.
This is as simple as using some glue to join the panels number 22 through to 25 as labelled below. You will need to do this five times in total.
That's the cardboard work done. Now for some electronics.
Preparing the Colour Sensor
Prepare four 33m long wires and then solder one each to SDA, SCL, VCC and GND on the colour sensor.
We can now glue this module into position on our machine. Take a look at the underneath and notice roughly where the colour sensor is on the board (surrounded by four LEDs).
Use some hot melt glue or similar to fix this in position on the top of our machine with the sensor as centrally aligned over the cutout as possible, whilst at the same time, trying to completely cover the hole so we do not let stray light from outside the machine interfere with our readings later.
Prepare the servo wires
Cut the brown and red wires from the plastic connectors leaving the orange wire still attached. This needs to be done to both of our servo leads.
The wires coming from our servos are too thin to insert into our plastic wiring connectors we will be using later. To resolve this we can solder a 4cm wire to each of the four wires we just cut from the plugs.
Wrap some insulation tape or use some heat shrink tubing to help prevent the wires from creating a short circuit later.
Step 10: Adding the Contact Switch
We need to add a 25cm and 12cm length of wire to our switch before we can install it onto our machine.
The long wire should be soldered to the central leg of the switch (white wire in below photo) and the 12cm wire should be soldered to the NO (normally open) leg which is the one where the metal arm attaches to the switch.
Flip your main cardboard machine upside down and turn it around so we can see the back.
We now need to position the switch so that its red roller wheel is up against the wheel and engages the switch whilst the wheel is turning. There are also two notches on our wheel which should allow the switch to extend its arm and disengage the switch with an audible click.
This is how the machine will know where we are in the revolution of the wheel. Position the switch first without glue and then while holding into place with one hand, use the other to slowly rotate the wheel until you find a position which allows the switch to toggle on and off at the correct times.
So in the above image the switch should have 'clicked on' and in the below, when the wheel is in the notch, the switch should have 'clicked off'.
Once a position has been found, mark it with a pencil and then you can remove it, add glue and then reposition it.
Keep turning the wheel as the glue cools to ensure it ends up in the ideal position once fully cooled.
Electronics
Connecting our hardware to the Arduino
We can now connect everything to the Arduino. I have created a wiring diagram which I strongly suggest you take a look at and follow. I have included a low resolution copy here inline but you can find the full quality one included with the other downloads for this project at the end of the article.
Here is concise run-through of the wiring.
Wiring the colour sensor
The 33cm long wires coming from the colour sensor are connected as follows:
Sensor ---> Arduino
VCC ---> 5V
GND --> GND
SDA -->A4
SCL --> A5
Wiring the Switch
The 25cm lead coming from the central leg of our switch connects to D8
Adding a ground to the Arduino
Create a new 14cm long wire and solder this to one of the unused ground pins on the Arduino.
Connecting the Servos
The orange lead coming from the servo which drives the wheel should be connected to D5 on the Arduino. As we left the connector on the end of the servos wire this can be pushed onto the leg already attached to the Arduino.
In a similar way the orange wire coming from the chutes servo should be connected to D6.
Step 11: Connecting Battery Pack and Batteries
We also need to add some additional length to the wires coming from our battery pack. Prepare two 5cm lengths and add one to each wire coming from the battery pack.
Add some insulation tape around your solder joints to help protect them.
Add the AA batteries to the pack and then glue it into position underneath the rear of the machine. Ensure that the wires are exiting upwards.
Connecting the batteries to servos
Use one of the two blue plastic connecting block to join together the positive wire from the batteries and the two positive wires from the servos. All three of these wires would have been red in colour when they left the device (however your extension wires may now be a different colour).
The wires are fitted into the block by exposing about 10mm of the wire and then pushing it into the block.
Repeat the same steps for the second connector but this time we will bring together all the ground connection. That is:
- 14cm wire we soldered to the Arduino ground.
- The remaining wire coming from each servo (originally brown).
- The remaining ground wire from our battery pack.
- The remaining wire attached to our switch.
Once this is done, both connectors can be glued into place inside the back of the machine.
The software
Preparing the Arduino IDE
Connect your Arduino to your computer using the included USB cable.
You can then download the code for this project, you'll find it at the end of this article, and then open it in the Arduino IDE. If you do not already have this installed you can download it here: https://www.arduino.cc/en/Main/OldSoftwareReleases
Before we can upload the code we need to install a library for our colour sensor. To do this head to:
Sketch -> Include Library -> Manage Libraries....
In the window which appears search for 'TCS34725' and then install the Adafruit version if you do not already have it installed.
Check that you have the board type set to Arduino Nano
The processor set to 'ATMega328P (Old Bootloader)
You can then upload the code. The machine may try and spin the wheel around once and take a guess at what colour Skittle it sees if any. This is fine - but at the moment it does not know which Skittle to send where.
What we can do though is add the lower chute onto the bottom servo so that it is pointing as straight forwards as possible as the rotation of the lower servos is now known.
We will now calibrate your machine to work best how yours has come together.
Calibrating your machine
As everyones machine is a little different the machine has started in a calibrating reading mode so that we can begin to scan Skittles and teach it what each colour looks like.
To do this, start by putting several green Skittles into your hopper.
Then open the serial monitor setting your baud speed to 115200 and line ending to 'No Line Ending' in the bottom right area of the serial monitor.
You can now send a single letter to the Arduino through the serial monitor and look through the holes on the back of the colour sensor or peer just above the wheel. You should be able to see when a Skittle is directly underneath it as the light we see should turn from white to green.
If your Skittle goes past the sensor before stopping underneath it then you should reduce the value of the constant 'wheelOverRun' on line 11 of our code. Likewise, if your Skittle does not reach it then you should increase this value.
Send another character through the serial monitor (after re-uploading the code) to check and keep adjusting until you're happy with the result.
Step 12: Reading Skittles
Now we know that they are aligning under the colour sensor we can take five readings of a green Skittle under the sensor and write each set down.Take a look at the serial monitor and you will find that our program has reported the Red, Green, and Blue readings from the sensor. (Highlighted below).
Record these, then send another letter through the serial monitor to fetch a new green Skittle and record the readings again. Repeat this four times until you have five readings.
Work out an average value for the red, blue, and green readings.
Now repeat the same steps for each colour Skittle one by one until you have an average for each. You should also take 5 readings and work out and average for that so that we know what the sensor reports when there is no Skittle present.
I recorded mine into a spreadsheet as shown below - but don't use my readings, it's important you use your own.
Adding the value into your codes array
We can now add the calculated values back into our program. In the below image you can see where I have added my values for the Red Skittle (with no decimal places) to the array in the order of red average, green average, blue average.
Continue adding all the other values until your array is complete.
We can then change the value of our constant 'calibrating' from '1' to '0'. This tells our machine that we are done taking sample readings and are now ready for it to begin sorting.
It also increases the amount of information our machine prints to the serial monitor so that you can see what's happening.
You can now add the receiving containers to your machine, lining their short edges up with the five straight edges of the base plate.
Add some Skittle (if you've not eaten them all already)!
Re-upload your code one more time and enjoy your machine and your selection of wheel organised Skittles. :)
Step 13: Some Parting Advice:
If you find your machines wheel ever gets stuck it most likely because a Skittle has not entered correctly. Check the hopper first to see if two Skittle are not trying to enter the machine at the same time. If the wheel needs help ejecting two that have entered you can use your hands to turn it slowly from the sides. Once you have done this the machine will continue as normal.
If it does not seem to be sorting correctly, or if the values you calculated for each colour seem too similar (look at mine for an example of how different they should be) then you should check that your Skittle is indeed stopping directly underneath the colour sensor when it takes a reading. Check this and make an adjustment to the constant 'wheelOverRun' as explained earlier. If you make changes to this value you should repeat the calibrating process again.