Lab 5 :: Friendlier Alarm Clock

Submitted by ajeeta on Sun, 03/03/2013 - 23:35
ajeeta's picture

Description

 

This alarm clock attempts to improve the experience of 'waking up' every morning. Rather than jolting a person into consciousness, the alarm wakes her up slowly and gradually, by progressively increasing the intensity (brightness and pitch) of its light and sound output. 
 
A photocell in the clock senses ambient light conditions, and the light reading controls the intensity of the alarm sound- in low ambient light conditions (say early dawn), sound is gentler; in higher ambient light conditions (say later in the morning), sound intensity is higher. The intensity also increases proportionately with the increasing illuminance produced by the LEDs in the clock.
 
A force sensor mounted on the top of the clock controls the 'snooze' and 'turn off' functionalities. With a gentle tap, the alarm snoozes. With a more forceful tap, the alarm shuts off.
 
*Delays for the snooze function and increasing LED brightness are scaled down for quicker demo.
 
 
Video

Demo Video

 

Components

1 Arduino Uno

1 Breadboard

3 220 ohm Resistors

2 10k ohm Resistors

1 Photocell

1 Force Sensing Resistor

3 LEDs

1 Piezo Speaker

Wires and USB Cable

Diffuser for Alarm: Water Glass wrapped with Tissue

 

 

Code

 

/* Alarm Clock
 * -----------
 * (cleft) 2005 D. Cuartielles for K3
 * Adapted by Ajeeta Dhole on 03/03/13
 */
 
int FSR = 1;    // Select the input pin for the FSR
int photocell = 0;  // Select the input pin for the photocell
int speakerOut = 7;  // Select the output pin for the speaker 
int redLEDPin = 9;   // Select the output pin for the green LED 
int blueLEDPin = 10;  // Select the output pin for the blue LED 
int greenLEDPin = 11;  // Select the output pin for the red LED
 
int FSRval = 0;
int photoVal = 0;
 
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;
 
void setup() {
  pinMode(greenLEDPin, OUTPUT);  // declare the greenLEDPin as an OUTPUT
  pinMode(blueLEDPin, OUTPUT);  // declare the blueLEDPin as an OUTPUT
  pinMode(redLEDPin, OUTPUT);  // declare the redLEDPin as an OUTPUT
  pinMode(speakerOut, OUTPUT);
  Serial.begin(9600);
}
 
void loop() {
  for( int i=0; i< 255; i++ ) {  // Increase red pin brightness to 255
    analogWrite(redLEDPin, i);
    delay(30);
    photoVal=analogRead(photocell);
    //Serial.println(photoVal);
  }
  for( int i=0; i<3; i++ ) {
    playMelody(); // Play sound for 3 cycles.
  }
  for( int i=0; i< 255; i++ ) {  // Increase blue pin brightness to 255
    analogWrite(blueLEDPin, i);
    delay(20);
    photoVal=analogRead(photocell);
    //Serial.println(photoVal);
  }
  for( int i=0; i<5; i++ ) {
    playMelody(); // Play sound or 5 cycles.
  }
  for( int i=0; i< 255; i++ ) {  // Increase green pin brightness to 255
    analogWrite(greenLEDPin, i);
    delay(20);
    photoVal=analogRead(photocell);
    //Serial.println(photoVal);
  }
  soundLoop(); // Play sound in loop until snoozed or stopped.
}
 
void playMelody() {
  digitalWrite(speakerOut, 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(speakerOut,HIGH);
            delayMicroseconds(35000/photoVal);
            digitalWrite(speakerOut, LOW);
            delayMicroseconds(35000/photoVal);} 
          if (melody[count*2 + 1] == 'p') {
          // make a pause of a certain size
            digitalWrite(speakerOut, 0);}
        }
      }
    }
  FSRval = analogRead(FSR);
  Serial.println(FSRval);
}
 
void soundLoop() {
  while (FSRval < 2) { // Plays sound in loop until force is detected.
    playMelody();}
  if (FSRval > 2 && FSRval < 600) {  //Snoozes the alarm. At end of snooze time, starts playing sound in loop until force is detected.
    analogWrite(redLEDPin, 150);
    digitalWrite(greenLEDPin, LOW);
    digitalWrite(blueLEDPin, LOW);
    delay(6000);
    FSRval = 0;
    digitalWrite(redLEDPin, HIGH);
    digitalWrite(greenLEDPin, HIGH);
    digitalWrite(blueLEDPin, HIGH);
    soundLoop();}
  if (FSRval >= 600) { // Shuts off the alarm.
    digitalWrite(redLEDPin,LOW);
    digitalWrite(greenLEDPin,LOW);
    digitalWrite(blueLEDPin,LOW);
    delay(10000000);} // This is a hack. Don't know how to terminate loop(). 'break' doesn't work.
}
 
Circuit
Alarm
0
Your rating: None
Drupal theme by Kiwi Themes.