Hi
im using a sound sensor combined with a audio spectrum analyzer
On thingspeak could measure from the same pin the dB and the frequenzy. And to id the data i have 3 value as testperson.
but I was wondering if I can do it here as well?
#define BLYNK_PRINT Serial
// SimpleTimer - Version: Latest
#include <SimpleTimer.h>
#include <FHT.h> //source http://wiki.openmusiclabs.com/wiki/ArduinoFHT?action=AttachFile&do=view&target=ArduinoFHT4.zipt&target=ArduinoFHT4.zip
#include <AudioAnalyzer.h>//source image.dfrobot.com/image/data/DFR0126/library/AudioAnalyzer%20v1.3.zip
#include <SPI.h>
#include <WiFi101.h>
#include <BlynkSimpleMKR1000.h>
//------------Initialize the variables for the AUDIO sensor
#define SoundSensorPin A0 //this pin read the analog voltage from the sound level meter
#define VREF 5.0
//to identify which freq band range is the loudest,
// its need to be labelled by its peak num
// Always show the max magnitude from the sound signal
Analyzer Audio = Analyzer(4,5,0);//Strobe pin ->4 RST pin ->5 Analog Pin ->0
//Analyzer Audio = Analyzer();//Strobe->4 RST->5 Analog->0
//String FreqNames[] = {"63", "160","400", "1K","2.5K", "6.25K","16K"};
int FreqNames[] = {63,160,400,1000,2500,6500,16000};
int FreqVal[7];//
int max_index;//
//int hz = 0;
float voltageValue,dB;
//to identify the testperson
int testperson = 1;
// Create instance of WiFi client
WiFiClient client;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
void setup()
{
// Debug console
Serial.begin(57600);
Audio.Init();//Init module
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000,soundFreq);
timer.setInterval(1000,soundVol);
timer.setInterval(1000,testp);
}
void soundFreq()
{
Audio.ReadFreq(FreqVal);//return 7 value of 7 bands pass filiter
//Frequency(Hz):63 160 400 1K 2.5K 6.25K 16K
//FreqVal[]: 0 1 2 3 4 5 6 magnitude
max_index = 0;
for(int i=1; i<7; i++) //
{
if (FreqVal[max_index] < FreqVal[i]) max_index = i;
}
Serial.print("Frequenzy: ");
Serial.print(FreqNames[max_index]);
Serial.println("hz");
Blynk.virtualWrite(V0,FreqNames[max_index]);
}
void soundVol()
{
voltageValue = analogRead(SoundSensorPin) / 1024.0 * VREF;
dB = voltageValue * 50.0;
Serial.print("Volume: ");
Serial.print(dB);
Serial.println("dB");
Blynk.virtualWrite(V1, dB);
}
void testp()
{
Serial.print("testperson: ");
Serial.print(testperson);
Blynk.virtualWrite(V2, testperson);
}
void loop()
{
// Connects to the WiFi
// If the network does not need a password: WiFi.begin(ssid);
WiFi.begin(ssid, pass);
delay(10000); // Waits 10 seconds to confirm connection
// Print WiFi strength information
Blynk.run();
timer.run();
printCurrentNet() ;
// Disconnects from the WiFi
//WiFi.disconnect();
}
void printCurrentNet() {
// Print the WiFi signal strength:
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI): ");
Serial.print(rssi);
Serial.println(" dBm");
}