User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Light Alarm Clock

Submitted by naryasece on Wed, 10/08/2008 - 22:33

Assignment: Input / Output Coincidence Lab Assignment

Collaborators:

Light Alarm Clock

This alarm clock is for those people who like to rise with the sun. The alarm clock will play two melodies when it becomes light outside. You can use the force sensor to set the threshold at which the light will activate the alarm. If it is significantly brighter outside, then the alarm will play a second melody (just in case you slept in!) When the user holds down the force sensor, the LED blinks slowly to let the user know it is in setup mode. When it starts blinking faster, then the Arduino board records the ambient light in the room, and sets that as the threshold to play music.

 

Ideally, I wanted to make this a morning dove, which would sing when the sun came up until you squeezed its tail. It would have been nice to program in a song like "Here Comes The Sun" by the Beatles

 

Parts used:

1 force sensor

1 light pot

2 10k resistors

1 22 ohm resistor

1 red led

Arduino board

wires

1 Piezo speaker

 

Test use:

waking up

you can see me trying to turn off the alarm clock in the morning

 

close up of my board

This is a close up of the board

 

The code:

 

 

/* Light Alarm clock-
 * wakes you up when the light outside is just right
 *
 *
 * 2008 Sean Carey
 */
 //melody setup
 byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};  
 int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
  byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p";
  byte melody2[] = "3b3g3a3f3g3e3f3d3e3c3C3a3b3g3a3f3g3e3f3d3e3c33C";
  // 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;

//program setup
 
 
 int potPin=0; // select input for the photocell
 int speakerPin= 7; // output for speaker
 int LEDpin = 9; //pin for the LED
 int squeezePin = 5; // force sensor input for pin
 
 int ambientLight = 500; //storage for the ambient light
 int forceSensor = 400; //stores the value of the force sensor
 int inputForce=0; //storage for the input from user
 int inputLight=0; //storage fro the input from photo sensor
 int playSong=0;//boolean for playing the song
 int val=0;
 int setcount=0;
 
 void setup(){
   pinMode(LEDpin,OUTPUT);
   pinMode(speakerPin, OUTPUT);
   beginSerial(9600);
   Serial.println("ready");
 }
 void loop(){
   inputForce=analogRead(squeezePin); //reads values from the force sensor
   //Serial.print("Input Force ");
   //Serial.print(inputForce);
   //Serial.println();
   inputLight = analogRead(potPin); // reads values from the light sensor
   //Serial.print("Light value ");
   //Serial.print(inputLight);
   //Serial.println();
   

   if (inputForce >forceSensor){
    //playSong=0;
    digitalWrite(LEDpin, HIGH);
    
    if (setcount < 5){
    delay(1000);
    digitalWrite(LEDpin,LOW);
    delay(1000);
    }
    if (setcount > 5){
      ambientLight=inputLight;
      delay(500);
      Serial.println(ambientLight);
      digitalWrite(LEDpin,LOW);
      delay(500);
    }
   
    setcount=setcount+1;
    //Serial.println(setcount);
    //digitalWrite(LEDpin, LOW);
    

      
    }
    
    if (inputForce < forceSensor){
      if (count>10){
           count=0; 
      }
    
    if (inputLight > ambientLight+20){
     //playSong=1;
        Serial.println(inputLight);
     digitalWrite(speakerPin, LOW);     
  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(speakerPin,HIGH);
          delayMicroseconds(tones[count2]);
          digitalWrite(speakerPin, LOW);
          delayMicroseconds(tones[count2]);
        } 
        if (melody[count*2 + 1] == 'p') {
          // make a pause of a certain size
          digitalWrite(speakerPin, 0);
          delayMicroseconds(500);
        }

      }

    }

  }//melody1
  
  if (inputLight > ambientLight+200){
          Serial.println(inputLight);
     digitalWrite(speakerPin, LOW);     
  for (count = 0; count < MAX_COUNT; count++) {
    statePin = !statePin;
    //digitalWrite(LEDpin, statePin);
    for (count3 = 0; count3 <= (melody2[count*2] - 48) * 30; count3++) {
      for (count2=0;count2<8;count2++) {
        if (names[count2] == melody2[count*2 + 1]) {       
          digitalWrite(speakerPin,HIGH);
          delayMicroseconds(tones[count2]);
          digitalWrite(speakerPin, LOW);
          delayMicroseconds(tones[count2]);
        } 
        if (melody[count*2 + 1] == 'p') {
          // make a pause of a certain size
          digitalWrite(speakerPin, 0);
          delayMicroseconds(500);
        }

      }

    }

  }//melody2
  }// if it is really bright outside  
  
  }//play loop
  
      
    }
   }