NOT Alarm

Made by Pengyuan Huang

Found in Home Hack

Not to disturb user's daily routine of setting the alarm on the phone, this device is not designed to be an alarm but enhance the function of alarms. It works by detecting the alarm sound in the morning and starting timing. If no motion of leaving the bed detected after a while, it will start its own alarm tone. Further down, it sends message to roommate for help.

0

Intention

One morning my roommate was overslept for his class. I was in the room and did not notice until he came out of the room. I could help to wake him up if I knew he was in the room. This incident inspired this project.

0
NotAlarm
Pengyuan Gerry Huang - https://www.youtube.com/watch?v=o8hMmyW_HFM
0

Context

There are many similar projects of web enabled alarm clock. The unique part of this project is it does not require user interaction with the device. Instead, the device is triggered by the sound of user's own alarm clock.

0

Process

At the beginning of design, I planned to do a alarm clock that sends message to the roommate if the user failed to wake up. A pressing question is what UI to be used for user to set the alarm time. A text message requires user to type only in correct syntax, while a standalone app is definitely overkill for just an alarm. With this in mind, I looked for method to allow the device to synchronize with with the users' own alarm. Then I choose to use a mic to detect the alarm sound from the phone and triggers the system.

0

Product

How does it work:

Starting 6am, the device will started to monitor the sound in the room. Once alarm sound detected, it starts the timing and activates the PIR motion sensor placed near the ground. If no motion of leaving the bed detected in 5mins, it will activate its own alarm sound. In another 5mins, the devices sends a message to the roommate for help. If motion detected anytime, the alarm will be stopped. The system will only be triggered once in the day to prevent false alarm triggered by the noise in the day time. System resets at 6am.  

0
#include "captouch.h"
#define CAPTOUCH_DEBUG

// Audio

//Connections:
// - 5 V to mic amp +
// - GND to mic amp -
// - Analog pin to microphone output
int mic_pin = A0;
// store the noise level
// from the microphone
int noise_level = 0;
//PIR sensor
int inputPin = D0;
int pirState = LOW;             // we start, assuming no motion detected
int val = LOW;                    // variable for reading the pin status
int calibrateTime = 10000;      // wait for the thingy to calibrate
//LED to indicate system triggered
int ledPin = D7;

const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)

// Noise level to trigger the system
const int alarmTreshhold = 250;

// To track if the system has been trigglered in the same day
bool triggeredToday = false;

//timer after alarm triggered
int timeElapsed = 0;

//Pizeo Variables
int speakerPin = D1;

// create an array for the notes in the melody:
//C4,G3,G3,A3,G3,0,B3,C4
int melody[] = {1908,2551,2551,2273,2551,0,2024,1908};

// create an array for the duration of notes.
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {4,8,8,4,4,4,4,4 };

//Time to reset the system
int resetHour = 5;
int resetMinute = 59;

void setup()
{

  Particle.variable( "noise", noise_level );
  Particle.variable( "triggered", triggeredToday );
  Particle.variable( "val", val);
  Serial.begin(9600);
  pinMode( inputPin, INPUT_PULLDOWN );
  pinMode( ledPin, OUTPUT );
  //Piezo
  pinMode( speakerPin, OUTPUT );
  Time.zone( -5 );

}

void loop(){
  //reset system in the morning
  if (resetHour == Time.hour() and resetMinute == Time.minute() ){
  triggeredToday = false;
  }
  noise_level = sampleNoise( );
	Serial.print("sensorValue ");
  Serial.println( noise_level );

//System triggered by the phoen alarm, start countddown for further actions
  if (triggerSystem () == true ) {

    digitalWrite (ledPin, HIGH);
    timeElapsed = millis();
    while (PIRmain () == false){
      Particle.process();
      if( timeElapsed + 5000 < millis() ){ //adjust timer to your own setting
        playNotes(); //system alarm
      }
      if( timeElapsed + 10000< millis() ){ //adjust timer to your own setting
        Particle.publish("Wake up!","It's time!"); //publish event for IFTTT message
        timeElapsed = millis()-5000; //reset timer for another 5s (adjust to your own timing)
      }
    }
    digitalWrite (ledPin, LOW);
  }
}



int sampleNoise( )
{

  unsigned long startMillis = millis();  // Start of sample window
  int highest_sample = 0;
  int lowest_sample = 1000;
  // collect data for 50 mS
  while (millis() - startMillis < sampleWindow)
  {
     int sample = analogRead( mic_pin );
     // invert the range, and convert it to a percent
     sample = map( sample, 0, 4095, 1000, 0 );
     // now see if the sample is the lowest;

     if ( sample > highest_sample ){
      highest_sample = sample ;
     }
     if ( sample < lowest_sample ){
       lowest_sample = sample;
     }
  }

  int peakToPeak = highest_sample - lowest_sample;

  return peakToPeak;
}

//To check if system is triggered by the high alarm sound
bool triggerSystem()
{
  if (triggeredToday == false and noise_level > alarmTreshhold){
      triggeredToday = true;
      Particle.publish("alarm");
      return true;
    }
  else {
    return false;
  }
}

//PIR Functions
bool PIRmain () {
  // if the sensor is calibrated
  if ( calibrated() )
  {
  // get the data from the sensor
  readTheSensor();
  // report it out, if the state has changed
  reportTheData();
  }
  if (pirState == HIGH){
    return true;
  }
  return false;
}

void readTheSensor() {
  val = digitalRead(inputPin);
}

bool calibrated() {
  return millis() - calibrateTime > 0;
}

void reportTheData() {

  // if the sensor reads high
  // or there is now motion
  if (val == HIGH) {

    // the current state is no motion
    // i.e. it's just changed
    if (pirState == LOW) {
      // we have just turned on
      // Update the current state
      pirState = HIGH;
      //setLED( pirState );
    }
  } else {
    if (pirState == HIGH) {
      // we have just turned of
      // Update the current state
      pirState = LOW;
      //setLED( pirState );
    }
  }
}

void playNotes()
{
    // iterate over the notes of the melody:
    for (int thisNote = 0; thisNote < 8; thisNote++) {

      // to calculate the note duration, take one second
      // divided by the note type.
      //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
      int noteDuration = 1000/noteDurations[thisNote];
      tone(speakerPin, melody[thisNote],noteDuration);

      // to distinguish the notes, set a minimum time between them.
      // the note's duration + 30% seems to work well:
      int pauseBetweenNotes = noteDuration * 1.30;
      delay(pauseBetweenNotes);
      // stop the tone playing:
      noTone(speakerPin);
    }
}
Click to Expand
0

Reflection

I spent tremendous time debugging both software and hardware. Surprises were everywhere. 

Other than this, the data from mic is not reliable enough. As analog input, random noise affects the reliability of the system. A low-pass filter should be added to process the data. 

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.


Focused on
About

Not to disturb user's daily routine of setting the alarm on the phone, this device is not designed to be an alarm but enhance the function of alarms. It works by detecting the alarm sound in the morning and starting timing. If no motion of leaving the bed detected after a while, it will start its own alarm tone. Further down, it sends message to roommate for help.

Created

January 25th, 2017