# House from Up

Description:

I decided to channel energy from the Disney movie Up. I programmed the piezo to output the theme song from the movie when someone steps on the doorstep of the house. Let’s pretend the house is up in the sky, per the cotton of cloud beneath it. :}

Components Used:

• 1 Arduino
• 1 Resistor (10kΩ)
• 1 piezo
• 1 FSR potentiometer
• 1 3D printed house (out of PLA)
• cotton (to simulate a cloud)

Code:

```/* Play Melody
* -----------
*
* Program to play melodies stored in an array, it requires to know
*
* The calculation of the tones is made following the mathematical
* operation:
*
* timeHigh = 1/(2 * toneFrequency) = period / 2
*
* where the different tones are described as in the table:
*
* note frequency period PW (timeHigh)
* c 261 Hz 3830 1915
* d 294 Hz 3400 1700
* e 329 Hz 3038 1519
* f 349 Hz 2864 1432
* g 392 Hz 2550 1275
* a 440 Hz 2272 1136
* b 493 Hz 2028 1014
* C 523 Hz 1912 956
*
* (cleft) 2005 D. Cuartielles for K3
*/

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

byte names[] ={ 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', 'D', 'E', 'F', 'G', 'A', 'B'};
unsigned int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 852, 759, 716, 639, 568, 506};

byte melody[] = "3F3A3F9E5p3F3A3F5E2p3D3F3D4C2p3D8A8G1p3D8A8G1p3D1p9D8p";

int val = 0;
int count = 0;
int count2 = 0;
int count3 = 0;
int MAX_COUNT = 28;
int statePin = LOW;

void setup() {
// pinMode(ledPin, OUTPUT);
pinMode(speakerOut, OUTPUT);
}

void loop() {
digitalWrite(speakerOut, LOW);
if (val > 0 ){
for (count = 0; count < MAX_COUNT; count++) {
statePin = !statePin;
digitalWrite(ledPin, statePin);
for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) {
for (count2=0;count2<15;count2++) {
if (names[count2] == melody[count*2 + 1]) {
digitalWrite(speakerOut,HIGH);
delayMicroseconds(tones[count2]);
digitalWrite(speakerOut, LOW);
delayMicroseconds(tones[count2]);
}
if (melody[count*2 + 1] == 'p') {
// make a pause of a certain size
digitalWrite(speakerOut, 0);
delayMicroseconds(500);
}
}
}
}
}
}

```

Up Melody