Want to make a mini vending machine perfect for candy, erasers, gum, and other fun size goodies? You've come to the right place! I built an Arduino-Uno powered vending machine from scratch for Ms. Berbawy's robotics class, after I was inspired by a design I saw on the RetroBuiltGames Blog. Using Mrs. Berbawy's maker space and materials that cost a total of less than $50, I built a functional vending machine with little to no coding/robotics experience. Follow this Instructable, and you can too!
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Gather Materials/Necessary Equipment
- pieces of 1/8" thick birch wood for box body
- pieces of 1/8' thick transparent acrylic
- multicolored electrical wire and electrical tape
- 12x 12 mm M4 screws and nuts
- 2x continuous rotation servo motors (available for $16.99 on Amazon)
- sacrificial wire hangers
- 2x 1 cm diameter pushbuttons (pack of 10 for $7.29 from Amazon)
- Arduino Uno (available for $21.99 on Amazon)
- Breadboard (available for $7.99 on Amazon)
- 2 Resistors of any resistance
- Laser Cutter
- Wire Cutter
- Wire Stripper
- Digital Calipers
- Computer to code Arduino
Step 2: Laser Cut a Box
The pictures above showcase the various steps of the box-making process.
First, decide which material your box will be made out of. I used Birch wood which had a thickness of approximately 1/8 inch (measured using Digital Calipers, as shown above). Then, design a box of dimensions 9.25" x 10.25" x 7" using Adobe Illustrator. To make things easier, I designed my box using an online box designing website by entering the measurements, as is shown in the screenshot above, and uploading the pdf the website generated to Adobe Illustrator. After adjusting the design to meet the requirements of your laser cutter, cut all 6 sides of the box. Finally, assemble the box to make sure the sides fit together.
Step 3: Make a Shelf
Design a shelf to hold the candy using Adobe Illustrator. The shelf should have dimensions 9" x 5", so it will fit inside the box and be long enough to hold a coil containing around 6-7 spaces for candy. On one of its 9" edges, make three 1" wide tabs spaced 1.5" apart to connect it to the back side of the box. The tabs should extend a vertical distance equal to the depth of the back side of the box, which in my case was 0.115".
Create a shelf divider using Adobe Illustrator to divide the shelf into 2 lanes. According to my design, showcased above, the shelf divider has a height of 2.5" and width of 4.75", to ensure that the divider will not extend beyond the shelf or hit the ceiling of the box. On the bottom edge of the divider, create 2 1" wide tabs spaced 1" apart. Because these tabs will be used to attach the shelf divider to the shelf, their length should be equivalent to the thickness of the shelf, which in my case was 0.115". Create an additional 1" long tab on one of the shorter sides of the divider to attach the divider to the back side of the box. This tab should be placed 0.75" above the bottom of the divider and have a width equal to the thickness of the back side of the box, which in my case was 0.115".
Finally, cut rectangles on the shelf surface to secure the shelf divider to the shelf. Make 2 1" long rectangular cutouts down the shelf's vertical line of symmetry, as shown in the design above. The width of these rectangles should be equivalent to the thickness of the wood used to make the shelf divider, which in my case was 0.115".
After designing the shelf and shelf divider, laser cut and ensure that the two pieces fit together.
Step 4: Make Box Cutouts
Front Side of Box:
Using Adobe Illustrator, design a rectangular 4" x 7.75" window to allow people to see the candy on the shelf. This top edge of the window should be 1.625" from the top edge of the side, and the left/right edges of the window should be 0.75" from the left/right edges of the side. Beneath this window, design another window to retrieve the candy. This window has dimensions 7.75" x 2.25", and its top edge should be 2" underneath the first window's bottom edge. The two windows should line up. Then, design two circular holes with a radius equivalent to the smaller, screw portion of the pushbutton so that the top colored "button" part of the pushbutton sticks out on the surface of the side. I measured the pushbutton radius with digital calipers and designed circular holes with a radius of 0.189". The centers of the two holes should be 2.25" apart and 3.5" from the closest vertical edge of the box.
Back Side of Box:
Using Adobe Illustrator, design three 1" wide rectangular cutouts spaced 1.5" apart to attach the shelf to the back side of the box. The cutouts should begin 1.5" from the side's left edge, and have a width equivalent to the thickness of the shelf, which in my case was 0.115". Line up the cutouts 4.5" from the top edge of the side, to ensure that people can easily see the candy from eye level. Then, add a 1" long rectangular cutout on the side's vertical line of symmetry, 0.75" above the shelf cutouts. This cutout will fit the side tab of the shelf divider, so it should have a width equivalent to the thickness of the shelf divider, in my case 0.115". Finally, create two additional rectangular cutouts of dimensions equivalent to the dimensions of the back side of the servos, in my case 1.6" by 0.8". These cutouts will fit the servos, and should be placed 1.5" above the shelf cutouts. The center of each cutout should be 2.125" from the closest vertical edge of the box. Lastly, create a small rectangle on the bottom right edge of the back side of the box to connect the usb cable and servo wires to the arduino inside the box. The dimensions of the cutout I used were 0.5" x 1".
Sides of Box:
For each side of the box, using Adobe Illustrator, create two 1" wide rectangular cutouts spaced 1" apart to attach the shelf to each side of the box. The cutouts should have a length equivalent to the thickness of the shelf, which in my case was 0.115", and the cutouts should be placed 4.5" below the top edge of each side. The cutout closest to the back of the box should be placed 1" away from the closest vertical side of the box.
After designing the cutouts, move your design to the top left corner of the page. Make sure to delete the outline of the sides on Adobe Illustrator before cutting, and position your wooden sides in the top left corner of the laser cutter to ensure that the cuts are made in the correct locations. My cut sides are shown above.
Step 5: Code Arduino Uno
Using the Arduino coding environment that can be freely downloaded from the Arduino website, type up the code show in the pictures above. Connect your Arduino Uno to your computer using a usb cable, and press the "upload" button on your monitor to upload the code to the Arduino. Before uploading, make sure that you have selected the correct port and board under the "tools" menu.
Note: this code only works for modified, continuous rotation servos. The number in each "delay" command is the time, in milliseconds, it takes for each servo to rotate 360 degrees.
Step 6: Wiring!
Start off by using a wire to connect the ground (GRN) pin of the Arduino Uno to the negative rail of your breadboard, and the 5V pin of the Arduino Uno to the positive rail of your breadboard. I used a black wire and red wire, respectively.
Connect Servos to Arduino:
Connect the yellow wire of the servo to a constant Pin of the Arduino Uno. One servo should be connected to constant pin 9, and the other servo should be connected to constant pin 10. These constant pins are initialized as "output" in the setup section of the code. Connect the black wire of each servo to the negative rail of the breadboard, which will connect the servo to the "ground" pin of the Arduino. Connect the red wire of each servo to the positive rail of the breadboard, which will connect the servo to the 5V pin of the Arduino.
Connect pushbuttons to Arduino:
Connect one end of each pushbutton to a constant Pin of the Arduino Uno. I used a red wire for this purpose, and connected one pushbutton to constant pin 11, and the other to constant pin 12. These constant pins were initialized as "input" in the setup section of the code. Connect the other end of each pushbutton to a row with a resistor of any resistance on the breadboard. On the breadboard, connect the row with the resistor to the negative rail of the breadboard and the positive rail of the breadboard. This will, in effect, connect the resistor to the ground and 5V pins of the Arduino.
Power the Arduino:
After uploading the code into the Arduino, connect the Arduino's USB cable to any outlet to power the Arduino.
Step 7: Attaching Coils to Servos
Using Adobe Illustrator, design 2 circles: one with a radius of 2.5", and the other with a radius of 2". Each circle should have a smaller, 0.25" radius hole in its center. My design is shown in the first screenshot. Using a laser cutter, cut two circles of each dimension , for each of the 2 servos. The material I cut the circles out of was the same wood I used for my box.
To make the coils, find a pipe or rod of constant radius and wrap a wire around it 7-8 times. I used the wire from a sacrificial wire hanger to make my coils, as shown in the picture above.
Attach each bigger wooden circle to each smaller wooden circle by drilling two small holes in each circle and attaching with screws, leaving a small gap between the two circles. Slide the vertical end of your coil into the gap between the two circles, and tighten the screws to secure it. Attach the bigger circle to the red servo attachment using 2 screws. Finally, attach the entire coil+circle piece to the servo using the red servo attachment, as shown in the last picture.
Step 8: Assembling the Vending Machine!
First, attach the servos to the box by drilling a hole above the servo cutout and inserting a screw through the hole you drilled and the hole at the top of the servo. The back part of the servos should stick out of the box, as shown in the picture above.
To attach pushbuttons, slide pushbuttons though holes on front side of the box. Solder 2 long wires to each pushbutton and to the breadboard. Secure wires to the sides of the box using wire tape so they do not get in the way of dispensing the candy.
Secure the front, back, bottom, and sides of box together on each of the 8 box corners using 8 tiny wooden blocks. First, hold each block tight in each corner. Drill 2 holes on the front each of these 4 sides so that they line up with each block's center. Then, use a screwdriver to attach each side to 2 blocks with a screw. The blocks on the top side of the box are shown in the picture. Only the box top remains unattached to the rest of the box, as it must come off easily to add candy to the box.
Put breadboard in the box and finish wiring. Connect the servo wires and USB through the rectangular cutout in the lower left corner of the box. Attach the bottom divider so that the breadboard is separated from the candy retrieval area.
Add candy by removing the top of the box, as is shown in the pictures above. After candy is added, secure the box lid. Connect the USB cable to power and start dispensing candy.
Step 9: Problems Encountered + Troubleshooting
- code upload error -> make sure the right pin and board is selected!
- candy is moving backwards instead of forward -> coil the coil in the opposite direction!
- servo is not a continuous servo -> modify servo for continuous rotation and use the delay command with input = time it takes to complete one rotation
- Arduino/breadboard gets in the way of dropping candy -> laser cut a clear divider out of acrylic