Turn Down for What?!

Made by epeprah

Found in Home Hack

Since I live alone and have a subwoofer I have a habit of turning my music up. I never know if my neighbors are bothered because they don’t complain. To be kind to them I am designing a warning system that can let me know when I am being too loud.

0

Problem Statement:

Since I live alone and have a subwoofer I have a habit of turning my music up. I never know if my neighbors are bothered because they don’t complain. To be kind to them I am designing a warning system that can let me know when I am being too loud  
0

Goal

I will place a microphone in the hallway and have it send a signal to me when it picks up any sound. This way I can be more aware of when my sound is loud enough to go through walls and adjust it. 

0

Process

This project was divided into 4 parts: Powering On/Off, Listening and Publishing

Powering on and off - Using a button and an LED I created a switch and indicator light. The switch, since it is a tactile push button, required programming to have an on state and off state. Originally I was going to let the device continually listen and send data until it hit a certain threshold. Understanding that it would not be able to handle that while on battery power I switched my tactics.

I added a button to be press to trigger the  on-state is stored. The LED will also turn on to indicate that the device is sampling. 

Listening -  The microphone is picking up the highest and lowest signals over a 50 millisecond period and subtracting them to figure out the range sound level. It would then compare it to a given sound level to see if it was too loud. 

To find that given sound level I would have run the microphone thorough the serial port to get ambient hallways sound levels. I had trouble doing that because the serial port didn't work with windows. Instead I got an average using the particle.variable output and added just a bit more sound outside of the error range. 

Publishing - Simply put the final part of the device was to use the checked sample data to know when I was being too loud. If the sampled sounds ever exceeded the average I calculated and entered it would publish a too loud event to the particle. Using IFTTT I then had the messages sent to my cell phone.

0

Reflection

In retrospect this project was pretty easy but a necessity in my apartment complex. I found roadblocks to completion that required new information to fix:

On and Off states: First lesson is if I want to use switches, I will use mechanical switches. Effectively using switch statements were complex "if" statements that would work under some conditions and not others. with some help I was able to find that using the "!=" and currentState variables can help you easily vary the between on and off. 

Sampling: Not having the serial port available can be hard but its not impossible to get around. To get the threshold value for sampling I needed ambient hallway noise. This was impossible to get since I have no internet at home. So I got ambient institute noise. Once I was able to get a good average over 5 quiet minutes I checked the St Dev and added it in.

This project has helped me gain skills in gathering real world data to use in my devices. In the future I'd love it if the device could learn it's surroundings and let me know what an ambient level of noise is.

0
/*This project is to develop a microphone that can tell me when the sound coming through my door is too loud only at time when I want to hear that.
Press the button to turn on listening mode
Listen for the Decibels to get louder than a specific number of Decibels
Send Message to phone telling me to turn it down
Wait 1 minute(s) and see if the sound has gone down
*/
int led = D0;//Led Pin
int mic = A0;//Led mic
int btn = D2;//Led btn
int sample = 0;//Current mic reading at a specific time
bool dbLevel = FALSE;//initialize the Microphone
bool ledState = FALSE;//initialize the LED
int btnState = LOW;// initialize the button
int sampleWindow = 50;//sample every 50ms
int toggle = 0;// The power is Off
bool sampling = false;
// When was it last published
unsigned long lastPublishTime=0;
void setup(){
  pinMode(btn, INPUT_PULLUP);
  pinMode(mic, INPUT);
  pinMode(led, OUTPUT);
  Particle.variable("Noiselevel", &sample, INT);
  Particle.variable("Tooloud",&dbLevel);
  Particle.variable("button", &btnState);
  Serial.begin(9600);
  digitalWrite(led, LOW);
}
void loop(){
  TurnOn();
  if( sampling ){
    sample = sampleNoise();
      // if it's too loud...
      if( dbLevel ){
          publishAlert();
      }
  }

  delay(100);
}
void TurnOn()
{
  // find out if the button is pushed
  // or not by reading from it.
  int currentButtonState = digitalRead(btn);
  if( currentButtonState == LOW && btnState != currentButtonState ){
      sampling = !sampling;
      digitalWrite(led, sampling);
  }
  btnState = currentButtonState;
}
//function for sampling noise
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 );
    // 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;
    }
    else{
      lowest_sample = sample;
    }
  }

  int peak_to_peak = highest_sample - lowest_sample;

  if( peak_to_peak > 400 ){
    dbLevel = TRUE;
  }else{
    dbLevel = FALSE;
  }

  return peak_to_peak;
}
void publishAlert()
{
  if(millis()-lastPublishTime>60000)
  {
      Particle.publish("diot2017/elvin/too_loud" );
      lastPublishTime = millis();
  }
}
Click to Expand
0
Turn down for what
Elvin Peprah - https://youtu.be/A50W-X58l1o
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

Since I live alone and have a subwoofer I have a habit of turning my music up. I never know if my neighbors are bothered because they don’t complain. To be kind to them I am designing a warning system that can let me know when I am being too loud.

Created

February 1st, 2017