The Stubborn and Sleepy Housemate

Made by dvaglia

Found in Home Hack

Some housemates have a habit of hitting the “snooze” button on their alarm too many times. In an effort to efficiently awaken these types of housemates, an IOT alarm will be created. Once programmed, this alarm will first rouse the sleepy housemate with an audio alarm which will be quickly followed by an irritating display of LED lights. The only way to turn off the alarm will be to turn the lights on in the room. The photon will sense whether or not the lights have been turned on using a light sensor. In theory, once the housemate has gotten out of bed and turned the lights on, they will be awake enough to not go back to sleep.

0

Intention

The goal of this project is to provide my roommate with assistance in waking up every morning.  Currently, he has a tendency to repeatedly hit "snooze" on his alarm.  This results in him not getting out of bed until he is nearly late for work and woken me up with his repeated alarms.  To solve this problem, I created an alarm that will force him to get out of bed and turn the lights on before the alarm turns off.

0

Context

Knowing that my roommate would be more awake if he was forced to get out of bed and turn the lights on, I figured it would be helpful to design an alarm system that does just that.  The alarm is made up of a photon board, an alarm set button, a piezoelectric speaker, a photoresistor and an LED to enhance the alarm experience.

While this system will be used primarily in the morning, I find that it relates a strongly to devices that could be used at night.  For example, by using a series of photoresistors and motion sensors, a smart hallway could be created that illuminates only the area immediately around you so that it does not hurt you night vision.

This devices was inspired by a coffee maker alarm, a toy car alarm clock and a bit of programmer humor hidden in code:

https://particle.hackster.io/30039/the-ultimate-alarm-clock-86b95d?ref=search&ref_id=alarm&offset=3

https://particle.hackster.io/ddk220/photon-alarm-with-mozilla-os-2ff407?ref=search&ref_id=alarm&offset=0

https://learn.sparkfun.com/tutorials/sparkfun-inventors-kit-for-photon-experiment-guide/experiment-5-music-time

0

Process

To create this product, I approached the problem in small segments.  I first established how the alarm was to be tripped.  I wanted the alarm to be very simple to use and not require reprogramming between uses.  With that in mind, I established a simple delay timer.  After the alarm button is pushed, the device waits a programmed amount of time before it starts the alarm.  It is currently eight seconds, but it could easily be coded to a desired amount of sleep time.  It took some trial and error to get this right, so during this process I also added a "stop" button.  This button would not be used in the final product, but it was instrumental in testing the code.  

Next, I established my alarm tone.  Using code from SparkFun, I was able to establish a tune that would be played when the alarm went off in the morning.  For simplicity's sake, I also incorporated the flashing of the light directly into the tone loop.  This provided the added benefit of the LED blinking with the music.  

After the alert sounds and lights were completed, I began work on how the device would be turned off.  Using the code from class as an example, I programmed a function that would turn off the alarm once a photo resistor experienced prolonged, blight light.

0

Product

As stated before, the device is made up of a piezoelectric speaker, an LED array (made up of one LED in this iteration), a photoresistor, two buttons and a photon board.  Here is an image of the device configuration:

Displaying FullSizeRender.jpg 

The device features two buttons in this image.  As the second button serves as a manual shutoff, it will likely not be included in the final version.  The only shutoff that will exist on the system will be the photoresistor.

 Below is a sample video of the device working in action:

0
0
int LightSensor = A3;
int leds = D5;
int StartButton = A0;
int emergencyOff = A1;
const int speakerPin = D2;


int Alarming = 0;
int lightThresh = 150;
int timeElapsed = 0;
int lightReading = 0;


//nunber of notes and rests
const int songLength = 18;

//list of tones and rests
char notes[] = "cdfda ag cdfdg gf "; // a space represents a rest

//duration of the notes
int beats[] = {1,1,1,1,1,1,4,4,2,1,1,1,1,1,1,4,4,2};

//tempo of the song
int tempo = 150;


void setup()
{
  pinMode(speakerPin, OUTPUT);
  pinMode(LightSensor,INPUT);
  pinMode(leds,OUTPUT);
  pinMode(StartButton,INPUT);
  pinMode(emergencyOff,INPUT);

  digitalWrite(leds,LOW);
  // We only want to play the song once, so we'll put it in the setup loop

  //If you want your song to loop forever, place that code in the loop() below.
}


void loop()
{

  if (analogRead(StartButton) >= 3000){
     Alarming = 1;
     //can be set to any amount of time to accommodate a sleep goal
     delay(8000);
   }

  if (analogRead(emergencyOff) >= 3000){
     Alarming = 0;
     digitalWrite(leds, LOW);
   }



//Turning the alarm off with the light sensor
lightReading = analogRead(LightSensor);

   if (lightReading < lightThresh){
     timeElapsed = 0;
   }else{
     if (timeElapsed == 0){
         timeElapsed = millis();
     }
     if (timeElapsed + 2000 < millis() ){
         Alarming = 0;
     }
   }

Particle.variable("light", &lightReading, INT);

//The alarm sequence.  Lights flash and the audio alarm goes off
if (Alarming){
  int i, duration;


delay(500);


  for (i = 0; i < songLength; i++) // step through the song arrays
  {
    duration = beats[i] * tempo;  // length of note/rest in ms

    if (notes[i] == ' ')          // is this a rest?
    {
      delay(duration);            // then pause for a moment
    }
    else                          // otherwise, play the note
    {
      digitalWrite(leds, HIGH);
      tone(speakerPin, frequency(notes[i]), duration);
      delay(duration);            // wait for tone to finish
      digitalWrite(leds, LOW);
    }
    delay(tempo/10);              // brief pause between notes
  }


}
}


int frequency(char note)
{
  // This function takes a note character (a-g), and returns the
  // corresponding frequency in Hz for the tone() function.

  int i;
  const int numNotes = 8;  // number of notes we're storing

  // The following arrays hold the note characters and their
  // corresponding frequencies. The last "C" note is uppercase
  // to separate it from the first lowercase "c". If you want to
  // add more notes, you'll need to use unique characters.

  // For the "char" (character) type, we put single characters
  // in single quotes.

  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523};

  // Now we'll search through the letters in the array, and if
  // we find it, we'll return the frequency for that note.

  for (i = 0; i < numNotes; i++)  // Step through the notes
  {
    if (names[i] == note)         // Is this the one?
    {
      return(frequencies[i]);     // Yes! Return the frequency
    }
  }
  return(0);  // We looked through everything and didn't find it,
              // but we still need to return a value, so return 0.
}
Click to Expand
0

Reflection

My primary takeaway from this project was an appreciation for programming devices that do not always have an outward display of success.  In other words, code that I have written in previous classes on my PC will immediately tell me if my code is working correctly or not.  If the code is not working, I can run the program line by line to determine the error.  With the Photon, I have no way of easily isolating the problem.  Instead, I had to work in ways to segment my code while is going through its continuous loop.  I achieved this primarily by using buttons and cloud variables.  In future projects I will know to build in similar breaks to make debugging easier.

x
Share this Project

Found In
Courses

49-713 Designing for the Internet of Things

· 26 members

A hands-on introductory course exploring the Internet of Things and connected product experiences.


About

Some housemates have a habit of hitting the “snooze” button on their alarm too many times. In an effort to efficiently awaken these types of housemates, an IOT alarm will be created. Once programmed, this alarm will first rouse the sleepy housemate with an audio alarm which will be quickly followed by an irritating display of LED lights. The only way to turn off the alarm will be to turn the lights on in the room. The photon will sense whether or not the lights have been turned on using a light sensor. In theory, once the housemate has gotten out of bed and turned the lights on, they will be awake enough to not go back to sleep.

Created

January 25th, 2017