Michael DiCenzoSteven Adkins
Published

Sound Disturbance and Temperature Detector for Gamers

Utilize sensors to monitor sound disturbances and temperature levels in a gaming environment. If thresholds are reached, alerts are sent.

IntermediateFull instructions provided180
Sound Disturbance and Temperature Detector for Gamers

Things used in this project

Hardware components

Elegoo Small Sound Sensor
×1
Elegoo Digital Temperature Sensor
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×2
LED (generic)
LED (generic)
×2
Resistor 220 ohm
Resistor 220 ohm
×2
Jumper wires (generic)
Jumper wires (generic)
×1
ELEGOO Upgraded 37 in 1 Sensor Modules Kit V2.0
ELEGOO Upgraded 37 in 1 Sensor Modules Kit V2.0
×1
Personal Ceramic Heater
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
ThingSpeak Small Sound Sensor Live Data
ThingSpeak Digital Temperature Live Data

Hand tools and fabrication machines

Digilent Screwdriver
Digilent Screwdriver

Story

Read more

Schematics

Small Sound Sensor Particle Argon Circuit

Digital Temperature Sensor Particle Argon Circuit

Code

Small Sound Sensor with Temperature LED Trigger

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

int sensorPin = A0;
int Led = D7;
int buttonpin = D3;
int sensorValue = 0;
int val = 0;

int Templight = 0;

int led1 = D6;
//initializes temperature
int temperature_f;
int Light_Position;

void setup ()
{
     Serial.begin(9600);
    
    // Subscribing to integration response event
    Particle.subscribe("hook-response/Sound", myHandler, MY_DEVICES);
    pinMode(led1, OUTPUT);
   
    Particle.subscribe("temp1", temperatureHandler, ALL_DEVICES);
    //
    pinMode (Led, OUTPUT);
    pinMode (buttonpin, INPUT);
}

void myHandler(const char *event, const char *data) {
  // Handles integration response
}

void loop ()
{
      val = digitalRead(buttonpin);
        
     if (val == HIGH)
     {
       digitalWrite (Led, HIGH);
      // 
     }
     else
     {
       digitalWrite (Led, LOW);
      //
     }
     String Digitaldata = String(val);
     Particle.publish("LedTrigger", Digitaldata, PRIVATE);
     //
     sensorValue = analogRead(sensorPin);
      Serial.println(String(sensorValue) );//print analog value onto serial monitor

      delay(250);
     
      // Recieves the Data
         String data = String(sensorValue);
      // Triggers the  integration
         Particle.publish("Sound", data, PRIVATE);
  
    // Delay of 2 seconds
      delay(2000);
    //*********************************
        if (temperature_f >=  78){
        //Temperatures greater than 78 degrees Fahrenheit will close the circuit and turn on the light
        digitalWrite(led1, HIGH), Light_Position = 1;
         }
         else if (temperature_f <= 77){
          //Temperatures less than 77 degrees Fahrenheit it will open the circuit and turn off the light
           digitalWrite(led1, LOW), Light_Position = 0;
          }
          else{
          //Any Temperature readings between temperatures will restart the loop
             }
     
    
    Particle.publish("Light", String(Light_Position), PUBLIC);
      delay(2000);
    //
      
   
}

void temperatureHandler(const char *event, const char *data1){
    //sets a new string, which has been "pew" to take in the temperature_f data
    String pew = data1;
    //Converts this new string "pew" into the previously defined integer "temperature_f"
    temperature_f = pew.toInt();
}

WiFiSignal sig = WiFi.RSSI();
float quality = sig.getQualityValue();

// Lines 5-6, 27-28, 37-48; Source: 'Sound-sensor Module Arduino Datasheet'.  https://www.robotshop.com/media/files/pdf/sound-sensor-module-arduino-datasheet.pdf .
// Line 1-4, 7-12, 17-29, 31-85, 92-93; Source: 'Workspace Environment Device'. https://particle.hackster.io/iot-group-20/workspace-environment-device-ac7486 .
// Line 13-15, 25, 65-79, 85-90; Source: 'IOT Temperature Sensor'. https://www.hackster.io/team-52/iot-temperature-sensor-6117be .

Digital Temperature Sensor with Sound LED Trigger

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

int Trigger;
int analogvalue = 0;
int temp_f;
// Sets D6 as pin to control LED
int led2 = D6;
int Sound;
int Light_Position;
TCPClient client;
// Channel number and Api key to get data to print to thingspeak
unsigned long myChannelNumber = 1934155;
const char * myWriteAPIKey = "B2VUYQX6Z3WWH948";

void setup(){
Serial.begin(2000);

  ThingSpeak.begin(client);
  
  Particle.variable("analogvalue", analogvalue);
  Particle.variable("temp_f", temp_f);
  pinMode(led2, OUTPUT);
  // Code from argon with sound data 
   Particle.subscribe("LedTrigger", temperatureHandler, ALL_DEVICES);

  pinMode(A0, INPUT);
}

void loop()
{
    delay(1500);
  // Read the analog value of the sensor (TMP36)
  analogvalue = analogRead(A0);
  //Convert the analog reading into degrees fahrenheit
  temp_f = (analogvalue*-.08099688473520249+135.99688473520249);

    if (Trigger == HIGH){
        // When the sound is higher than the threshold set by the potentiometer, the circuit will close, turning on the light
        digitalWrite(led2, HIGH), Light_Position = 1;
    }
    else if (Trigger == LOW){
        //When the sound is less than the threshold set by the potentiometer, the circuit will open, turning off the light
        digitalWrite(led2, LOW), Light_Position = 0;
    }
    else{
        //when the Sound reading directly at the threshold set by the potentiometer, it will restart the loop.
    }
     
    
 Particle.publish("Light", String(Light_Position), PUBLIC);
    delay(2000);

  
  Particle.publish("temp1",String (temp_f), ALL_DEVICES);
  ThingSpeak.setField(1,temp_f);
  Serial.print(temp_f);
  Serial.println("temp_f");
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  delay(2000);

}
    void temperatureHandler(const char *event, const char *data1){
    //sets a new string, which is defined as "pew" to take in the sound data
    String pew = data1;
    //Converts this new string "pew" into the previously defined integer "Trigger"
    Trigger = pew.toInt();
    }
    
//************************************************************************************************************************************
// References:
// Line 1 to Line 70; Source: 'IOT Temperature Sensor'. https://www.hackster.io/team-52/iot-temperature-sensor-6117be .
// Lines 38-48; Source: 'Sound-sensor Module Arduino Datasheet'. https://www.robotshop.com/media/files/pdf/sound-sensor-module-arduino-datasheet.pdf .

Credits

Michael DiCenzo

Michael DiCenzo

1 project • 1 follower
Steven Adkins

Steven Adkins

1 project • 1 follower

Comments