Introduction: Arduino Candy Machine

Introduction

I wanted to create a device that would dispense candy, (but it can dispense a lot more since it is made out of LEGO the container is customizable to your liking) so I started thinking and with many failed design attempts, I decided to go with a LEGO based design. It was way more flexible to work with. How does it work? Well that is easy, the device is programmed with the Arduino Uno, that has a knob attached to it, the knob is programmed by code. Once you turn the knob it will activate a servo motor, that will rotate the container at a negative forty-five degree angle, dispensing the candy out of the open mouth hole in the container. Then just by turning the knob back into the original position will reset the container to the position it started in.

Step 1: Things You Will Need:

LEGOs
Arduino Uno

A1M Knob

A Servo Motor (I used a JR Sport Brand with a ball Bearing, but any should do.)

A computer to code

Cable wires

Solder

Soldering Iron

A 5V wall charger(I used an old phone charger)

Candy

Step 2: Directions:

1.Grab some LEGOs and make a foot base 16x16 pegs( 4 horizontal 8 pegged rectangle blocks) that should give your Arduino plenty of space to build around of. The design is really up to the builder’s imagination, all you need is two open holes in your structure where the power supply and knob wires can stick out, so you can plug it into the wall.
2.Once you build your base it time to code the Arduino. Here is the code I used:

#include
Servo myservo; // create servo object to control a servo

int potpin = 0; // analog pin used to connect the potentiometer int val; // variable to read the value from the analog pin

void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object }

void loop() { val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180) myservo.write(val); // sets the servo position according to the scaled value delay(15); // waits for the servo to get there }

Once you have that just upload it to your board and follow the circuit schematic image shown.

4. Once you did that you are ready to go, now just put a roof on your base and lets start building the servo base 5. The servo base has the same principles as our first base, you just want to build something that will hold the servo in place, Also the servo will be laying on it side not standing straight up. 6.Once the servo has been covered up it time to build the container, this depends on how much candy you want to dispense at once, since this is only a prototype I did a small container, which was made out of LEGOs to attach the LEGO container to the servo. I took my soldering iron and burned a small screw hole into a flat 6x6 peg square LEGO piece , then I tighten the screw into the servo and it hel, for more support try adding glue as well.

5. The servo base has the same principles as our first base, you just want to build something that will hold the servo in place, Also the servo will be laying on it side not standing straight up.


6.Once the servo has been covered up it time to build the container, this depends on how much candy you want to dispense at once, since this is only a prototype I did a small container, which was made out of LEGOs to attach the LEGO container to the servo. I took my soldering iron and burned a small screw hole into a flat 6x6 peg square LEGO piece , then I tighten the screw into the servo and it hel, for more support try adding glue as well.

7. Make sure there is a hole in your container where the candy can fall out once rotated.
8. That’s it you are done!

Step 3: Video!