now it seems that Volume works in both code
Apology to share this whole, but I dont know how else could I explain better.
In my test code it can id in realtime the peak of the frequenzy range ,
#include "ThingSpeak.h"
#include <SPI.h>
#include <Wire.h>
#include <WiFi101.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
//------------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
int max_index = 0;//
String FreqNames[] = {"63", "160","400", "1K","2.5K", "6.25K","16K"};
int FreqVal[7];//
int hz = 0;
float voltageValue,dB;
//to identify the testperson
int testperson = 1;
// Create instance of WiFi client
WiFiClient client;
char ssid[] = SECRET_SSID; // your network SSID (name) //Weyland-Yutani Corp.
char pass[] = SECRET_PASSWORD; // your network password (if needed)
//unsigned long myChannelNumber = SECRET_CH_ID;//channel ID
//const char * myWriteAPIKey = SECRET_WRITE_APIKEY;// write api key
// Add yourThingSpeak channel information here
unsigned long myChannelNumber = 630023;
const char * myWriteAPIKey = "8YTDWEWVV8V6JI08";
//---------------------------------------------------------------
void setup()
{
//Serial.begin(9600); // open serial over USB at 9600 baud
Serial.begin(57600); //Init the baudrate
Audio.Init();//Init module ?
// Initialise the I2C sensors and ping them
//sensor.begin();
// Initialise the ThingSpeak library
ThingSpeak.begin(client);
}
//---------------------------------------------------------------
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
printCurrentNet();
//Run the Sensors
runAudioSensor();
// Get the latest readings from the sensor
// hz = sensor.getfreq();
//dB = sensor.getdB();
//testperson = sensor.getid();
// Double-check if the field IDs are correct
ThingSpeak.setField(1, hz);
ThingSpeak.setField(2, dB);
ThingSpeak.setField(3, testperson);
// Upload sensor data to ThingSpeak
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
// Print sensor data to the Serial Monitor, so that we can
// double-check the correct values are being uploaded to ThingSpeak
printInfo();
// Disconnects from the WiFi
WiFi.disconnect();
// ThingSpeak will only accept updates every 15 seconds
delay(15000);
}
void runAudioSensor()
{
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
for(int i=1; i<7; i++) //
{
if (FreqVal[max_index] < FreqVal[i]) max_index = i;
}
int hz = FreqVal[max_index];
voltageValue = analogRead(SoundSensorPin) / 1024.0 * VREF;
dB = voltageValue * 50.0;
//float dB = (hz + 83.2073) / 11.003; //convert the bits to dB
}
//---------------------------------------------------------------
void printInfo()
{
Serial.print("Time: ");
Serial.print(millis());
Serial.print("ms; ");
//int hz = FreqVal[max_index];
Serial.print("Frequenzy: ");
Serial.print(FreqNames[max_index]);
Serial.println("hz");
//float dB = (hz + 83.2073) / 11.003; //convert the bits to dB
Serial.print("Volume: ");
Serial.print(dB,0);
Serial.println("dB");
Serial.println("");//?
Serial.println("testperson1");
}
//---------------------------------------------------------------
void printCurrentNet() {
// Print the WiFi signal strength:
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI): ");
Serial.print(rssi);
Serial.println(" dBm");
}
but when Im using the thingspeak code the freq is always constant
both of the code works
#include "ThingSpeak.h"
#include <SPI.h>
#include <Wire.h>
#include <WiFi101.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
//------------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
int max_index = 0;//
int FreqNames[] = {63,160,400,1000,2500,6500,16000};//peak of the freq range
int FreqVal[7];//
int hz = 0;
float voltageValue,dB;
//to identify the testperson
int testperson = 1;
// Create instance of WiFi client
WiFiClient client;
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASSWORD; // your network password (if needed)
// Add yourThingSpeak channel information here
unsigned long myChannelNumber = 630023;
const char * myWriteAPIKey = "8YTDWEWVV8V6JI08";
//---------------------------------------------------------------
void setup()
{
Serial.begin(57600); //Init the baudrate
Audio.Init();//Init module ?
// Initialise the I2C sensors and ping them
//sensor.begin();
// Initialise the ThingSpeak library
ThingSpeak.begin(client);
}
//---------------------------------------------------------------
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
printCurrentNet();
//Run the Sensors
runAudioSensor();
// Get the latest readings from the sensor
// hz = sensor.getfreq();
//dB = sensor.getdB();
//testperson = sensor.getid();
// Double-check if the field IDs are correct
ThingSpeak.setField(1, hz);
ThingSpeak.setField(2, dB);
ThingSpeak.setField(3, testperson);
// Upload sensor data to ThingSpeak
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
// Print sensor data to the Serial Monitor, so that we can
// double-check the correct values are being uploaded to ThingSpeak
printInfo();
// Disconnects from the WiFi
WiFi.disconnect();
// ThingSpeak will only accept updates every 15 seconds
delay(15000);
}
void runAudioSensor()
{
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
for(int i=1; i<7; i++) //
{
if (FreqVal[max_index] < FreqVal[i]) max_index = i;
}
int hz = FreqVal[max_index];
voltageValue = analogRead(SoundSensorPin) / 1024.0 * VREF;
dB = voltageValue * 50.0;
//float dB = (hz + 83.2073) / 11.003; //convert the bits to dB
}
//---------------------------------------------------------------
void printInfo()
{
Serial.print("Time: ");
Serial.print(millis());
Serial.print("ms; ");
//int hz = FreqVal[max_index];
Serial.print("Frequenzy: ");
Serial.print(FreqNames[max_index]);
Serial.println("hz");
//float dB = (hz + 83.2073) / 11.003; //convert the bits to dB
Serial.print("Volume: ");
Serial.print(dB,0);
Serial.println("dB");
Serial.println("");//?
Serial.println("testperson1");
}
//---------------------------------------------------------------
void printCurrentNet() {
// Print the WiFi signal strength:
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI): ");
Serial.print(rssi);
Serial.println(" dBm");
}