0
\$\begingroup\$

I've connected my arduino's analog input to my phone's headphone jack and am trying to visualize the audio data in the serial monitor. I have read on Arduino's site that the Arduino UNO is able to yield a resolution between readings of: 5 volts / 1024 units or, 0.0049 volts (4.9 mV) per unit so I thought it would be able to pick up audio data from the jack. However, after looking at the data which appears totally random, I am not so sure. Do you think at these low level voltages it is possible to get an accurate reading of audio data? For the project I am working on it's important to collect accurate audio data so I can use it to find a repeated segment of the audio clip. Here is my simple code for printing voltages in Arduino ide.

int analogPin = A0;
int val = 0;

void setup() {
  Serial.begin(9600);  
}

void loop() {
  val = analogRead(analogPin);
  Serial.println(val);
} 
\$\endgroup\$
  • \$\begingroup\$ Possible duplicate of How to read an audio signal using ATMega328? \$\endgroup\$ – Diego C Nascimento Apr 11 at 1:16
  • 1
    \$\begingroup\$ Your project is not really workable - 9600 baud serial transporting 12 bit values in printable form cannot usefully convey audio, and sporadically software time conversion will have too much jitter to be useful. Really, ATmega based Arduinos and audio do not go together, except in very narrow cases very carefully engineered. For audio analysis you really want something with faster I/O and lots of buffer memory - start your project on a PC, and then consider finding a suitable embedded platform only once you have a sound algorithm. \$\endgroup\$ – Chris Stratton Apr 11 at 1:41
  • \$\begingroup\$ Thanks, couldnt i just increase the baud rate then? \$\endgroup\$ – st4rgut Apr 11 at 2:01
  • 1
    \$\begingroup\$ Take a look at the math. First off, when you print "val" you will get anywhere from 1 to 4 bytes. The transfer time will vary because of that. For 1 byte, you can send a value 1200 times a second. At 4bytes, that drops to 300 times a second. Your sampling rate depends on the sampled valued, and is effectively random. If you speed things up to 115200, then you still have that variation of a factor of four in your sampling rate. And, the Arduino standard libraries run out of steam when you start sampling at close to 10000 times per second - above that, you can't go any faster. \$\endgroup\$ – JRE Apr 11 at 8:30
  • 1
    \$\begingroup\$ And, it's worse than that. You are using println, which adds a line feed character at the end. That's another byte, and that much more time to send the value. \$\endgroup\$ – JRE Apr 11 at 8:32

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.