Play Music With Arduino!

2,167

25

8

About: Photonics Engineer

Intro: Play Music With Arduino!

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!

Audio Contest 2018

This is an entry in the
Audio Contest 2018

Share

    Recommendations

    • Audio Contest 2018

      Audio Contest 2018
    • Metalworking Contest

      Metalworking Contest
    • Tiny Home Contest

      Tiny Home Contest

    8 Discussions

    0
    None
    Mister Gears

    6 days ago

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

    1 reply
    0
    None
    Lindermann95Gadisha

    Reply 11 days 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 10 days 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.