Arduino Mega Audio File logging

Picture of Arduino Mega Audio File logging

Record Audio to your Audino Mega SD card.

This Instructable will show you how audio input can be repeatedly added to a 512 byte buffer and then transferred to a SD card in real time. The period recorded can be altered.

The sample rate is 9.4 KHz and the wav file output 8 bit, mono. Whilst not hi-fidelity, the sound quality is perfectly adequate.

The recorded wav file can be saved as tabulated data. It can also be displayed as a simple scrolling graph on the monitor.

All files are time stamped using a unix time code sent from the serial monitor.

The inspiration for this article came from reading Amanda Ghassaei:


My latest program update at the end of this instructable, increases the sample rate to 19 KHz with a significant improvement in audio quality.


You may also be interested in my instructable on playing wav files from the Arduino:

Remove these adsRemove these ads by Signing Up

Step 1: Requirements

Picture of Requirements

Arduino Mega 2560

The following components work- alternatives may be viable (with program tweaking- I leave that to you!)

LCD Keypad Shield

MicroSD Breakout Board Regulated with Logic Conversion V2

4GB Micro SD Memory Card

Microphone pre-amplifier-

ac coupled with a potential divider to centre the voltage between Arduino 0-5 V rail

Amanda Ghassaei has published a circuit at

I designed my own with bass, treble and volume controls. However there are plenty of pre-amp designs on the web.

thanks for posting this! a lot of great info here. Do you think it's possible to increase the sampling rate above 9.4kHz? is there a limit to how fast you can interface with the sd card?

DavidPatterson (author)  amandaghassaei10 days ago

I did a re-write this evening, utilizing double buffering.

I now have the frequency easily up to 19Khz, with very good clarity.

Further testing at higher frequencies is needed, but results are very promising.

DavidPatterson (author)  amandaghassaei17 days ago

I investigated sampling with pre-scalars of 16 (72Khz), 32,(36Khz), 64(18.6Khz) and 128 (9.4Khz). I have left the necessary code in the startad subroutine for those who wish to try.

Without doubt, the limiting factor is the 512 byte block transfer to the sd card.

I believe that it is unlikely that further optimization is possible within the block write section of the code.

Obviously, if it takes longer than the sample period to write a sd block, then the audio is missed (or the frequency perverted) and the sound quality collapses.

At present, 9.4Khz is the limit for my SDcard writer.

No doubt card writer technology will speed up.

I have read claims for faster (beta) versions for sd libraries. However I wanted to use the standard sd library.

Faster sampling is possible if memory is used as the buffer, rather than the sd card.

My best optimization for that system allowed for a 6000 byte buffer on a Mega.

At 38 Khz, only a fraction of a second can be read. This is no good for recording audio, but has applications as an oscilloscope / fast logger.

bergerab14 days ago

This is simply incredible. I love how you go over wav files. I always thought about this but I never thought it could actually be done with an arduino. Thanks for sharing

DavidPatterson (author)  bergerab14 days ago

Thanks for that.

Let us know if you you get it up and running.


Get More Out of Instructables

Already have an Account?


PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!