7
\$\begingroup\$

What is the best way to make an Arduino play a sound file? Is there a code library or shield I would need? How would I store this sound file on the Arduino's chip? Is isn't very big, so I would be concerned doing this.

\$\endgroup\$
  • 3
    \$\begingroup\$ Are you referring to simple tones, or something more complex like an mp3 or wav file? \$\endgroup\$ – apnorton Apr 13 '13 at 16:20
11
\$\begingroup\$

It depends on what your definition of "sound" is. If you just want it to beep, than that's easy. If you want it to start playing your favorite song, that's a bit more challenging.


If you want to use a Piezo speaker to make simple sounds:

For just tones you can look at here on Arduino's website. You wouldn't need to store the sound file, you would just have the Arduino generate the sounds at runtime. Arduino Piezo speaker

From Arduino's website. It seems fairly easy to implement if needed for this use.


If you need it to play a song or sound file:

I highly don't recommend playing sound files on Arduino. A couple of things:

  1. The sound quailty is going to be TERRIBLE.
  2. You are going to have to have to figure out a way to split the sound file into frames, and find one common frequency. If you want more than one frequency, I believe you'll need more than one Pizeo speaker.
  3. Once you have all the frames, you are going to have to write in the code to change it every __ seconds to another tone. If you had 5 FPS than you would have to change it every 200 milliseconds.

Another alternative would be to have multiple Piezo speakers, figure out how to have a computer "dissect" the sound files, and send it over a high baud rate serial communication. I don't think that would work.


The easiest thing would to buy a $10 MP3 player and rig it with $3 servos from eBay to push the buttons and have some cheap speakers.

EDIT: You could also do a similar thing to this, it is a coffee maker, but the information is good. It shows you how to modify the buttons to "push" them with Arduino.


EDIT: Found some shields:

There are tons more that are more expensive, but these are pretty good for their price. The tutorial for Audafruit has it playing some sound so you can hear the quality.


It is easy, but costly and/or you have to get creative if you don't want to buy a shield. Good luck!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy