The Arduino talking! How is it? Connect speaker and play audio files

I this tutorial we will learn how to play audio files with the Arduino. For this we will use speaker. Also we will use SD card module for keep the audio files.
After this tutorial you can make mini mp3 player using the Arduino.


Required Hardware

Arduino Board -
SD Card Module -
Mini Speaker -
2GB MicroSD -
SD Card Reader -
Jump Wires -

Mid-year Promotion --
Arduino & DIY Kits --
Flash deals Electronics --
Arduino Basic Starter Kit --
Recommended Site --


About the SD Card Module Adapter

The module (MicroSD Card Adapter) is a Micro SD card reader module, and the SPI interface via the file system driver, microcontroller system to complete the MicroSD card read and write files.

Support Micro SD Card (<=2G), Micro SDHC card (<=32G)
The level conversion circuit board that can interface level is 5V or 3.3V
Power supply is 4.5V ~ 5.5V, 3.3V voltage regulator circuit board
Communication interface is a standard SPI interface



SD Card Module VCC connect to +5V of the Arduino Board
Module GND connect to GND of the Arduino Board
Module CS connect to digital 4 pin of the Arduino
Module SCK connect to digital 13 pin of the Arduino
Module MOSI connect to digital 11 pin of the Arduino
Module MISO connect to digital 12 pin of the Arduino

Connection of the Speaker

We will connect two wires to the speaker jack
I use hot silicone (for remove it again). You can use solder if you like.
One wire from the speaker jack will connect to GND of the Arduino.
The other wire will connect to digital input 9 of the Arduino.
(The library use digital pin 9)


Create and Convert of audio file

We will transfer the audio files to the Arduino via SD card
Connect your SD card to your computer with a card reader
The type of audio file we need to use is WAV
I recorded the audio with the phone application and I used it by converting it
You can use any song or sound if you want
I used an online website to convert the audio file. You can use a different website if you want.

Upload your audio you want to convert to WAV
Then we change the settings as below
bit resolution: 8 bit
sampling rate: 16000 Hz
audio channels: mono
Then we press Convert File button
Our WAV audio file is ready
Copy the file into the SD card
Insert the SD card into the SD card module


Get the Library -


Voice Recognition Module

In the coming days I will make a project with Voice Recognition Module. 
We will send any voice command and in reaction to this command the Arduino will answer to us.
If you yet do not have a Voice Module, you can buy this module from the link in the below.

Voice Module -
USB to TTL Module -


Get the Source Code
#include <SD.h>                           //include SD module library
#include <TMRpcm.h>                       //include speaker control library

#define SD_ChipSelectPin 4                //define CS pin

TMRpcm tmrpcm;                            //crete an object for speaker library

void setup(){
  tmrpcm.speakerPin = 9;                  //define speaker pin. 
                                          //you must use pin 9 of the Arduino Uno and Nano
                                          //the library is using this pin
  if (!SD.begin(SD_ChipSelectPin)) {      //see if the card is present and can be initialized
    return;                               //don't do anything more if not
  tmrpcm.setVolume(6);                    //0 to 7. Set volume level"1.wav");         //the sound file "1" will play each time the arduino powers up, or is reset

void loop(){}