Lane of Things 2018 - Sound

Sound sensor construction for the Lane of Things project at Wrigley Field.

AdvancedFull instructions provided254
Lane of Things 2018 - Sound

Things used in this project

Hardware components

Photon
Particle Photon
×2
Electron
Particle Electron
×3
DFRobot Gravity: Analog Sound Level Meter
×5

Software apps and online services

Google Sheets
Google Sheets
Particle Web IDE

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)
X-Carve

Story

Read more

Custom parts and enclosures

Sound Sensor Enclosure (Front)

Sound Sensor Enclosure (Back)

Schematics

Photon Schematic Pic

Photon Schematic

PCB getting cut

Code

Photon/Electron Code

Arduino
Collects sound values from the microphone. Measures voltage and converts into decibels.
#define SoundSensorPin A1  //this pin read the analog voltage from the sound level meter
#define VREF  3.3  //voltage on AREF pin,default:operating voltage
double voltageValue,dbValue;

double count;

long avg_accum = 0;
double dbMin = 100;
double dbMax = -1;
double dbAvg = 0;


// measure volage, return dB
double dBA()
{
    voltageValue = analogRead(SoundSensorPin) / 4096.0 * VREF;
    return dbValue = voltageValue * 50.0;  //convert voltage to decibel value
}    

double minuteReading() {
    double avg = avg_accum/count;
    digitalWrite(7, HIGH); // just a little blinky so we know things are working
    return avg;
}

void resetValues() {
    avg_accum = 0;
    count = 0;
    dbMin = 100;
    dbMax = -1;
    digitalWrite(7, LOW);
}


void setup()
{
    pinMode(7, OUTPUT);
        
    Particle.variable("min",dbMin);
    Particle.variable("max",dbMax);
    Particle.variable("avg",dbAvg);
    
    Time.local();
}


void loop()
{  
    double dB = dBA(); //Serial.println(dB);
    Serial.println(dB);
    avg_accum += dB; // accumulate values for average
    count++;         // accumulate count for avg    
    
    if(dB > dbMax) { dbMax = dB; } // get max
    if(dB < dbMin) { dbMin = dB; } // get min
    
    if(Time.second() == 59) {

       dbAvg = minuteReading();
       resetValues(); // reset values for the next minute count
  }
}

Spreadsheet code

Java
This code pulls the data from the Photons and Electrons once every minute and compiles them into a spreadsheet
var sheet;
var accessToken = [Your Particle Access Token];


function getSoundLevel() {
  try
  {  
    sheet = SpreadsheetApp.getActiveSheet();
    
    
    var deviceObject = UrlFetchApp.fetch("https://api.spark.io/v1/devices?access_token="+accessToken);
    deviceObject = JSON.parse(deviceObject.getContentText());
    
    for (var i =0; i < deviceObject.length;i++){
        addRowFromDevice(deviceObject[i]);
    }
    
   
  } catch (e)
  {	
	Logger.log(e.name + ": " + e.message);
	throw (e);
  }
}

function addRowFromDevice(device){
  var min = 0; 
  var max = 0;
  var avg = 0;
  var status = 0;
  var connected = (device.connected==true);
  
  try{
    if(device.connected!=false){  
      var response = UrlFetchApp.fetch("https://api.spark.io/v1/devices/" + device.id + "/max?access_token=" + accessToken);
      var jsonResponse = JSON.parse(response.getContentText());
      max = jsonResponse.result;
      var response = UrlFetchApp.fetch("https://api.spark.io/v1/devices/" + device.id + "/min?access_token=" + accessToken);
      var jsonResponse = JSON.parse(response.getContentText());
      min = jsonResponse.result;
      var response = UrlFetchApp.fetch("https://api.spark.io/v1/devices/" + device.id + "/avg?access_token=" + accessToken);
      var jsonResponse = JSON.parse(response.getContentText());
      avg = jsonResponse.result;
    }
  }catch(e){
   connected = false; 
    
  }
    var timeStamp = new Date();

  sheet.appendRow([timeStamp, min, max ,avg, device.id, ((!connected)?"Not ":"")+ "Connected",device.name]);
  
}

Credits

Julian O'Hern

Julian O'Hern

2 projects • 1 follower
Sinai Martinez

Sinai Martinez

2 projects • 5 followers
Maxwell Krolak

Maxwell Krolak

2 projects • 5 followers
Lane Tech Junior
Roberto Jacobo

Roberto Jacobo

2 projects • 6 followers
Junior at Lane Tech
Maureen Thomas

Maureen Thomas

2 projects • 3 followers
Nick Udell

Nick Udell

2 projects • 1 follower
Student, maker, roboticist, aspiring engineer
Timothy Bargo

Timothy Bargo

2 projects • 0 followers
Alek Popovic

Alek Popovic

2 projects • 1 follower
Jacob Brada

Jacob Brada

1 project • 0 followers

Comments

Add projectSign up / Login