Henry DavalosMarco PerezDennis Dervisevic
Published

Sound Detector

Noise detector made to measure sound in a classroom.

IntermediateShowcase (no instructions)10 hours1,041
Sound Detector

Things used in this project

Hardware components

Photon
Particle Photon
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
SparkFun Sound Detector
×1

Software apps and online services

Particle.io
Google Sheets
Google Sheets
Maker Case
Used to create the dimensions for enclosure

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)

Story

Read more

Custom parts and enclosures

Picture of Wiring - 1

Picture of Wiring - 2

File missing, please reupload.

Picture of Wiring - 3

Enclosure - First Draft

Enclosure (Acrylic Top) - Final Draft

Enclosure (Wood) - Final Draft

Enclosure (Side)

Enclosure (Opening)

Opening for the power cable

Enclosure (Side)

Enclosure (Side)

Enclosure (Top)

Code

Particle.io Sound Sensor Code

Arduino
Code used to collect sound data
const long sample_rate = 50; // time between samples (in miliseconds)
const int array_size = 1200; // 1000/50=20 * 60=1200
int snd_array[array_size] = {};
int snd_max, prev_max = 10000;
int snd_min, prev_min = 4096;
double snd_avg = 2048;

const int blink_thresh = 2048;

unsigned long broadcast_interval = 3000;
unsigned long last_broadcast = 0;

void averageReading(int value) {

    // Shift all the values right by 1
    for(int i = array_size-1; i >= 1; i--) {
        snd_array[i] = snd_array[i-1]; 
    }

    snd_array[0] = value; // add new value to the first position in the array // NOPE

       // Average array
    float avg_sum = 0; 
    for (int a=0; a <= array_size; a++) {
        avg_sum  = avg_sum + snd_array[a];
    }
    //Serial.println("out of average loop") ;
    snd_avg = avg_sum / array_size;
}

void minReading(int value) {
    if(value < prev_min) { 
        snd_min = prev_min = value;
    }
}

void maxReading(int value) {
    if(value > prev_max) { 
        snd_max = prev_max = value;
    }
}

void blinkMic(int reading) {
    if(reading > blink_thresh) {
        digitalWrite(D7, HIGH);
    } else {
        digitalWrite(D7, LOW);
    }
}


void checkBroadcast() {
    unsigned long now = millis();
    if((now - last_broadcast) > broadcast_interval) {
        Serial.print("Avg: "); Serial.println(snd_avg);
        Serial.print("Min: "); Serial.println(snd_min);
        Serial.print("Max: "); Serial.println(snd_max);
        snd_avg = 10000;
        snd_min = 4096;
        snd_max = 0;
        snd_array[array_size] = {};
        last_broadcast = now;
    }
}

void setup() {
    Serial.begin(9600);
    pinMode(A0, INPUT); // mic AUD connected to Analog pin 0
    pinMode(D7, OUTPUT); // flash on-board LED
    Particle.variable("sound", snd_avg);
}

void loop() {
    int mic_reading = analogRead(0); //Serial.println(mic_reading);
    blinkMic(mic_reading);
    minReading(mic_reading);
    averageReading(mic_reading); 
    Serial.println("average: "+ String(snd_avg)) ;
    
    checkBroadcast();

    delay(sample_rate);
}

Google Script Editor

Arduino
function collectCurrent() {
  "use strict";
  try
  {
    //Replace the device ID below with your Photon's unique device ID
    var deviceID = "25003f001747343337363432";
    
    //Replace the access token below with your Photon's unique access token
    var accessToken = "5719a250c4800704dadcbe78f91913d2dc840914";
    
    //Replace the value below with you group ID
    var groupID = 400;
    
    //Replace the room number below with location of the Photon
    var room = 224;
    
    var sheet = SpreadsheetApp.getActiveSheet();

    // Fetch the value of the testValue variable from the Spark Cloud API.
    // The name of your variable in Particle's cloud must match the variable in the URL below.
    var response = UrlFetchApp.fetch("https://api.spark.io/v1/devices/" + deviceID + "/sound?access_token=" + accessToken);

    // Parse the JSON and extract the testValue.
    var jsonResponse = JSON.parse(response.getContentText());
    var sound = jsonResponse.result;

   // response = UrlFetchApp.fetch("https://api.spark.io/v1/devices/" + deviceID + "/temp?access_token=" + accessToken);
   // jsonResponse = JSON.parse(response.getContentText());
  //  var temp = jsonResponse.result;    

    // Create a timestamp.
    var timeStamp = new Date();

    // Append the timestamp and the temperature to the sheet.
    sheet.appendRow([timeStamp, groupID, room, sound]);
   //sheet.appendRow([timeStamp, groupID, room, temp, hum]);
  }
  catch (e)
  {	
    // If something doesn't work, log it, then rethrow the error.
	Logger.log(e.name + ": " + e.message);
	throw (e);
  }
}

Credits

Henry Davalos

Henry Davalos

-1 projects • 0 followers
ICL student
Marco Perez

Marco Perez

-1 projects • 0 followers
Dennis Dervisevic

Dennis Dervisevic

0 projects • 1 follower

Comments

Add projectSign up / Login