Things used in this project

Hardware components:
10167 01
DHT22 Temperature Sensor
×1
13285 01
PIR Motion Sensor (generic)
×1
12758 02
SparkFun SparkFun Electret Microphone Breakout
×1
12002 04
Breadboard (generic)
×1
Photon new
Particle Photon
×1
Software apps and online services:
Google sheets
Google Google Sheets
Hand tools and fabrication machines:
Lasercutter
Laser cutter (generic)
09507 01
Soldering iron (generic)

Custom parts and enclosures

Enclosure Design
We decided to make the enclosure to look like a radio since the location of the sensors/enclosure would be the dance room which makes the radio design completely relevant.
809_jH8GWqRmAR.ai
Prototype Photos
This is a group of photos that show the prototypes and designing process of the enclosure
Screen shot 2017 04 24 at 2 33 20 pm wz2uoz1nyg
DATA CHART(Temperature)
A chart for temperature over time.
Screen shot 2017 04 24 at 2 44 01 pm md30yo1oz3
DATA CHART(Humidity)
A chart for temperature over time.
Screen shot 2017 04 24 at 2 44 11 pm gcw39ticqr
DATA CHART(Sound Average)
A chart showing the average of sound levels over time.
Screen shot 2017 04 24 at 2 44 48 pm d7ah5ohoej
DATA CHART(Motion)
A chart showing whether motion was present (value = 1) over showing no motion (value = 0)
Screen shot 2017 04 24 at 2 43 21 pm cnpdokpsuo
Data - Cleaned and Cut
Our set of data that shows the classroom, time, motion, sound, temperature and humidity.
-lot_-_group_809_-_sy1617_-_data_-_cleaned_and_cut_data_f8qkiASius.csv
Picture of Enclosure Design
Picture of Enclosure Design
Screen shot 2017 04 24 at 2 51 09 pm htzll1pezd

Schematics

Project Design 2
This is the general Idea of how we hooked it up. We used different sensors with the same amount of connectors as substitutes for the PIR and sound detectors.
projectdesign2_thlcCtYayS.fzz
Hookup
Screen shot 2017 04 24 at 3 14 22 pm ahapxp2l1a

Code

LofT-Com.inoC/C++
#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, prev_max = 0;
int snd_min, prev_min = 4096;
double snd_avg = 2048;
int inputPin = D2;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status
int motVal = 0;

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]; 
        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 array
    float avg_sum = 0; 
    int size = 0 ;
    for (int a=0; a <= array_size; a++) 
    {
        if(snd_array[a] > 0)
        {
            size++ ;
            avg_sum  = avg_sum + snd_array[a];
        }
    }
    snd_avg = avg_sum / size;
}

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 = 0;
        snd_min = 4096;
        snd_max = 0;
        snd_array[array_size] = {};
        last_broadcast = now;
    }
}

void setup() {
    pinMode(inputPin, INPUT);     // declare sensor as input
    Serial.begin(9600);
    pinMode(DHTPIN, INPUT);
    pinMode(A0, INPUT); // mic AUD connected to Analog pin 0
    pinMode(D7, OUTPUT); // flash on-board LED

    Particle.variable("hum", hum);
    Particle.variable("temp", temp);
    Particle.variable("snd_avg", snd_avg);
    Particle.variable("snd_max", snd_max);
    Particle.variable("snd_min", snd_min);
    Particle.variable("motion", motVal);
    
    
}


void loop() {
    int mic_reading = analogRead(0); //Serial.println(mic_reading);
    blinkMic(mic_reading);
    averageReading(mic_reading); 
    checkBroadcast();

    delay(sample_rate);
    double checkHum = dht.getHumidity();
    double checkTemp = dht.getTempFarenheit();
    
    if (checkHum > 0 && checkHum < 100)
        hum = checkHum;
        if (val == HIGH) {            // check if the input is HIGH
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      motVal = 1;
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
   // digitalWrite(ledPin, LOW); // turn LED OFF
    if (pirState == HIGH){
      // we have just turned of
      Serial.println("Motion ended!");
      motVal = 0;
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  } 
    if (checkTemp > 32 && checkTemp < 100)
        temp = checkTemp; 
        if (val == HIGH) {            // check if the input is HIGH
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      motVal = 1;
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
   // digitalWrite(ledPin, LOW); // turn LED OFF
    if (pirState == HIGH){
      // we have just turned of
      Serial.println("Motion ended!");
      motVal = 0;
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  } 
  val = digitalRead(inputPin);  // read input value
  
    
    Serial.println("Temp: " + String(checkTemp));
    Serial.println("Hum: " + String(checkHum));
    Serial.println("Mot: "+String(motVal));    
}

Credits

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

Similar projects you might like

Lightweight Sliding Door Automator
Intermediate
  • 1,535
  • 7

Work in progress

Automate the opening and closing of a lightweight sliding door (e.g. a screen door), including remote controls on your phone.

Christmas Gift Box
Intermediate
  • 3,633
  • 595

Full instructions

Christmas Gift Box plays music and sends an email when it is opened.

Carbon Fiber Vacuum Chamber
Intermediate
  • 2,905
  • 94

Full instructions

Our project is a carbon fiber vacuum chamber that is monitored by multiple particle photons and various sensors.

ConnectTheDots with Particle Azure IoT Hub Integration
Intermediate
  • 841
  • 8

Protip

This project will allow you to connect your Particle device into an Azure IoT Hub for viewing data in real-time through an ASP.NET web app!

What should I wear outside?
Intermediate
  • 5,044
  • 67

Full instructions

A whimsical weather clock powered by Particle and forecast.io

Garage Door Opener with Blynk
Intermediate
  • 367
  • 2

Open, close and monitor a garage door opener with a smart phone using a Particle Photon and the Blynk application.

Add projectSign up / Login