User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Lab 5: Input / Output Coincidence: The Sad Thermos

Submitted by Michael Manoochehri on Wed, 10/08/2008 - 23:02

Assignment: Input / Output Coincidence Lab Assignment

Collaborators:

Assignment: Input / Output Coincidence Lab Assignment
Collaborators: Michael Manoochehri

 

The Sad Thermos

Assignment:

Create an artifact that features input and output that occur at the same place.

 

Description:

A Thermos bottle plays a somewhat morose tune when the top is opened. Upon adding a flower to the bottle, a much happier tune is played. However, once the flower is removed, the Thermos reverts to its sad song. The songs are "toggled on" by a photocell near the top of the bottle. There is an force sensistive resistor at the bottom of the Thermos, and if something is placed in it, it will play the happier song.

 

Components List:

  • 2 X 10K Ohm Resistors
  • 1 Breadboard
  • 1 FSR
  • 1 Photocell
  • 1 Piezo buzzer
  • 1 Arduino Board
  • 1 Old Thermos
  • 1 SF Giants Shotglass
  • 1 Paper "Flower"
  • Lots of electrical tape

 

Notes:

The circuitry is very similar to other projects using two inputs - the challenge for me was to find ways to stuff the components into the Thermos bottle.

I also had some challenges using the Arduino programming environment. I wanted to create a function that would play any arbitrary collection of notes. I tried to pass an array of "note" information into a function that would play it, but I couldn't quite get it to work. Since the Arduino language is based on C, I tried a C-like "pass by reference," but I kept generating errors, so I ended up unelegantly repeating code (see code below).

Although I had originally picked the Thermos used in this assignment because of it's large size, I found that stuffing our regular breadboards into it was very difficult. I soldered my components to a much smaller, thinner components board in my toolbox. This was a much better fit.

 

Thermos Circuits

Code used in this Assignment:

Arduino Code:

/*
*
* Simple 2 song Piezo Speaker toggle, for use inside a broken thermos.
*
* Photocell input toggles Songs to play
*
* "Sad" Song is default. FSR input toggles Happier song to play
*
*/



int speakerOut = 7;               
byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};  
int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};

byte happyMelody[] = "2a2e2a2e2g2f2e2d2a2e2a2e2g2f2e2d2C2c2C2c2g2f2e2d";
int happyMelodylength = 18;

byte sadMelody[] = "2a2a2a2a2e2e2e2e2b2g2e2e2a2a2b2g2e2e";

int count = 0;
int count2 = 0;
int count3 = 0;
int MAX_COUNT = 24;
int statePin = LOW;


// Analog pin settings
int photocellIn = 0;    
int fsrIn = 1;    



// Values
int photocellVal = 0;   
int fsrVal = 0;  



int checkSum     = 0; // Aggregate pot values
int prevCheckSum = 0;
int sens         = 3; // Sensitivity theshold, to prevent small changes in 
                      // pot values from triggering false reporting
// FLAGS
int PRINT = 1; // Set to 1 to output values
int DEBUG = 0; // Set to 1 to turn on debugging output

void setup()
{
  pinMode(speakerOut, OUTPUT);
  Serial.begin(9600);     // Open serial communication for reporting
}

void loop()
{


  photocellVal = analogRead(photocellIn);  // read input pins
  fsrVal = analogRead(fsrIn); 


	if (photocellVal > 50) { // If the thermos is open...

		if (fsrVal > 450) {
    		Serial.println("Play the Happy tune!");
				// Play Start
 				digitalWrite(speakerOut, LOW);     
  				for (count = 0; count < MAX_COUNT; count++) {
					for (count3 = 0; count3 <= (happyMelody[count*2] - 48) * 30; count3++) {
  						for (count2=0;count2<8;count2++) {
    						if (names[count2] == happyMelody[count*2 + 1]) {       
      							digitalWrite(speakerOut,HIGH);
      							delayMicroseconds(tones[count2]);
      							digitalWrite(speakerOut, LOW);
      							delayMicroseconds(tones[count2]);
   							 } 
    						if (happyMelody[count*2 + 1] == 'p') {
      							// make a pause of a certain size
      							digitalWrite(speakerOut, 0);
      							delayMicroseconds(1);
    						}
  						}
					}
  				} // Play End!

				
		
		} else  {
	
    		Serial.println("Play the Sad tune!");
				// Play Start
 				digitalWrite(speakerOut, LOW);     
  				for (count = 0; count < MAX_COUNT; count++) {
					for (count3 = 0; count3 <= (sadMelody[count*2] - 48) * 30; count3++) {
  						for (count2=0;count2<8;count2++) {
    						if (names[count2] == sadMelody[count*2 + 1]) {       
      							digitalWrite(speakerOut,HIGH);
      							delayMicroseconds(tones[count2]);
      							digitalWrite(speakerOut, LOW);
      							delayMicroseconds(tones[count2]);
   							 } 
    						if (sadMelody[count*2 + 1] == 'p') {
      							// make a pause of a certain size
      							digitalWrite(speakerOut, 0);
      							delayMicroseconds(1);
    						}
  						}
					}
  				} // Play End!
 		}

	} else {
   			Serial.println("Thermos is closed");
	}



  
        Serial.print("Photocell:");        // ...then print the values.
        Serial.print(photocellVal);         
        Serial.print("\t"); 
        Serial.print("FSR:  ");        
        Serial.print(fsrVal);              
        Serial.println(); 
       
}