Introduction: Chocoloate Egg Dispenser - Made With Arduino

About: First year Game Art student

For one of my classes I've been tasked with making something using an Arduino. Naturally as the bunny lover that I am, I had to make something related to bunnies! With Easter coming up only a few days after my deadline I decided to make a chocolate egg dispenser.


By petting the bunny on top of the box, you're rewarded with a singular chocolate egg!

Supplies

So, fellow chocolate egg enjoyer, let's have a look at all the things you need to make this!


Electronical components

  • 1x Arduino Uno
  • 1x SG90 Mini servo
  • 1x Micro switch without a lever
  • 1x LED
  • 1x 10kΩ resistor
  • 2x 330Ω resistor
  • M/M Jumper wires


Housing materials*

  • 1x Outer box - 4 mm thick MDF & flat edge joints
  • Outside measurements : 168 x 178 x 88 mm
  • Hole in top piece (88 x 168 mm) : 36 x 29 mm
  • Hole front piece (80 x 170 mm) : 74 x 40 mm
  • Hole back piece (80 x 170 mm) : 25 x 25 mm
  • 1x Outer basket - 4 mm thick MDF & flat edge joints
  • Outside measurements : 88 x 58 x 29 mm
  • 1x Egg container - 3 mm thick MDF & finger edge joints
  • Outside measurements : 36 x 110 x 29 mm
  • Egg slider - 3 mm thick MDF
  • 2x side pieces : 80 x 20 mm
  • 1x top piece : 30 x 30 mm
  • 2x inside pieces : 30 x 17 mm
  • Middle piece - 3 mm thick MDF
  • 160 x 80 mm
  • Hole : 30 x 27 mm
  • 3D printed bunny with a hole in its back for the switch & lid (sizes are up to you! Just make sure it fits on your box :) )

*I've provided an image with a reference for where all the holes need to go!


Equipment

  • Lasercutter
  • 3D printer
  • Glue
  • Soldering iron and supplies


Extra

  • Chocolate eggs (mine are about 30 x 20 mm)
  • Paint
  • Other decorations if you'd like!

Step 1: Thinking. a Lot of It

Me, being a complete Arduino noob and not having the faintest idea what an Arduino even is to begin with, had a lot of thinking and researching to do before I started this project. I knew I wanted to do something related to bunnies since they're my favourite animals and I have two of them hopping around in my backyard (look how cute they are, their names are Pixie & Kiyo).

So, I started off by just writing all my bunny-related ideas down. At my school there's a 3D printer so I really wanted to try that out. One of my first ideas was making a bunny with an LED display as a head and have it react to something like movement. This seemed a little complicated so I did some more thinking and then I thought: "I could 3D print a bunny and have it poop candy.."

I did a little tweaking and made Sketch 1. The idea was having a sensor in the head, so you would need to pet the bunny to trigger a mechanism that would give you a chocolate egg.

Then I started looking into the things I would need to make this and with some feedback from my teacher I settled on making a mechanism with a servo motor and a micro switch!

Step 2: Designing and Prototyping

As it turns out, 3D printing a bunny as big as the one in my initial sketch takes a long time and at my school you have to make a reservation for it which can only be 2 hours a week. I could've split the print up into multiple parts and then glue it together but it just seemed like a lot could go wrong and too much of a hassle to arrange.

So instead I decided to change some things around and make the bunny smaller and the box bigger. While making sketches, I realised this was a lot more difficult than I initially thought it would be. So I made a general idea (Sketch 2) to go and prototype and from there I would adjust my sketch and make a final design.


The whole prototyping phase was a bit of a mess and I struggled quite a bit with it. I took some leftover cardboard boxes to cut apart and make my prototypes with.

Prototype A was basically Sketch 2; a little square container that would store the eggs, a middle part that would be the foundation for the sliding mechanism & a ramp so the eggs would roll out. After this first prototype I realised the box was way too big: I had a lot of unused room on the side that I just didn't need. So I made Prototype B, in the same box but with a steeper ramp to insinuate a narrower box, which I preferred! I also made the container with a funnel/angled sides in it and then realised this didn't work well at all.

Besides the fact that this was a very poorly constructed prototype, I realised there was no way to regulate how the eggs exited the container. The hole was made with the intention that the eggs would come out vertically, but 95% of the time the eggs had different plans and got stuck horizontally, blocking all the other eggs.I had to figure out a way to make sure the eggs would all consistently come out of the storage the same way. My solution for this was a long rectangular container, narrow enough to fit exactly one egg. I did have to sacrifice some storage, having to limit my design to have a capacity of only 7 eggs. But this did work a lot better! I also made a prototype for the mechanism that would slide the eggs to the opening, so they could roll out. Now that I had everything figured out, I went back to the drawing board to adjust my design and make something with precise measurements.

Step 3: Final Design

I have reached a new level of respect for people who design things for a living because my lord my brain still hurts from trying to design this. I wish I was joking when I say I spent multiple days designing this thing. Let's get into it.

So! The first image is my first attempt with accurate measurements. My goal was to make the box as small as I could get it, so I went back and forth a lot to adjust things here and there. Initially I thought I'd need a box that was 180 x 220 x 80 mm (more or less the size my prototype was), but I managed to narrow it down to a box that was 160 x 170 x 80 mm. The egg container in my prototype was 30 x 144 x 23 mm but this made my box a lot taller than I wanted it to be, so instead of a container that could fit 7 eggs, I made one that would fit 5 eggs and would be 30 x 104 x 23 mm instead.


I made a 2nd design with more measurements, since my initial design was intended to have a clear idea of how big the outer box needed to be. In the 2nd image I'm measuring everything out properly, with measurements next to it.

After finally having figured out how big everything is going to be, I went ahead and made the outer box, outer basket & egg container on Makercase and freehanded the other pieces in the lasercutting program.

Step 4: Making All Components

While I was working out the measurements, I've also been working on 3D modelling a bunny in Blender! Now having all my measurements and files prepared, I could go and get everything printed and cut out.

Back home I got started on removing the supports on my 3D printed bunny & this is where i realised the hole in the bunny isn't big enough to fit a microswitch, so I painstakingly filed the hole bigger. I also sanded down the bunny so she was nice and smooth and ready to be painted on later.

Step 5: Arduino Set Up & Code

Next up! Actual Arduino related things! Let's have a look.

The circuit is provided above; we have our Arduino hooked up to a servo motor which activates using a microswitch. I added an LED for fun and so you can tell when the mechanism is activated & working. The website I used didn't have a microswitch so I used a button instead, but it works the same way!


The idea is the following: the microswitch is pressed and triggers the servomotor to move, all while this is happening the LED glows so you can tell the mechanism is working (since all the Arduino stuff will be hidden in a box). You can't press the switch multiple times while it's actively running its code, so there's no cheating a 2nd egg or potentially breaking the system! Yay!


And here's the code you need to make everything work! I added comments to try and explain what everything does :)

As you can see there's a ton of for loops in this code, while I was working on the mechanism, I discovered some issues: at first I just had my servo go to pos = 135 and back to pos = 0, but this would cause eggs to get stuck sometimes. So, I added multiple little shakes where the servo goes back and forth to try and minimise how often this happened. Of course, occasionally eggs will still get stuck, but with the extra for loops it shouldn't happen as often!

#include <Servo.h>  //including a library for servo related code (look up a tutorial for this if you don't know how it works!!)


Servo myservo;      // naming my servo!


int pos = 0;        // variable for servo position


void setup()
{
  Serial.begin(9600);


  myservo.attach(9);      //pin i attached my servo to
  pinMode(4, INPUT);      //pin i attched my microswitch to
  pinMode(11, OUTPUT);    // pin i attached an led to


  myservo.write(0);       //setting the position of my servo to 0, otherwise everytime you power it up, it resets to pos = 90, so this prevents that!
}


void loop()
{
  int buttonState = digitalRead(4);       //variable for the buttonstate of my microswitch so we can check if it has been pressed or not


  if (buttonState == 1)                   //this checks if the microswitch has been pressed, if yes it runs the code below
  {
    digitalWrite(11, 1);                  //led turns on (kind of functions as a check to see if everything works!)


    for (pos = 0; pos <= 135; pos += 1)  //servo goes from 0 to 135 degrees
    {
      myservo.write(pos);                 //tell servo to go to "pos"
      delay(5);                           //takes 15ms for the servo to reach the position
    }


    delay(1000);


    for (pos = 135; pos >= 100; pos -= 1)  //servo goes from 135 to 100 degrees
    {
      myservo.write(pos);
      delay(5);
    }


    for (pos = 100; pos <= 135; pos += 1) //etc etc
    {
      myservo.write(pos);
      delay(5);
    }


    for (pos = 135; pos >= 25; pos -= 1)
    {
      myservo.write(pos);
      delay(7);
    }


    for (pos = 25; pos <= 50; pos += 1)
    {
      myservo.write(pos);
      delay(7);
    }


    for (pos = 50; pos >= 0; pos -= 1)
    {
      myservo.write(pos);
      delay(7);
    }


    delay(1000);


    digitalWrite(11, 0);                  //led turns off
  }



}

Step 6: Assembly : MDF

Buckle up, this is going to be a long one!

Now that in theory I have everything I need to make this bad boy, all I need to do now is put everything together. So, let's start by glueing some pieces together: I assembled 4 out of 6 walls of the outer box, leaving the top and one of the side parts open so I had easy access to mount it's inside pieces later (Image 1). I glued together the egg container, making sure to leave the lid so I could open and close the container to refill the eggs. And I also put the outer basket together, make sure to leave one of the longer side pieces out so the eggs can land in there (Image 2).

I glued together the pieces to make the egg slider (Image 3 & 4), and then I realised there was no support for the slider. So using one of my leftover pieces from the outer basket, I cut it in half to make guides for the slider so it would stay in place (Image 5).

I didn't really think about how I was going to mount my servo in there, so I ended up cutting a hole into my middle piece for my servo to fit into snugly (Image 6). Then into one of the top pieces of my egg slider, I drilled a hole to poke a piece of iron wire into. The other end I stuck in my servo, and after a little tweaking in code, this worked almost perfectly! (Video, thank you dad for holding everything in place for me)

Something I did worry about a bit was the positioning of all my pieces inside: if only one thing wasn't glued properly it wouldn't work at all, so I decided to make a little platform for my egg container to stand on, so it would stay in place, and not have to depend on how I glued it into the top part of the outer box. Using some more spare pieces, I made some supports and a platform with a hole in it big enough to fit an egg through it and mounted this on top of the sliding mechanism, glueing everything together (Image 7). I cut off a little corner from the middle piece so the servo cables could come back up to the Arduino. Speaking of which, I drilled some holes into the large side piece so i could mount my Arduino there (Image 8, again thank you dad for holding everything in place for me as I take on the very taxing task of taking photos and videos, phew)

With the middle piece ready, I glued it into my box, with the bottom of it sitting exactly aligned with the opening in the front, nice!

Since I did add a platform to this piece, the egg container that would've fit nicely into the hole on the top piece, now pokes out. I do not really mind, but you can also cut it off. I did a lot of tests to see if it all works properly, which it does like 95% of the time.

Before we close it off, let's do some soldering!

Step 7: Assembly : Soldering

Time for soldering! I will not lie, I zoned out while doing this, so I do not have any step by step photos of what to solder to what. I will try my best to explain what to do here, though! (I'm secretly hoping you're a soldering genius and don't need my help for this.. No? Damn)


I would recommend to keep the circuit (image 1) close for reference!


I'm going to go through all the ports in my Arduino that have wires connected to them! (Image 2 + 3)

Let's start with the easier ones:

  • Port 9 is connected to my servo (orange wires) so I soldered two orange wires together.
  • Port 11 is connected to a resistor (330Ω) which then connects to my LED's Anode

Now we're going into slightly more complicated things:

  • 5V has to connect to the microswitch & the servo's red wire
  • Ground has to connect to the servo's brown wire, the LED's Cathode and to a resistor (10kΩ) which then connects to both Port 4 as well as the microswitch


You might notice my cables have black tubes on them: these are heat-shrinking tubes which I used so I didn't have to worry about everything short circuiting.

Lastly, I mounted my Arduino in place and put a tie wrap around the cables to try and keep them in one place (image 4).


And here's all the mechanical things done (video)!

Step 8: Polishing

This is optional, but I thought the box was boring so I've done some painting! You can of course decorate this however you want, I just painted each side of the box a different colour and added some stars for fun!


I also painted the bunny and gave her some eyes. Since my 3D print used bright pink material I put on multiple coats of white paint. For the lid I glued only the part at the red cross (image 4).


Happy Easter! :)


Looking back

Honestly I surprised myself while making this, especially since it's my first time ever using an Arduino. I had fun designing this and putting everything together! Measuring everything and planning things out was incredibly challenging, but I made do with what I had and I'm pretty proud! I especially enjoyed figuring out how to make my mechanism work better and the whole ordeal was kind of like a puzzle to me, which I enjoyed trying to solve!

I've learned a ton of things: how to use a lasercutter and 3D printer (planning my next 3D print as we speak!) and how to make circuits using an Arduino. Which was quite fun but I do not see myself using it again in the future, but it was a nice change of pace from the stuff I usually occupy myself with!