Assignment: Input / Output Coincidence Lab Assignment
Collaborators:
Description: Being a tea lover means you drink lot of tea everyday. And tea preparation isn't that easy. Especially when we are talking about tea in Indian style. So, if someone in your house is preparing tea, you also feel the urge to drink some tea. Wouldn't it be great if you can tell the person who is preparing tea using some digital gadgets. So I designed "I want tea" indicator using Arduino, Piezo Speakers and FSR. I used wired FSR and piezo speakers to tea coaster. So when you place a empty tea cup on tihs coaster it will play some music indicating you want tea. I'm actually interested in extending this assembly to various day to day situations and objects. Similar tools can be extremeley helpful for the people with speech impairments.
Components Used:
Arduino
Circuit Board
Wires
Tea Coaster
Piezo Speaker
FSR
Code:
int speakerOut = 7;
byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};
int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p";
// count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
// 10 20 30
int count = 0;
int count2 = 0;
int count3 = 0;
int MAX_COUNT = 24;
int statePin = LOW;
int fsrPin = 0; // select the input pin for the FSR
int ledPin = 11; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(speakerOut, OUTPUT);
}
void loop()
{
val = analogRead(fsrPin); // read the value from the sensor, between 0 - 1024
digitalWrite(speakerOut, LOW);
Serial.println(val);
if(val > 10)
{
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<8;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);
}
}
}
}
}
}