Makecourse USF: Arduino Candy Machine
by ScottC10 in Cooking > Candy
916 Views, 4 Favorites, 0 Comments
Makecourse USF: Arduino Candy Machine
This Instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com)
This is a simple Arduino run candy machine using a stepper motor two buttons and four 3D printed pieces. In this Instructable all files will be provided as well a step by step process explaining how to build, program and present the candy machine so that it works to it's full potential.
**NOTE: Do not leave in car, will melt the PLA and distort print if hot
Print the 3D Pieces
How the candy machine works is candy will be funneled down to a short cylinder inside the machine. This cylinder has four holes in it that carry the candy around to the front and dispensed out the front. This cylinder has a short rod connected to the stepper motor.
First thing you will want to do is print the four plastic pieces of the candy machine. The candy machine has four basic parts; The base (where the candy is dispensed; depicted in yellow), the mid part (where the motor is housed; depicted in gold), the top (where the candy is funneled down into the machine; depicted in purple), and a short cylinder (what is connected to the servo motor that dispenses the candy; inside machine).
If you want to design your own candy machine print feel free to make your own. I used Autodesk Inventor 2014 to design my pieces. But you might have a larger stepper motor that can't fit into my design. You may want to use a larger candy than I used (M&M's)
I used plastic epoxy to cement the pieces together and connected the servo to the cylinder with hot glue and it worked fine.
Downloads
Circuit Setup
The above picture is a straightforward way of setting up the circuit for the candy machine. The stepper motor is plugged into the motor module. From here you plug the power and ground inputs into the power and ground on the bread board. Respectively plug digital pins 8-11 into the motor module. After this do a basic two button setup and plug these into digital pins 2 and 3. Finally take two wires to plug the bread board into the ground and power. This is a simple setup, if you follow the diagram you should be fine. Of course, you are able to play around with the circuit setup to best fit your design.
**I have two buttons for a forward and reverse incase candy gets jammed in the machine.
Code
//Robert Core //Using two buttons to control the direction of the stepper motor int button_1 = 2;//Button 1 is plugged into digital port 2 int button_2 = 3;//Button 2 is plugged into digital port 3 int motorPin1 = 8;//Motor pin 1 is plugged into digital port 8 int motorPin2 = 9;//Motor pin 2 is plugged into digital port 9 int motorPin3 = 10;//Motor pin 3 is plugged into digital port 10 int motorPin4 = 11;//Motor pin 4 is plugged into digital port 11 int motor_Speed = 3;//Tells how fast the stepper motor is int motor_Step; int val1 = 0; int val2 = 0; void setup() {//input and output values of the pins pinMode(button_1, INPUT); pinMode(button_2, INPUT); pinMode(motorPin1, OUTPUT); pinMode(motorPin2, OUTPUT); pinMode(motorPin3, OUTPUT); pinMode(motorPin4, OUTPUT); } void loop() { val1 = digitalRead(button_1);//if button 1 is pressed motor will go clockwise if (val1 == HIGH) { digitalWrite(motorPin1, HIGH);//Motor pin is on digitalWrite(motorPin2, LOW);//Motor pin is off digitalWrite(motorPin3, LOW);//Motor pin is off digitalWrite(motorPin4, LOW);//Motor pin is off delay(motor_Speed); digitalWrite(motorPin1, LOW);//Motor pin is off digitalWrite(motorPin2, HIGH);//Motor pin is on digitalWrite(motorPin3, LOW);//Motor pin is off digitalWrite(motorPin4, LOW);//Motor pin is off delay(motor_Speed); digitalWrite(motorPin1, LOW);//Motor pin is off digitalWrite(motorPin2, LOW);//Motor pin is off digitalWrite(motorPin3, HIGH);//Motor pin is on digitalWrite(motorPin4, LOW);//Motor pin is off delay(motor_Speed); digitalWrite(motorPin1, LOW);//Motor pin is off digitalWrite(motorPin2, LOW);//Motor pin is off digitalWrite(motorPin3, LOW);//Motor pin is off digitalWrite(motorPin4, HIGH);//Motor pin is on delay(motor_Speed); } val2 = digitalRead(button_2);//if button 2 is pressed motor will go counterclockwise if (val2 == HIGH) { digitalWrite(motorPin4, HIGH);//Motor pin is on digitalWrite(motorPin3, LOW);//Motor pin is off digitalWrite(motorPin2, LOW);//Motor pin is off digitalWrite(motorPin1, LOW);//Motor pin is off delay(motor_Speed); digitalWrite(motorPin4, LOW);//Motor pin is off digitalWrite(motorPin3, HIGH);//Motor pin is on digitalWrite(motorPin2, LOW);//Motor pin is off digitalWrite(motorPin1, LOW);//Motor pin is off delay(motor_Speed); digitalWrite(motorPin4, LOW);//Motor pin is off digitalWrite(motorPin3, LOW);//Motor pin is off digitalWrite(motorPin2, HIGH);//Motor pin is on digitalWrite(motorPin1, LOW);//Motor pin is off delay(motor_Speed); digitalWrite(motorPin4, LOW);//Motor pin is off digitalWrite(motorPin3, LOW);//Motor pin is off digitalWrite(motorPin2, LOW);//Motor pin is off digitalWrite(motorPin1, HIGH);//Motor pin is on delay(motor_Speed); } }
Above is the code that I used for the candy machine. It's a basic two button stepper motor control. In sequence it turns one of the motor pins on while the rest are off. Then the next motor pin goes on while the rest are off and so on. Button 1 (val 1) is in one direction (motorpin 1,2,3,4) while Button 2 (val 2) is in the other direction (motorpin 4,3,2,1). The delay is how long between each step the Arduino will wait. The smaller the number the faster. I found out that a delay of 3 is the fastest the stepper can go.
Finished Product
This is what my final product looks like. I cemented the three pieces together and then cemented that on top of an Arduino box which houses the Arduino as well as the bread board. I drilled two holes for the buttons and glued those against the wall of the box. In the back I drilled a hole for the usb plug so I can power the Arduino with an rechargeable power supply. When you push the red button the cylinder spins and dispenses the candy out the slot on the bottom part.
Thank you for checking out my Intractable and I hope you have fun building a candy machine:)