Play Music With Arduino!

by Lindermann95 in Circuits > Audio

24444 Views, 56 Favorites, 0 Comments

Play Music With Arduino!

IMG_1561.jpg

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!

Parts

IMG_1562.jpg

We will need the following parts:

Arduino UNO

SD Card Reader

Jumper Wires

Audio Amplifier

Speaker

Code

Code.PNG

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

}

Transform the Audio Files

2.PNG
Captura.PNG

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!

Diagram

image1.jpeg

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!

Results

TEK00000.PNG

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!