Monday, March 28, 2016

MIDTERM - Coin Flipper



The Coin Flipper



My idea was to create a machine to settle trivial disputes. My brother and I used to flip a coin to settle said disputes, which is what gave me the idea. However, inevitably, a single coin flip felt unsatisfactory so we would often play first to 3 wins. I implemented a score counter in the LEDs to have this functionality.

I first focussed on the physical components keeping in mind how they would interact with the Arduino. Then I built my circuit and wrote some testing code. I had to make several iterations on my original design so that everything would communicate properly. 

Finally I tried to build an intuitive and attractive and yet simple and accessible casing.

Learning from some problems I had accessing my circuits/physical components while building my interactive toy I took a different approach to designing the casing of my machine. Instead of opting for a fully enclosed and sealed design, for this first prototype all of the component and circuit housing is designed to be easily accessible. This made the tweaking process at the end much easier. 


Plan



My plan was fairly simple. I needed some sort of spring loaded bolt to hit a coin on a button press. Then I needed a way to record the score of each flip. I was originally looking at a solenoid for my bolt, but I had a broken pen in my backpack and realized that the spring load mechanism in its casing could work just as well.

I was not sure how my final casing would look, so I did a quick mock up sketch just so that I could visualize all the components in conjunction.


The general flow is:

Button press --> Servo pushes down bolt --> Bolt springs up and flips coin --> Servo resets 

Button press to record score --> LEDs light indicating score --> On three wins flash and reset

I was originally thinking three LEDs, but I did not have enough of each color and I think two that light and then a flashing pattern on the third win conveys the same message.

Physical Components


So I started by trying to get the bolt to launch properly. I coded the servo to continually rotate back and forth its full 180 degrees.

I first had the problem that it would not reset with the full rotation on the servo:


After some adjustments to the servo angle and the height of the washer on the bolt I had the opposite problem that the servo wasn't powerful enough to push it down all the way and would stall.

I end this process quickly to avoid damage to the servo




After a few more adjustments I got my first successful launch AND reset. 




I continued to build out the casing and work on the code and when I had it almost all together I realized that the flipping of the coin was so erratic that I could not predict its landing accurately. The randomness was perfect for a fair coin flip, but it would not stay within the bounds of my machine. 



To address the flying coin problem made a lid that you place on top of the catcher. Its irregular shape probably contributes to random flipping which makes the machine all the more fair.


Final Test


Once I worked out all the code and mocked up most of the casing I ran it through a final test.


As you see the coin flips irregularly and I record the score based on the flip result. The LEDs indicate the current score. Once Heads or Tails gets to three wins the LEDs flash and the game resets. 


Code & Circuit


I spent most of my time working on finalizing my physical components, so my code is fairly simple. I would definitely want to go back and abstract the repetitive pattern I used to create the flashing effect, but in terms of functionality it all works according to plan. 

My circuit is also quite simple, with just three buttons: 
  1. Blue: controls the servo and coin flip
  2. Red: records Heads wins controlling the red LEDs
  3. Green: records Tails wins controlling the green LEDs


Conclusion

I think my machine performed well in the context of my original design. If I were to make improvements it would probably be to the code first. I had some trouble with dealing with accumulators in my main loop and I would like to revisit the code to fix any little bugs.

If I really wanted to devote some time to it, I think it would have been best if the coin had flipped straight up and fell straight back down into the catcher. That would probably require a very precise angled hit and I would in all likelihood have to rehaul the physical components I used. Eventually a more compact and sealed casing would be required to make the product market worthy

I think it has a lot of viability outside of this class, but it would have to be in a more compact, durable, finalized form. If I was willing to sacrifice an Arduino I would definitely like to keep working on this and I'm sure my roommates and I would find a use for it, however as Arduino's are a little pricey for a coin flip I doubt I will keep it around for very long. That being said my easy access design means there is no reason I should not be able to return to it later without much difficulty. 

No comments:

Post a Comment