Microphone Code

Hey everyone! I'm thinking about attempting to take on a project that involves a microphone and headphones. First of all, I'm looking at this microphone... Basically, I need to know that if it would be possible with code to read the frequency that the microphone detects. Also, what's the best way to connect headphones to an Arduino? On adafruit I've found a few different parts, I'm just not sure which ones I'd need...

Breadboard-Friendly 3.5mm Stereo Headphone Jack : ID 1699 : $0.95 : Adafruit Industries, Unique & fun DIY electronics and kits (I'm assuming I'll need this for sure)

Stereo 3.7W Class D Audio Amplifier - MAX98306 : ID 987 : $8.95 : Adafruit Industries, Unique & fun DIY electronics and kits (Will I need this to drive the headphones?)

Also, in code, how do I produce a frequency that can be played on a speaker...

Sorry that I'm asking so many questions, I just don't know much about sound when it comes to arduino code....

Thanks!

Basically, I need to know that if it would be possible with code to read the frequency that the microphone detects.

The incorrect assumption in this statement is that the microphone will read one frequency. It will NOT.

No microphone will. That is not what a microphone does.

PaulS:
The incorrect assumption in this statement is that the microphone will read one frequency. It will NOT.

No microphone will. That is not what a microphone does.

Ok so I'm assuming that the microphone emits pulses of electricity. Is there any way to find out the frequency of a sound or no? I'd basically be trying to do the same thing that this app does... Tell me how many hz a sound is... Is that possible or no? Thanks!

Is that possible or no?

You are assuming that sound is a single frequency. That is rarely, outside of a studio, the case.

It is possible to determine the frequencies involved. But, not with an Arduino.

Also, in code, how do I produce a frequency that can be played on a speaker

Use the tone() function.

PaulS:
You are assuming that sound is a single frequency. That is rarely, outside of a studio, the case.

It is possible to determine the frequencies involved. But, not with an Arduino.

Of course I know this, but there's really no way to read a tone?

jremington:
Use the tone() function.

Is that to play a tone on a speaker or to read a tone from a microphone?

but there's really no way to read a tone?

How are you going to get the data INTO the Arduino? You keep saying microphone. Wrong answer.

PaulS:
How are you going to get the data INTO the Arduino? You keep saying microphone. Wrong answer.

Not sure what you mean... In my initial post I put a link to a microphone, I'm just wondering if I could find out what the frequency of a sound is with this microphone, essentially do what a tuner does, I play a note on the piano, or guitar or something, and it tells me how many hz that sound is. Maybe this microphone can't do this? Maybe it can only tell me how loud a sound is? Here's the link to the microphone:

http://www.miniinthebox.com/high-quality-arduino-microphone-sound-detection-sensor-module_p903301.html?currency=USD&litb_from=paid_adwords_shopping&litb_from=&adword_mt=&adword_ct=73208704722&adword_kw=&adword_pos=1o2&adword_pl=&adword_net=g&adword_tar=&adw_src_id=4196617767_313071522_22450980162_kwd-112159393035&gclid=CjwKEAjwueytBRCmpOyZ2L-xrG8SJADwH5c6_hpnnlvfJ8vpHIpNvcn5u7FMDcInvV4IIKblJTwiIRoC_Wvw_wcB

Ok so I've actually done some searching online and I think I've figured out how to read the frequencies, but I'm still wondering how to generate a tone and play it through headphones...

Use blink without delay to make a tone. Basically this:

// put this in loop
if (toneEnabled == 1){
currentMicros = micros();
elapsedMicros = currentMicros - previousMicros;
if (elapsedMicros >=halfPeriod){
previousMicros = previousMicros = halfPeriod;
// change output from  high to low, or low to high
// example: D2 = PORT D bit 2
PIND = PIND | 0b00000100;
}
}

CrossRoads:
Use blink without delay to make a tone. Basically this:

// put this in loop

if (toneEnabled == 1){
currentMicros = micros();
elapsedMicros = currentMicros - previousMicros;
if (elapsedMicros >=halfPeriod){
previousMicros = previousMicros = halfPeriod;
// change output from  high to low, or low to high
// example: D2 = PORT D bit 2
PIND = PIND | 0b00000100;
}
}

Ok cool! This is more of a wiring question (sorry!) but do I just hook headphones up to the Arduino as I would a speaker? Will they need any amplification or no? And will this work to hook them up to the board?

Speakers are low impedance - generally 8 ohm, sometimes 4 ohm. Impedance is similar to resistance.
Arduino output can't drive that low of an impedance directly, an output needs to see 125 to 150 ohm.
Similarly, a headphone is low impedance, perhaps 32 ohm.
Both would need a series resistance to avoid burning up the Arduino output.
Connecting to some form of amplifier would provide a louder output.

The connector gives you something to plug headphone into, but does not solve the low impedance problem.

CrossRoads:
Speakers are low impedance - generally 8 ohm, sometimes 4 ohm. Impedance is similar to resistance.
Arduino output can't drive that low of an impedance directly, an output needs to see 125 to 150 ohm.
Similarly, a headphone is low impedance, perhaps 32 ohm.
Both would need a series resistance to avoid burning up the Arduino output.
Connecting to some form of amplifier would provide a louder output.

The connector gives you something to plug headphone into, but does not solve the low impedance problem.

Would something like this work?

I believe that they're using a 10k ohm resistor... I'm assuming the black wire is ground? Maybe they just didn't color code their jumper wires...

10K is high. Would be okay for feeding into a powered amplifier.
Won't hear anything if a low impedance speaker/headphone is connected.

CrossRoads:
10K is high. Would be okay for feeding into a powered amplifier.
Won't hear anything if a low impedance speaker/headphone is connected.

But that wiring would be correct as far as adding resistance? What would you reccomend for a resistor? 1K? 5K?