2

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. I plan to next do FFT to find the frequencies associated with the sound sample

Having stripped down every other part of my code, I could still only get at the most 107 readings a second, as shown below

#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
}

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.

I've read also about preclocking, but the example codes were too complex for me to understand. A starting point in this direction would also be very much appreciated.

  • Serial prints at 9600 baud slow your loop down – Juraj Mar 27 at 6:05
  • i've tried it with 115200 and even 250000, it didnt get faster – zueses Mar 27 at 6:21
  • 500 samples per second for 5 seconds with 16 bit integer = 5000 byte. The arduino uno has 2000 byte sram. Do you have another arduino board? – Jot Mar 27 at 7:13
  • no...is it really complex to get maybe 400Hz? it doesn't need to be integers, i just need to read analog – zueses Mar 27 at 8:26
  • Use a hardware timer, for example arduino.stackexchange.com/questions/50045/… . Data sampling rates up to 100 kHz are possible! – MichaelT Mar 27 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.