Arduino Piezo Speaker | Help sincerely needed

So I posted something before which had too many questions regarding different matters that were non-topic. So I'm kind of rephrasing it in this post.
Is it possible to turn the arduino into a speaker? Virtually I mean, I want my computer to see the arduino as a speaker and try to use it. I don't really want the arduino to make sounds, I just want the arduino to pick up the music so I can use it for my project. The project is a whole other question.

Is it possible to turn the arduino into a speaker? Virtually I mean, I want my computer to see the arduino as a speaker and try to use it.

Analog, right?

The computer shouldn't have to "see" the Arduino at all,* you just want the Arduino to "tap into" the audio signal, right?

You can't put negative voltages into the Arduino, so you need to bias the AC audio signal at 2.5V, or block-out the negative half of the waveform.

The two 100K resistors and 10uF capacitor show on [u]this schematic[/u] will bias the signal. (You should be able to leave-out the 47nF capacitor.)

  • Some soundcards do need to see a load. But, assuming you have speakers or headphones connected with a Y-Adapter (splitter) to also send the signal to the Arduino, that shouldn't be an issue.

Why do you not just use an audio amp?

What is the reason you want to use an Arduino as an audio amp? It is not a speaker. The speaker is the speaker.

I just want the arduino to pick up the music so I can use it for my project

What do you mean by "pick up the music"?

What do you mean by "pick up the music"?

I think I understand what he is asking. He does need to work on clearer communication. I am working on something similar to this now so the post grabbed my attention.

I think what he was asking is can the arduino pick up sound and record the signals picked up. In the example of http://arduino.cc/en/Tutorial/Tone the arduino sends a signal to a piezo which plays a melody. I think he wants to reverse engineer this so the melody played is picked up by the arduino and the arduino records the sound sequence from the melody played.

I have below an attempt to do this using a piezo. It doesn't work though. Can a piezo be used to detect sound? Can someone please help me understand why the code I wrote isn't doing this?

int SoundSensor = A4;              
byte val = 0;


void setup() {
 pinMode(A4, INPUT);
 Serial.begin(9600);
}

void loop() {
  val = analogRead(SoundSensor);   
 Serial.println(SoundSensor); 
}

The output of a piezo used as a microphone is in the range of millivolts, at most. Like any microphone, you must amplify it.

A piezo element (one not designed and packaged to be a microphone) has poor frequency response and is not very sensitive. You can buy inexpensive modules with both an electret microphone and a preamplifier. You can't just feed an AC sound signal into an Arduino, as it won't read voltages below 0V. So typically the analog input pin is biased to be at 2.5V (assuming 5V for Vcc) and the signal is fed on that.

The capture speed of that program is going to be pretty slow. 9600 baud means 9600 bits per second. Using 8n1, that is about 1kByte per second. So it reads the analog voltage, then spends about 1ms sending, then reads it again, so your sample rate is about 1ksps.

Without a serial write in there and nothing else going on, the default max speed is about 10ksps.

Here is a thread about speeding up analogRead so that you can accomplish reasonable speeds while still accomplishing other tasks:

http://forum.arduino.cc/index.php?topic=6549.msg51570#msg51570

But you'll want to either not use serial to display the result, or set serial much faster.

BTW, the audio needs to have a lowpass filter so that frequencies about about 1/3 the capture rate are blocked. Forget Nyquist and the supposed limit of 1/2 of the capture speed - what you've heard is probably a fatally oversimplified rule-of-thumb. The real rule-of-thumb is more like 1/3, or at most 2/5 of the capture frequency.