BuzzMe Monster Alarm Clock!
Materials Used:
Arduino Uno, Piezo Speaker, Potentiometer, LEDs,Resistors, Force Sensitive Resistor
In Lab Section:
We interfaced a Piezo speaker to the Arduino play tunes which could be sent over the serial port.
Homework Section: Input Output Coincidence:
Goal: To design a system which has input and output at the same location. Any of the above materials may be used.
BUZZME! - The Concept:
Quick and easy to use alarm clock.. specifically for short term alerts like:
Wake from a nap!
Go down to get the laundry!
Get up and stretch!
BuzzMe is a monster who sleeps while you fiddle with the pot to light up his eyes. Each eye is a 5 second delay on the clock. Lighting up his eyes makes him angry, but he will bear with you. If you hit his tongue though, he will count (in seconds) exactly 5 times the number of eyes lit up, and then start screaming.
Hint: Hitting him again will keep him quiet!
The video demo can be seen at http://www.youtube.com/watch?v=HtskyFBPGvQ
Code:
/*
BuzzMe!
Quick and easy to use alarm clock.. specifically for short term alerts like:
Wake from a nap!
Go down to get the laundry!
Get up and stretch!
Time display: Number of LED's lit up = time to start buzzer
*/
// Ringtone settings
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 = 100;
int statePin = LOW;
int potPin = 0; // select the input pin for the potentiometer
int fsrPin = 1; // select the input pin for the FSR
int buzzPin = 2; // select the pin for the Piezo speaker
int led1Pin = 13; // select the pin for LED1
int led2Pin = 12; // select the pin for LED2
int led3Pin = 11; // select the pin for LED3
int fsrVal = 0; // variable to store the value coming from the FSR
int potVal = 0; // variable to store the value coming from the pot
void setup() {
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(led3Pin, OUTPUT);
pinMode(buzzPin, OUTPUT);
Serial.begin(9600);
}
void buzz(){ // play tune 24 times or until buzzer is pressed Based on playmelody.txt
digitalWrite(buzzPin, LOW);
for (count = 0; count < MAX_COUNT; count++) {
statePin = !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(buzzPin,HIGH);
delayMicroseconds(tones[count2]);
digitalWrite(buzzPin, LOW);
delayMicroseconds(tones[count2]);
}
if (melody[count*2 + 1] == 'p') {
// make a pause of a certain size
digitalWrite(buzzPin, 0);
delayMicroseconds(500);
}
// Read the FSR
fsrVal = analogRead(fsrPin);
// if the FSR is pressed, stop playing and return
if(fsrVal >= 500)
{
digitalWrite(buzzPin,LOW);
delayMicroseconds(100);
fsrVal = 0;
return;
}
}
}
}
}
void countdown(int time)
{
// delay 5 seconds per lit LED. jump back to input mode when the fsr is pressed
for(int i = 0; i<= 5*time; i++)
{
delay(1000); // wait a second
if(analogRead(fsrPin) >= 500)
{
return;
}
Serial.print("time left = ");
Serial.print(5*time-i);
Serial.println(" seconds");
}
}
void loop() {
int time = 0;
potVal = analogRead(potPin); // read the value from the sensor, between 0 - 1024
if((potVal >= 0) && (potVal <= 300)) // time = 1
{
analogWrite(led1Pin,255);
analogWrite(led2Pin,0);
analogWrite(led3Pin,0);
time = 1;
}
else if((potVal >= 300) && (potVal <= 600)) // time = 2
{
analogWrite(led1Pin,255);
analogWrite(led2Pin,255);
analogWrite(led3Pin,0);
time = 2;
}
else if((potVal >= 600)) // time = 3
{
analogWrite(led1Pin,255);
analogWrite(led2Pin,255);
analogWrite(led3Pin,255);
time = 3;
}
fsrVal = analogRead(fsrPin); // read the value from the FSR
if(fsrVal >= 500) // start the countdown
{
countdown(time);
buzz();
fsrVal = 0;
delayMicroseconds(1000);
}
}