Play Music With Arduino!

9,173

44

12

About: Photonics Engineer

In this instructable I will show you how I play music using an Arduino UNO and a SD Card module.

We will use the SPI Communication.

Let's get started!

Step 1: Parts

We will need the following parts:

Arduino UNO

SD Card Reader

Jumper Wires

Audio Amplifier

Speaker

Step 2: Code

The code its very simple, you can use it to play pretty much any sound that is on the SD Card but with an specific format, thats on the next step.

You need to download all the libraries frist, if you already have it then just copy and paste:

#include "SD.h" //SD library
#define SD_ChipSelectPin 4 //Select the SS pin for the SD module

#include "SPI.h"

#include "TMRpcm.h" //The library to play the audio files

TMRpcm Memoria; //Here you put the name you want

void setup(){

Serial.begin(9600); //Initialize serial com

if (!SD.begin(SD_ChipSelectPin)) { //If the SS pin is in a LOW state it will send a Fail message Serial.println("SD fail");

return;

}

Memoria.speakerPin = 9; //The pin where you will put the speaker, usually the 9

}

void loop(){

Memoria.setVolume(5); //You can set the volume here up to 7

Memoria.quality(1); //only accepts 1 or 0, 1 is for better quality

Memoria.play("1.wav"); //Here you place the name of your audio

delay(10000); //This delay should be at least of the same lenght of your audio,

//This library can play the music while the arduino is in other task so you can play it background

//or wait for the audio to finish

}

Step 3: Transform the Audio Files

This will work with .wav audio files but you have to make som adjusments to it.

For that you can use the following online converter.

https://audio.online-convert.com/convert-to-wav

So, in this page you will need to change the settings like is shown on the picture then you just click in "Convert File" and wait until the convertion is done and the new file is downloaded!

Then you have to put all this audio files on a SD card and plug it into the arduino module.

There are also other features on this library like in the image above so you can use it and make a music player with buttons for the volume, next song etc, etc. Or pretty much aniything you want! The sky is the limit!

Step 4: Diagram

This is the pin setup for the arduino and the SD module:

Arduino >>>>>>> SD Module

4 >>>>>>>>>>> SS

11 >>>>>>>>>> MOSI

12 >>>>>>>>>> MISO

13 >>>>>>>>>> SCK

5v >>>>>>>>>> 5v

Gnd >>>>>>>> Gnd

9 >>>>>>>>> PWM Audio Out

The audio output can be connected to an amplified speaker beacuse is low power, also the currect consumption could damage the arduino if you connected directly.

And... you are done!

Let me know if you have any doubts, I'll be happy to answer,

Thanks for reading my instrctable!

Step 5: Results

If you have an osciloscope you should be able to see the PWM signal at the audio output like this.

And... you are done!


Let me know if you have any doubts, I'll be happy to answer,

Thanks for reading my instructable!

Share

    Recommendations

    • Arduino Contest 2019

      Arduino Contest 2019
    • Trash to Treasure

      Trash to Treasure
    • Tape Contest

      Tape Contest

    12 Discussions

    0
    None
    Lindermann95Rupeshkadam

    Answer 4 months ago

    Well is really easy, there are plenty of tutorials of how to read a IR remote control with arduino, there is a library for it.
    Then you only need add some “if” sentences. (This is one way to do it)
    “If(bla bla bla IR read == Up){
    bla bla bla.play(music);
    }
    Something like that

    0
    None
    RupeshkadamLindermann95

    Reply 4 months ago

    Another question, I don't have SD module. Can I use Intel Galileo instead of Arduino because it has an SD card slot?
    Thank You!

    0
    None
    Lindermann95Rupeshkadam

    Reply 4 months ago

    Hi there,
    Well... I've never use an Intel Galileo but the most important thing here is the audio library, if there is one for the Galileo board and there is a functional output pin then it would work, I think...
    The pin is very important, in the Arduino Mega there is only 1 functional pin, the 46, even when almos all the pins are available for PWM, not all of them will work as a speaker, I think this is something that is declared in the library.

    Give it a try and let me know :)

    0
    None
    Mister Gears

    7 months ago

    Finally !!! An instructables about it ! thank you very much ^^

    1 reply
    0
    None
    Lindermann95Gadisha

    Reply 7 months ago

    I'm glad you like it, I’m using it to make my arduino respond to me when I use a voice command, but thats a topic for another instructable, I'll upload it it soon

    0
    None
    Lindermann95Elaya1

    Reply 7 months ago

    That could be an option but... what would you use the arduino for?

    Maybe I can add the bluetooth and control the music commands from there (Play, Stop, Next... ), but I wouldnt send the audio from my phone, for this you can use basicly any bluetooth audio module.