Jordane WilliamsSang Vang
Published

Music Junkie

A way to receive Bluetooth speaker shutoff warning notifications

BeginnerFull instructions provided8
Music Junkie

Things used in this project

Hardware components

Argon
Particle Argon
×1
Shock Sensor Module
×1
Microphone Sound Sensor
×1

Software apps and online services

Maker service
IFTTT Maker service
ThingSpeak API
ThingSpeak API
Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Shock Sensor Circuit

Sound Sensor Circuit

Code

Shock Sensor Code

C/C++
unsigned long time_last_vib;
unsigned long mytime; 
int jp = 0 ;
void setup() 
{
pinMode(D2, INPUT);
pinMode(D5, OUTPUT);
pinMode(D7, OUTPUT);
Particle.subscribe ("LED", toggled, MY_DEVICES);
}



void toggled(const char *event, const char *data) 
{
  // Handles integration response
  String myData = data;
  jp = myData.toInt();
  if (jp == 1)
    {
        digitalWrite(D7,HIGH);
        
    }
    else
    {
        digitalWrite(D7,LOW);
    }
}

void loop() 
{
    if (digitalRead(D2)==LOW) 
        {
            time_last_vib = millis();
            while ((millis()-time_last_vib) < 1000)
            {
                digitalWrite(D5, HIGH);
            }
            
            digitalWrite(D5,LOW);
        }
    else
        {
            mytime = millis();
            if ((mytime - time_last_vib > 5000) && (digitalRead(D7) == 0))
                {
                    Particle.publish("vib", "wp");
                }
        }
        
    
}

Sound Sensor Code

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



int soundsensor = A0 ;
int led2 = D7 ;
int p_input = D3 ;
int s_value = 0 ; 
int value = 0 ;

TCPClient client;

unsigned long myChannelNumber = 1962695;    // change this to your channel number
const char * myWriteAPIKey = "BAXF9EEF16DGAZS0"; // change this to your channels write API key

void setup() 
{
        Serial.begin(9600) ;
        Particle.subscribe("gg", myHandler , MY_DEVICES);
        pinMode(led2 , OUTPUT);
        pinMode (p_input, INPUT) ;
        ThingSpeak.begin(client);

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

void loop() 
{
           value = digitalRead(p_input);
        if (value == HIGH)
        { 
            digitalWrite (led2, HIGH) ;
            
        }
        else 
        {
            digitalWrite (led2, LOW) ;
        }
        
        String Digitaldata = String(value);
        
        
        Particle.publish("LED", Digitaldata, PRIVATE);
        
     //
        s_value = analogRead(soundsensor);
       //Serial.println(String(s_value) );//print analog value onto serial monitor

     
      // Recieves the Data
        String data = String(s_value);
      // Triggers the  integration
        Particle.publish("Sound", data, PRIVATE);
  
      delay(1000);
// read the input on analog pin 0:
int sensorValue = analogRead(A0);

// Write to ThingSpeak, field 1, immediately
ThingSpeak.writeField(myChannelNumber, 1, sensorValue, myWriteAPIKey);
//delay(15000); // ThingSpeak will only accept updates every 15 seconds.
}
//WiFiSignal sig = WiFi.RSSI();
//float quality = sig.getQualityValue();

Credits

Jordane Williams

Jordane Williams

1 project • 0 followers
Sang Vang

Sang Vang

1 project • 0 followers

Comments

Add projectSign up / Login