You need to have the rotor in the right position on the servo. If it’s off by more than 5 degrees, GAME OVER. By the time you realize the problem, the glue will have dried and there’s no way to take the machine apart without destroying stuff.
To accomplish mounting the rotor to these tight specifications, I’ve created a servo stand that you can put together to help mount the rotor in the right position, the first time, EVERY time!
Step 1. Assemble the stand.
By now, putting these parts together should be old hat so I’ll just show you a few pics of the finished stand. All the pieces are labeled 99 so they are easy to find.
Or maybe they are labeled 66? Who knows?




When you put the servo in, be sure to orient it so that the spindle is at the center of the hole.
Wire hookups to the Arduino- red = 5V
brown = GND
yellow = pin 9
Step 2: Upload this code to your Arduino
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 160; // variable to store the servo position
String key;
void setup() {
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo.write(pos);
Serial.println("\n\n\n\n\n\n\nThe servo has been moved into install position (160 degrees).\nInstall the rotor so that it's hole is perfectly lined up with the hole through the ring.\n"
"If you can't get it perfect, stage the rotor slightly clockwise of the hole"
"After installation, input an angle around 10 into the serial monitor to line the hole up with the drawn circle.\n"
"The drawn circle should now be centered in the hole. If it isn't, fuss with the angle input until it's as close as possible.\n"
"Now find your angle for the ring hole (should be around 160?).\n"
"Swing the rotor back and forth a few times to make sure everything is good and record your numbers into the main sketch.\n"
"The ring hole becomes DropAngle = ___ on line 61 of the main sketch and the drawn circle becomes TubeAngle = ___ on line 59.\n");
}
void loop() {
if (Serial.available()) { // Check if user input is available on the serial monitor.
key = Serial.readStringUntil('\n'); //read data if it's there
pos= key.toInt();
if(pos > 0 && pos <=180) {
myservo.write(pos);
Serial.println(pos);
}
}
}In Arduino IDE, turn on the serial monitor and plug in the Arduino. The servo will to turn the servo to 160 degrees if it isn’t already.
Looking straight down on the stand, install the rotor so that it’s either perfectly over the hole or just a hair to the right. It should look like this:

Good. Now we need to find the angle our Skittles tube will be at. Input different values into the serial monitor paying special attention to the circle that’s engraved in the cardboard. You want to get it centered in the hole like this:

That’s your custom TubeAngle value.
Download and open this code in Arduino IDE
Skittles Machine Code
Put in your custom TubeAngle value at TubeAngle = XX on line 59 of the code.
Now swing the servo back around to around 160 degrees.
Get the rotor aligned over the hole, or maybe a little past it… whatever you feel good with.
Record this value onto line 61 where DropAngle = XXX.
Swing the rotor back and forth a few times to make sure everything moves as expected. If not, update your angles accordingly.
One you’re happy with the way everything looks, hit “back” on your browser to get back to the build tutorial, or use the link here: