Things used in this project

Hardware components:
sparkfun sound
×1
11026 02
Jumper wires (generic)
Wires for sound (3) were soldered.
×7
Mfr 25frf52 10k sml
Resistor 10k ohm
×1
12002 04
Breadboard (generic)
×1
10167 01
DHT22 Temperature Sensor
×1
Photon new
Particle Photon
×1
Hand tools and fabrication machines:
Lasercutter
Laser cutter (generic)

Custom parts and enclosures

Enclosure
The enclosure is quite simple- even so we decided to use t-slots and acrylic for this.
enclosure_draft_FOPkqJ1PpR.ai
Illustrator Screenshot
Screen shot 2017 04 24 at 10 58 58 am gtcysejn0q

Schematics

Fritzing Diagram
The DHT temperature sensor uses 4 wires total. One of these wires must connect to the 3V3 on the photon. For the sound sensor, the necessary outputs are GND, VCC and gate. The gate wire must connect to A0 and the GND output connects to GND on the photon. VCC is the power source, so it must also connect to 3V3 on the photon.
Screen shot 2017 04 17 at 11 19 58 am ogavekcuot

Code

Sound and Temperature Code Arduino
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>



#define DHTPIN 4            // what pin we're connected to
#define DHTTYPE DHT22       // DHT 22 (AM2302)

DHT dht(DHTPIN, DHTTYPE);

double hum;                 // current hum
double temp;                // current temp

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 = 0 ;
int snd_min = 4096 ;
double snd_avg = 0;

const int blink_thresh = 3000;

unsigned long broadcast_interval = 1000;
unsigned long last_broadcast = 0;
unsigned long lastSample = 0 ;
unsigned long lastReset = 0 ;

void setup() {
    Serial.begin(9600);
    pinMode(DHTPIN, INPUT);
    
    Particle.variable("hum", hum);
    Particle.variable("temp", temp);
    Particle.variable("avg",snd_avg);
    Particle.variable("min",snd_min);
    Particle.variable("max",snd_max);
    

    Serial.begin(9600);
    pinMode(A0, INPUT); // mic AUD connected to Analog pin 0
    pinMode(D7, OUTPUT); // flash on-board LED
}

void loop() {    
    double checkHum = dht.getHumidity();
    double checkTemp = dht.getTempFarenheit();
    
    if (checkHum > 0 && checkHum < 100)
        hum = checkHum;
        
    if (checkTemp > 32 && checkTemp < 100)
        temp = checkTemp;
    
    Serial.println("Temp: " + String(checkTemp));
    Serial.println("Hum: " + String(checkHum));
    
    
    
    int mic_reading = analogRead(0); //Serial.println(mic_reading);
    blinkMic(mic_reading) ;
    averageReading(mic_reading) ; 
    broadcast() ;
    
    //this will reset the min and max, but keep in mind that those
    //large and small values will remain in the array for up to one
    //minute depending on the sample_rate
    checkReset() ;
        
    delay(3000);
}



void averageReading(int value) 
{
    unsigned long now = millis();

    if((now - lastSample) > sample_rate) 
    {
        // Shift all the values right by 1
        for(int i = array_size-1; i >= 1; i--) 
        {
            snd_array[i] = snd_array[i-1]; 
            if((snd_array[i] < snd_min) && (snd_array[i] > 0))
            {
                snd_min = snd_array[i];
            }
            if(snd_array[i] > snd_max)
            {
                snd_max = snd_array[i];
                
            }
        }
    
        snd_array[0] = value; 
    
        // Average of all non-zero elements in the array
        double avg_sum = 0; 
        int size = 0 ;
        for (int a=0; a < array_size; a++) 
        {
            if(snd_array[a] > 0)
            {
                size++ ;
                avg_sum += snd_array[a];
            }
        }
        snd_avg = avg_sum / size;
        
        lastSample = now ;
    }
}

//blink the onboard LED (D7) if reading is louder than threshold
void blinkMic(int reading) 
{
    if(reading > blink_thresh) 
    {
        digitalWrite(D7, HIGH);
    } 
    else 
    {
        digitalWrite(D7, LOW);
    }
}

//check to see if we should reset min and max
void checkReset() 
{
    unsigned long now = millis();
    
    //if it has been one minute since resetting min and max, reset
    if((now - lastReset) >= 60000) 
    {
        snd_max = 0 ;
        snd_min = 4095 ;
        lastReset = now ;

    }
}

//print out the values of avg, min and max to terminal
void broadcast() 
{
    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);

        last_broadcast = now;
    }
}

Credits

6694eba1a22356bc4d1aef905540d0ef
Emily Stummer
1 project • 1 follower
Contact
4f2cf0acdd66645612b066706b6d9e06
Juanairis Castaneda
1 project • 1 follower
Contact
2b5487718afec9d5930f07db4ad552b3
Diego Roman
1 project • 0 followers
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaBlog