Wearable Alarm Clock

In this project, I worked on a shirt that also acts are your alarm clock. The motivation behind it was I wanted to create an alarm clock that is not so easy to get rid of in the morning. If alarm clock is embedded in your clothing, hopefully it will “alarm” you more in the morning and also be harder to get rid of.

 

I used 12 button keypad to set the time duration until alarm sets off, and used buzzer + vibrator as the output device. Biggest challenge I had was trying to figure out the 12 button keypad input, because the documentation provided online wasn’t consistent with the device I used.  

Photos:

 

 

Here’s the code I used:

 

/*

 * Author: Sungjoon Steve Won (stevewon@gmail.coM)

 */

 

//Pin indicator for the keypad matrix

int row1 = 10;

int row2 = 7;

int row3 = 8;

int row4 = 9;

int col1 = 12;

int col2 = 13;

int col3 = 11;

 

//Variables declared to deal with keypad input

int val1 = 0;

int val2 = 0;

int val3 = 0;

int val4 = 0;

int val5 = 0;

int val6 = 0;

int val7 = 0;

 

 

int vibratorPin = 2; //output pin for vibrator

int buzzerPin = 3; //output pin for buzzer

int ledPin = 4; //pin for LED

 

//Other indicators

int alarmOff = 0; //If set to 1, alarm should go off

int setAlarmNext = 0; //If set to 1, set alarm next time loop comes around

 

void setup() {

  pinMode(row1, INPUT);

  pinMode(row2, INPUT);  

  pinMode(row3, INPUT);  

  pinMode(row4, INPUT);     // declare pushbutton as input

  pinMode(col1, OUTPUT);

  pinMode(col2, OUTPUT);  

  pinMode(col3, OUTPUT);  

 

  pinMode(buzzerPin, OUTPUT); //Buzzer pin

  Serial.begin(9600);

 

}

 

void loop(){

  int thisKey = getKey(); //Detect input from keypad

 

 

  if (thisKey == 10) { //If input if “*”, use it to set Alarm.

 

    digitalWrite(ledPin, HIGH);   // sets the LED on

    delay(1000);                  // waits for a second

    digitalWrite(ledPin, LOW);    // sets the LED off

    delay(1000);                  // waits for a second

 

    setAlarmNext = 1;

    Serial.println(“3”);

 

    thisKey = getKey();

    int alarmDuration = thisKey * 1000; //For the purposes of demonstration, make alarm keypad number seconds

    delay(alarmDuration); 

 

    int wakeUpSteps = 10; //steps used to determine how strong wake-up alerts should be

    do {

      wakeUp(wakeUpSteps);

      thisKey = getKey();

      wakeUpSteps–; //Make it stronger & faster next time

    }

    while (thisKey != 11);

    analogWrite(vibratorPin, 0); //turn off vibrator

 

 

    Serial.println(“2”);   

   }

}

 

//Function that calls buzz and vibrate functions.

void wakeUp(int stepNum) {

    if (stepNum <= 1) {

      analogWrite(vibratorPin, (2000));  //Vibrate 

      buzz(buzzerPin, 2500, 500); // buzz the buzzer on pin 4 at 2500Hz for 1000 milliseconds

      delay(100); // 1 second delay

    }

    else {

      analogWrite(vibratorPin, (1000-stepNum*100));  //Vibrate 

      buzz(buzzerPin, 2500, 500); // buzz the buzzer on pin 4 at 2500Hz for 1000 milliseconds

      delay(stepNum*100); // 1 second delay

    }

}

 

 

//10 = *

//11 = #

int getKey() {

  digitalWrite(col1, HIGH);

  digitalWrite(col2, LOW);

  digitalWrite(col3, LOW);

 

 

  if (digitalRead(row1) == HIGH) {

     Serial.print(“Num 1\n”); 

     return 1;

  }

  if (digitalRead(row2) == HIGH) {

     Serial.print(“Num 4\n”); 

     return 4;

  }

  if (digitalRead(row3) == HIGH) {

     Serial.print(“Num 7\n”); 

     return 7;

  }

  if (digitalRead(row4) == HIGH) {

     Serial.print(“Num *\n”); 

     return 10;

  }

 

  digitalWrite(col1, LOW);

  digitalWrite(col2, HIGH);

  digitalWrite(col3, LOW);

 

 

  if (digitalRead(row1) == HIGH) {

     Serial.print(“Num 2\n”); 

     return 2;

  }

  if (digitalRead(row2) == HIGH) {

     Serial.print(“Num 5\n”); 

     return 5;

  }

  if (digitalRead(row3) == HIGH) {

     Serial.print(“Num 8\n”); 

     return 8;

  }

  if (digitalRead(row4) == HIGH) {

     Serial.print(“Num 0\n”); 

     return 0;

  }

 

 

  digitalWrite(col1, LOW);

  digitalWrite(col2, LOW);

  digitalWrite(col3, HIGH);

 

 

  if (digitalRead(row1) == HIGH) {

     Serial.print(“Num 3\n”); 

     return 3;

  }

  if (digitalRead(row2) == HIGH) {

     Serial.print(“Num 6\n”); 

     return 6;

  }

  if (digitalRead(row3) == HIGH) {

     Serial.print(“Num 9\n”); 

     return 9;

  }

  if (digitalRead(row4) == HIGH) {

     Serial.print(“Num #\n”); 

     return 11;

  }

 

  digitalWrite(col1, LOW);

  digitalWrite(col2, LOW);

  digitalWrite(col3, LOW);

 

  return -1;

}

 

//Imported from http://rob.faludi.com/itp/arduino/buzzer_example.pde

void buzz(int targetPin, long frequency, long length) {

  long delayValue = 1000000/frequency/2; // calculate the delay value between transitions

  //// 1 second’s worth of microseconds, divided by the frequency, then split in half since

  //// there are two phases to each cycle

  long numCycles = frequency * length/ 1000; // calculate the number of cycles for proper timing

  //// multiply frequency, which is really cycles per second, by the number of seconds to 

  //// get the total number of cycles to produce

 

  for (long i=0; i < numCycles; i++){ // for the calculated length of time…

    digitalWrite(targetPin,HIGH); // write the buzzer pin high to push out the diaphram

    delayMicroseconds(delayValue); // wait for the calculated delay value

    digitalWrite(targetPin,LOW); // write the buzzer pin low to pull back the diaphram

    delayMicroseconds(delayValue); // wait againf or the calculated delay value

  }

}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s