Make a simple Arduino audio player that plays .wav files from an SD card in as little as 10 minutes.
This is a simple and fun Arduino project you can build in 10–15 minutes — an Arduino audio player that plays ".wav" files. It consists of a speaker, a simple transistor acting as an amplifier, and a micro-SD card adapter for a micro-SD card that holds the .wav files.
Software needed:
How Does the Audio Player Work?
The Arduino in the circuit shown below loads the .wav files from the micro-SD card. It then generates a signal and outputs it through the speaker connected to digital pin 9. This allows the speaker to create sounds and play music. In this tutorial, I have programmed the Arduino audio player to play "Rain Over Me” by Pitbull and Marc Anthony.
The .wav files used in this circuit have a slight limitation in playing audio. Since a transistor is used as an amplifier, it cannot read complex .wav files. Therefore, the .wav files should be converted to have these dimensions:
Samples Per second (Hz): 16000
Channel: Mono
Bits Per Sample: 8
Converting files to .wav File Format for Your Arduino Audio Player
You don’t need to install any software in order to convert the songs to .wav files. There's an
online music converter to do the work for you.
Follow the steps given below to make songs compatible with your Arduino audio player:
- Upload a music file or enter a link for the song or audio file to be converted. You can even choose files from Dropbox or Google Drive.
- In optional settings, change bit resolution to 8 bit.
- Change sampling rate to 16000 Hz.
- Change audio channels to Mono.
- Click on "Show advanced options".
- Set the PCM format as PCM unsigned 8-bit.
- Click on "Convert", and the files are converted!
Formatting Your Micro-SD Card
- Download the SD Formatter tool.
- Run the tool as administrator.
- Select the proper drive to format. Name your card by filling in the Volume label field and click the "Format" button. It will prompt you with a couple of dialogues. Click on them, and your card will be formatted!
- Add the previously converted .wav files to the card and save them with simple names such as 81.wav.
Preparing Your Circuit
MOSI — pin 11 on Arduino Uno/Duemilanove/Diecimila
MISO — pin 12 on Arduino Uno/Duemilanove/Diecimila
CLK — pin 13 on Arduino Uno/Duemilanove/Diecimila
CS — Depends on your SD card shield or module.
Pin 4 is used here for consistency with this Arduino code.
Connecting the Arduino and Uploading the Code
The code is as follows:
#include "SD.h"
#define SD_ChipSelectPin 4
#include "TMRpcm.h"
#include "SPI.h"
TMRpcm tmrpcm;
void setup(){
tmrpcm.speakerPin = 9;
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD fail");
return;
}
tmrpcm.setVolume(6);
tmrpcm.play("rain.wav");
}
void loop(){ }
Plug in the power, and your Arduino audio player will successfully play a song.
You can see the working demo in the video below.