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. 

Wednesday, March 23, 2016

Processing Lab

Oscillating circle with Processing


  • What language is Processing based on?
    • Java
  • In your own words, what is the difference between a global and a local variable?
    • A global variable is a variable that is defined and available in the global scope -- is made available throughout the entire file. A local variable is a variable only available in a specific scope, like in a function definition. 
  • What data type does the draw() function return when it is called?
    • It doesn't return a data type -- void type
  • In your own words, explain in detail what the code below the "//keep the circle in bounds" comment does
    • It checks the upper and lower part of the circle and if either go outside the range of the processing window it changes the direction of the ball -- making the bounce of effect at the edges. 

Sending serial data from an Arduino circuit to a Processing application



Etch-a-Sketch assignment



The Circuit:

The Code:

This video was extremely helpful in explaining and helping me code multiple variables through processing:

 https://vimeo.com/97527889





Monday, March 21, 2016

Interactive Toy - Cat Fishin



My toy is intended as a game for cats and their owners. The biggest design challenge I recognized is actually getting a cat interested in anything I made as they are pretty temperamental and aloof at the best of times. Also I am allergic to cats, so my interaction with them has to be a little distant making playing tricky.



* Disclaimer: Let it be known that this cat (Lucy) just gave birth to kittens last weekend, so she was especially disinterested in me, therefore the fact that I got any response was a win in my opinion.

My solution was to create a toy/game that would allow someone who is allergic to play with a cat and interest the cat by playing on its instincts for chasing small things that scurry along the floor.

Subject: Cat
  • No opposable thumbs
  • Bad attitude
  • Four legs
  • Interacts with mouth a lot
  • Near the ground
  • Instinct for chasing things
  • A known allergen
Affordances:
  • Interaction is twofold:
    • The human controls the "reel" 
    • The cat interacts with/chases the "bait"
  • The reel is designed with a simple ON/OFF knob that allows for easy interaction with the human
  • The bait is a colorful little bag sure to catch a cats eye that moves in an interesting way to play on the hunting instincts of the cat.
    • The bait is also soft cloth and nontoxic accounting for the possibility that the cat might get it in its mouth at some point. 
  • The interaction is designed to maintain some distance to reduce possibility of allergy attack.

The Device:


The circuit is a dc motor controlled by a potentiometer

The Code:
Improvements:

  • To improve upon this design I would like to be able to reel OUT as well as IN. The circuit and code would have to be changed to allow for a polarity change to get the dc motor to spin backwards.
  • Also speed control with the potentiometer would be another possible improvement. 







Tuesday, March 8, 2016

Servo Lab

Servo motor controlled by pulse width modulation from an Arduino




  1. Why do we add a delay after rotating the servo?
    • Since we can't output an analog signal and digital signals are either High or Low the delay in digital output can mimic variable analog output -- Pulse width modulation. It allows us to adjust the servo's speed.
  2. What is the pulse width that corresponds with a 45 rotation?
    • According to Arduino their servos run on a pulse width range of about 1ms - 2ms while around 1.5ms would bring the servo to 90˚, so to bring the servo to 45˚ a pulse width of around 1.75ms would be needed
  3. Why doesn't the Arduino reliably turn a servo motor at the same time as it plays a sound from a piezo speaker using the tone() function?
    • Because it uses pulse width modulation for both and the Arduino doesn't have the capability to send pulse width to two separate components.


Servo motor controlled by potentiometer with Arduino



Servo motor controlled by a pushbutton momentary switch




My Code:







Wednesday, March 2, 2016

Transistor Labs

Force-sensitive resistor and LED with Arduino




  1. Give ideas of 2 applications of this sensor in the field of improving accessibility for handicapped people.
    • As a way to help wheelchair access, a pressure sensor on the ground that when activated by a person size weight could open automatic doors would be a good application. 
    • Also, since a pressure sensor can handle such variable input it would be very useful for someone who has very little movement. For example a quadriplegic or someone who relies on a motorized wheelchair could control acceleration with just the pressure of a single finger. 


Temperature sensor and LED circuit with Arduino



  1. We use a voltage divider circuit for potentiometers, force-sensitive resistors, and many other sensors. Why do we not need to use a voltage divider circuit with this temperature sensor?
    • The temp sensor has it's own variable voltage output, it controls it internally, therefore we don't have to control it. 
  1. Unlike pressure sensed by force-sensitive resistors, or rotation sensed by potentiometers, ambient temperature sensed by temperature sensors almost always changes very gradually and slowly. How does this affect the design of interactions based on this sensor?
    • Interactions with direct immediate input with the expectation of direct immediate output would not work. As the sensor is more calibrated to the ambient environment and inputs, processes, and outputs very slowly over time the interactions it can facilitate must also be in tune to the ambient environment. For example a thermostat that turns on at a certain temp and turns off when the environment has reached another temp.
  2. Given the range of temperatures at which this sensor works, please give 2 ideas for applications of this sensor. Applications may involve anything from scientific research to artistic endeavors, but they should necessitate the use of this sensor, as opposed to other sensors.
    • As I said above, this sensor would be ideal for a thermostat to regulate the temp of a room by turning the heat on or off depending on a previously input range.
    • As an art project I think it would be really interesting to set up a room with the full color spectrum of lighting and use this sensor to change the 'coolness' and 'warmth' of the color of the lighting, but based on the ambient temperature of the room. So blue lights = cold, red lights = hot, and as the temp changes the color of light slowly changes. 

Transistor as switch
(Sorry about the narration, was talking politics with my roommate)

  1. Why is the LED turned on by the switch dimmer than the LED turned on by the transistor?
    • The transistor and the 560 ohm resistor must offer less resistance than the 10k resistor and the switch, therefore the first LED is receiving more current.
  1. Give the approximate current flowing through each leg of the circuit (ignore any affect the transistor might have on the current flow or voltage drop).
    • i_switch = V/R = 5V / 10k ohms = 0.5mA
    • i_transistor = V/R = 5V / 560 ohms = 8.9mA

Transistor as amplifier

  1. How does turning the potentiometer to maximum resistance affect the sensitivity of the circuit to the photo-resistor's signal, as compared to turning the potentiometer all the way to minimum resistance?
    • The potentiometer is used to tune the sensitivity of the photoresistor. With the potentiometer at max resistance the photoresistor controls most of the current to the LED making the circuit more sensitive, at min potentiometer resistance the LED is getting current directly therefore is less sensitive to the photoresistor.

Transistor controlled by Arduino

As Switch:

As Amplifier: