Arduino Audio Player: Best tutorial for playing audio files!

From our STAR Maker : Sarvagnya Purohit

Arduino Audio

This Arduino project is a simple and fun project you can build in 10-15 minutes. The result of this make will be 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 with a micro-SD card in it where the .wav files are loaded and played.

Required Materials


  1. Arduino Uno (Any other Arduino except Duo will work)
  2. Micro-SD card adapter
  3. 8-ohm speaker
  4. Micro-SD Card
  5. Mini Breadboard
  6. BC 546b NPN transistor
  7. 7k Resistor
  8. Male-to-male jumpers


How does it 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 makes the speaker create sounds and play music. It can play many different songs saved on the micro-SD card. 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

Step 1: Convert 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. The link is:

Follow the steps given below to make songs compatible with your Arduino audio player:

  1. 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.
  2. In optional settings, change bit resolution to 8 bit.
  3. Change sampling rate to 16000 Hz.
  4. Change audio channels to Mono.
  5. Click on “Show advanced options”.
  6. Set the PCM format as PCM unsigned 8-bit.
  7. Click on “Convert” and the files are converted!

Arduino Audio

Step 2: Format Your Micro-SD Card

  1. Download the SD Formatter tool from:
  2. Run the tool as administrator.
  3. Select the proper drive to format. Give the card your favorite name by writing it on Volume label and click the “Format” button. It will prompt you with a couple of dialogues. Click on them and your card will be formatted perfectly!
  4. Add the previously converted .wav files to the card and save them with simple names such as ’81.wav’.

Arduino Audio

Step 3: Prepare Your Circuit

Arduino Audio

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

Step 4: Connect the Arduino and Upload the Code

Arduino Audio

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;
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD fail");


void loop(){  }

Plug in the power and you have your Arduino Audio Player successfully play Rain Over Me. Feel the happiness with the energetic starting lines, “Girl my party don’t lie”!!!!!

You can see the working demo in the video below:

Thank You.

Sarvagnya Purohit-min

Sarvagnya Purohit – STAR Maker at DIY Hacking

About the maker:

Sarvagnya Purohit is a 13 year old passionate maker from Thane, Mumbai with experience in Arduino and Raspberry Pi. He is a tech enthusiast and has interests in robotics, IoT, 3d printing, coding, and solving Rubik’s cubes.

Recommended Posts
Showing 39 comments
  • Robert

    Hi Sarvagnya,
    I was wondering if you could help me. I am building an r2d2 themed electric skateboard. I have a battery pack that would provide power to the motor, and it has a usb port. I would like to use that usb port to connect a music system (ideally a soundboard with an sd card and a small speaker /with bluetooth connectivity) so that when I turn on the skateboard it makes a welcoming r2d2 sound. I have no experience in coding or doing any of these things, hence why i’m here asking for your help :) I was thinking whether to purchase this small bluetooth speaker with sd card capability , remove the plastic , revealing the raw electrics and connecting this to the skateboard battery. I understand that I would somehow need to program the speaker so that when it turns on it plays the r2d2 sounds from the sd card and once it finishes playing it turns off the speaker. Could you tell me whether its possible to do this with the speaker i sent in the link, or do you advise buying everything seperately and building it. If you advise building it could you recommend the stuff that I would need to build it?

    Many Thanks


    • Sarvagnya Purohit

      Hey Robert,
      Your project is quite interesting. I think it wouldn’t be the perfect place here for us to talk about it. You can email me([email protected]) or contact me on facebook.

  • Ilan

    Hi Sarvagnya,

    Is the music quality mainly dependent on the speaker, or is there no way of getting a better sound quality with an Arduino as audio
    player? thanks

    • Sarvagnya Purohit

      Actually we used a transistor as an amplifier. You can use MP3 shields for better quality. for example those adafruit mp3 shields.

  • corado

    how can i use two speakers to play different types of audio files??

  • Chaitanya

    Good Evening Sarvagnya,
    I was referring your material for my project work, i am able to dump the code on controller the code is running successfully but i am unable to get audio output.

    • Sarvagnya Purohit

      Did you convert those .wav files according to the instructions? If yes, then try connecting that white wire in the circuit diagram to pin 9 rather than pin 8.

  • Jake Lachi

    Hello. I’m doing a final project and we are using an SD card to play drum sounds. We are also using push buttons to play only one type of sound. I need some help with the code so that each push button plays a different drum sound from the SD card

  • Akhilan

    can we play different types of audio files in different situations in program?
    example: when obstacle is detected at right side of IR sensor 1.wav as output..?
    when obstacle is at leftside 2.wav as output…?

    • Frit

      It does not generate any music at all from sd card.NOTHING HAPPEN!!!

    • Ahmed

      i have the same the question

  • debra

    does it works with piezzo?

  • Marco

    Nice post. Thanks a lot!

    • Sarvagnya Purohit


  • W

    Hi, I’m currently doing my final year project and my project’s objectives is to control the volume of the music by using ultrasonic sensor & paused the music when the distance of ultrasonic sensor is 0cm to 5cm. May I know how to code it? I used the same coding as yours to play my music but when I add my volume control statement into the code in the loop, the music won’t play anymore.

    • Sarvagnya Purohit

      can you pm me?? i can give u the code

  • sai

    hi,how to give my wave file in the place of rain.wave.

  • arbit

    Thanks for this simple solution to play audio.
    One question: I am trying to play audio in a sketch with blinking leds.
    Can you recommend a sketch where the “Play rain.wav” command is part of the Loop, rather than the setup?
    I want to play different files as part of my loop.
    For example, if red light blinks, I want to play file 1, if green light blinks, I want to play file 2, etc.
    To do that, I need the play command in the loop, not the set up.
    Thanks again, and keep Making.

  • adibah

    hi, i’m using arduino uno …i’m using ur code there but i have some problem with it…when i’m compiling the code…it turned like this..

    compilation terminated.for #include “TMRpcm.h”

    • Sarvagnya Purohit

      You have to download that library

      • Jonii

        how to download this library i tried many time but i couldn’t.kiindly help me i really need that

  • aa

    bullshit, that’s not working

    • Sarvagnya Purohit

      Try again. Believe me, it works …

  • Tejasurya Mouli

    I’m getting static buzzing sound when i connect the speaker, what can be the problem here? pls help

    • Sarvagnya Purohit

      Sorry btw for the late reply as I was busy in my 9th standard exams. You may have a problem in your files. Try step 1 properly again. The same happened with me first. Then I tried again. It will work :)

      • J

        Hi, may I know why my SD keep failing? I have my connection all correct.

    • Sarvagnya Purohit

      the white wire connected to pin 8 should be connected to pin 9 shown in the diagram ;) it was my mistake.

  • Derek States

    I’m new to Arduino, but you say that the circuit will output audio through a speaker connected to digital pin 9, but, in the diagram, you don’t have anything connected to digital pin 9. Is there another step that I am unaware of?

    • Sarvagnya Purohit

      Sorry btw for the late reply as I was busy in my 9th standard exams. the white wire connected to pin 8 should be connected to pin 9 shown in the diagram ;) it was my mistake. Thanx for pointing it out.

  • Kyle

    I’m still a bit new to Arduino. Would an Arduino Nano be able to do this as well? And do you know of any way to play multiple audio files? Like, have a short audio file that plays at the press of one button and a different file that plays when you press another.

  • saad

    hi .. can u please upload a clear crcuit diagram as i am new to arduino and cannnot understand the wiring . thank you

  • Chris

    BC 546b NPN transistor? What is that? I cannot find it on Is there some other name for this part? Thanks.

    • Sarvagnya Purohit

      Sorry btw for the late reply as I was busy in my 9th standard exams. You can buy these specific value transistors in a local electronic, electrical, hardware, hobby, etc. shop but not on Amazon. You can find them on internet or Sparkfun as Amplifier Transistors. You can buy it at Mouser on the following link :
      Thank you for watching.

  • srp

    Is there any way to play mp4 format in audrino

    • Sarvagnya Purohit

      You mean “mp4”? Means even videos? You can rather do that by using a TVOUT library of Arduino through which you can get the video output and the above tutorial is enough for the audio part! Sorry btw for the late reply as I was busy in my 9th standard exams.

  • Ken L
    • Sarvagnya Purohit

      Thanx for that site.

Leave a Comment

7 + 2 =

Start typing and press Enter to search