I need to read an analog signal at about 500-1000Hz for at least 5 seconds.
I've a battery powered microphone wired into an analog and ground pin on my arduino and am trying to measure the frequency (and amplitude) of sound coming from a rijke tube
To accurately represent the sound waves I need to take samples with a frequency at least twice that of the sound I'm studying, hence the frequency above. Having stripped down every other part of my code, I could still only get at the most 107 readings a second, as shown below
// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3
#include "EmonLib.h" // Include Emon Library
#define VOLT_CAL 269
#define CURRENT_CAL 60
unsigned long time;
EnergyMonitor emon1; // Create an instance
void setup()
{
Serial.begin(9600);
Serial.println("CLEARDATE");
Serial.println("LABEL, DATE, TIME,Wall Voltage,Wall Current, Mic Voltage, Time Elapsed");
}
void loop()
{
int sensorValue = analogRead(A4);
time = millis();
Serial.print(sensorValue);
Serial.print(",");
Serial.println(time); //prints time since program started
delay (1);
}
can anyone tell me what I'm doing wrong/how I can increase the sample rate?
I've also tried to use a for loop to take my readings first, only printing them at the end but also maxed out at only 100 readings a second with the next attempt of code
#define NUMSAMPS 100
int data[NUMSAMPS];
int times[NUMSAMPS];
void setup()
{
Serial.begin(9600);
Serial.println("Mic Voltage, Time Elapsed");
}
void loop()
{
for(int i=0;i<NUMSAMPS;i++)
{
data[i]=analogRead(A4);
times[i]=millis();
}
for(int i=0;i<NUMSAMPS;i++)
{
Serial.println(data[i]);
}
for(int i=0;i<NUMSAMPS;i++)
{
Serial.println(times[i]);
}
}
Any direction would be appreciated very much