Reading more value from the same analog pin

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");
    }

Not necessarily related to your question… but you are trying to run all three of these functions at the exact same time, each second. Best to stagger them in non-consecutive times (E.g 1000, 1035, 1077, etc.)

This is also a big NO NO when using an IoT process like Blynk… causes disconnections

Actually… I just noticed… the whole WiFi.begin() and delay() combo shouldn’t be in the void loop() at all… why is it there?

I havent mentioned but I want measure the heartbeat through smartwatch, and since im doing this with different test persons
i need to differentiate with the data

i want id each freq magnitude with db

so when i get the csv file they stamped to the person
btw thanks for heads up
its mash code from thingspeak, I take out han

I just want to see if its connected to the wifi or not on the serial port

Well… in a general answer to your question… yes, you could probably read multiple readings from one analog pin… IF your sensors always sent at different times and IF you could definitively know at which time a particular sensor was sending its data.

Probably better to use a multiplexer analog input board.

But, this is NOT a Blynk specific issue, rather a hardware, coding and/or sensor timing and feedback one. We teach about Blynk here, not random coding or troubleshooting, so not sure what more we can do to solve that particular issue.

thanks I was just looking to confirm to this idea can work, in terms of code

Well, as long as the needed timing is not quicker then the code can process it… again… most anything is possible. Now, how easy… well that is a whole 'nother issue :stuck_out_tongue: