Record audio from a microphone to an SD card?

Hello there!
My idea goes like this: I want to try to record the sound from a microphone (like my voice), to an SD card. I guess I can't expect record it at a sampling rate higher than 8 KHz (due to the timing of the functions). The audio will be stored in a "raw file" (because I don't know how to create the WAVE/RIFF header automatically); and maybe playback that recording with the same board (but that's the "stage two" of my plan). Now here are my questions:

  • Shall I need amplification for the microphone's signal, or changing the reference voltage will also help?
  • Can an analog input pin handle negative parts of a waveform? I think even a schottky diode will completely kill the input signal.
  • Since the recorded samples must be unsigned 8 bit, which of the following is faster? Map the value or shift two bits?
  • Would you mind suggest me a way to automatically stop recording? I guess suddenly stop writing to a file without closing it is a bad idea.

Thanks beforehand and sorry if I made misspellings.

  1. you need an amplifier
  2. no you need to bias the input waveform to 2.5V
  3. shift
  4. push switch, or when the input envelope drops to zero for a certain time

Grumpy_Mike:

  1. you need an amplifier

Even for a desktop computer microphone?

  1. no you need to bias the input waveform to 2.5V

Is that like mixing 2.5V with my audio signal?
If so, can I just put both in the same pin, or do I need some additional components? (Apart from a voltage divider)

Even for a desktop computer microphone?

Yes.

Is that like mixing 2.5V with my audio signal?

If you like to think of it like that. The proper way of describing is adding a DC offset.

If so, can I just put both in the same pin,

Yes you have to.
Use 10K pull up and pull down on the analogue input and couple the audio in with a none polerised capacitor as big as you have got.

Grumpy_Mike:
Use 10K pull up and pull down on the analogue input

I think this is the voltage divider part, right?

and couple the audio in with a none polerised capacitor as big as you have got.

  • How that capacitor goes here? Between the signal and the input pin (in series), or between the signal and ground (in parallel)?
  • Non-polarized capacitor of which type? Because I think a big one is electrolytic

Even for a desktop computer microphone?

Almost all "computer microphones" are electret condenser types and they require 5V power (normally supplied by the soundcard).

[u]Here is an example[/u] of an electret microphone preamp circuit with power for the mic and biased output.

Is that like mixing 2.5V with my audio signal?

Yes. The Arduino can't read negative voltages, so and AC audio signal must be biased. (You can subtract-out the bias in software if you wish.) [u]Hre is an example[/u] of a bias circuit.

How that capacitor goes here? Between the signal and the input pin

yes.

Non-polarized capacitor of which type?

doesn't matter.

All right, thank you very much!
Is not that hard to do this, but now I'm worried about two things:

analogRead function is so slow by default (and still not yet tested its "fast mode")
I don't know how long takes writting a byte to a file in a SD card. Will the technique discussed in this thread work too?

I don't know how long takes writting a byte to a file in a SD card.

No and you will not find out because it is not fixed. It depends on the type of SD card, where abouts on the card it is and its age. Plus a lot more factors.

Will the technique discussed in this thread work too?

No idea, the url is wrong.

Grumpy_Mike:
No idea, the url is wrong.

Jeesh what I made wrong this time? How can I get the actual URL of a thread?

Copy and past normally works for me. Just put the link into url tags and don't use the link icon.

Grumpy_Mike:
Copy and past normally works for me. Just put the link into url tags and don't use the link icon.

https://forum.arduino.cc/index.php?topic=377029.60

This is the actual URL of the thread then. Hope it works properly this time...

Yes it will work.
Another technique is to put a pin high, do the code and put it low, using port manipulation. Then measure the width of the pulse on an oscilloscope.

Grumpy_Mike:
Another technique is to put a pin high, do the code and put it low, using port manipulation.

Will the "port manipulation" execute almost instantly? (unlike the digitalWrite function)

Then measure the width of the pulse on an oscilloscope.

Awwwwww. Will a cheapy one work too? I mean, this one:
http://www.amazon.com/SainSmart-DSO138-1Msps-Digital-Oscilloscope/dp/B00XXZB5LW

Will the "port manipulation" execute almost instantly?

Yes.

Will a cheapy one work too?

No that one is way too slow. It will only work at 1M samples per second. You have a 16MHz processor so to actually measure anything approaching accurately you need it 100 times better than this.

FN-RM01 is a high quality MP3 audio recorder that can record voice messages to a micro SD card. Maybe you can take a few to try. It's available here on Aliexpress.
http://www.aliexpress.com/item/Digital-Audio-Recorder-with-Playback-Function-2-PCS-A-lot-MP3-Sound-Recorder-Module-micro-SD/32603016265.html?spm=2114.01010208.3.1.7UHOP1&ws_ab_test=searchweb201556_6,searchweb201602_3_505_506_503_504_10020_502_10014_10001_10002_10017_10005_10006_10003_10021_10004_10022_10018_10019,searchweb201603_1&btsid=9ee0e5dc-21b1-41d5-9541-67a047a64b5f

Grumpy_Mike:
No that one is way too slow. It will only work at 1M samples per second. You have a 16MHz processor so to actually measure anything approaching accurately you need it 100 times better than this.

Oh well, I don't wanna spend a lot of money on this, so the micros timer is my only way I think.

By the way, the MP3 module can be useful for this purpose, but I just wanna use the Arduino itself if possible. But, because the MCU hasn't enough memory for record sounds, then the cheapest way to get more space, is by interacting with a SD card (in any form factor). However, thanks anyways...

Take a read thru here
http://forum.arduino.cc/index.php?topic=180769.0
I designed this card for the project, got hung up on integrating the ADC & DAC into it, but left myself some room to play some more when I had some time. You can see that fat16lib had the code working to record mono audio to SD card at CD quality speed/data (16 bit data, 44.1 KHz)
http://www.crossroadsfencing.com/BobuinoRev17/

(and I got carried away and added screw terminals too vs making them a shield to sit on top)

CrossRoads:
Take a read thru here
16-bit sample & store, then readback & play, finally store to SD - Programming Questions - Arduino Forum

I've read it. Is that the code for that board of yours?

I designed this card for the project, got hung up on integrating the ADC & DAC into it, but left myself some room to play some more when I had some time. You can see that fat16lib had the code working to record mono audio to SD card at CD quality speed/data (16 bit data, 44.1 KHz)
Cross Roads Electronics

Is that like "all-I-need-in-one" board? Yeah, it looks promising, but... I'm trying to keep up with the simple stuff.
By the way, how you can achieve a higher sampling rate? Because of the SRAM or the ADC?

And again, thank you for your replys!