Mp3 Play From SD Card With Arduino

80,852

64

19

Introduction: Mp3 Play From SD Card With Arduino

About: Mechanical engineer, Entrepreneur, Maker, robotic systems expert and founder of Robimek and RobiBot

Audio file playback from SD card will tell. Without using any module will play MP3 audio files only with SD card reader.

Step 1: Materials:

Materials:

  1. Arduino
  2. SD card module
  3. Speaker
  4. sd card and adapter

Step 2: Electronic Section:

Download fritzing file .

SPI pins in arduino model for the communication module according to the SD card SPI protocol varies.If you use a different model that models must insert pins according to the SPI pins.

You have to convert MP3 files into WAV format.You can do the conversion in the online wave convent site. 8-bit 32000 Hz in stereo mp3 file converter file set as follows: Click the button. the files you download, install directly to your SD card.

Step 3: Software Part:

Library: SimpleSDAudio

Sample code:


#include <SimpleSDAudio.h>

void setup() {

SdPlay.setSDCSPin(4); // sd card cs pin

if (!SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO | SSDA_MODE_AUTOWORKER))

{ while(1); }

if(!SdPlay.setFile("music.wav")) // music name file

{ while(1);

}

}

void loop(void)

{

SdPlay.play(); // play music

while(!SdPlay.isStopped())

{ ;

}

}

Step 4: Result

Except arduino mega-plus pin 9 pin to digital speakers on other models, while the mega arduino 44. Insert the digital pin. We do not specify the speaker pins in the code. Library automatically provide output from these pins.

Original Project web site : turkish web and english web

Be the First to Share

    Recommendations

    • Pocket-Sized Speed Challenge

      Pocket-Sized Speed Challenge
    • Super-Size Speed Challenge

      Super-Size Speed Challenge
    • Audio Challenge 2020

      Audio Challenge 2020

    19 Discussions

    0
    Tanmay Deuskar
    Tanmay Deuskar

    4 years ago

    Hello,

    really good project and and the sd card part is really cool, but could explain the music part of the code

    0
    ssolheim2000
    ssolheim2000

    Reply 3 months ago

    In short, it doesn't work. UGH!

    0
    suneththu
    suneththu

    2 years ago

    It makes lot of noise can you explain it why

    0
    ssolheim2000
    ssolheim2000

    Reply 3 months ago

    Never could figure out this one... I'm guessing it has to do with selecting the correct sampling rate, but I tried 8K, 32K and 44K and none of them worked. Maybe someone else can shed light on this.

    0
    Tataaa
    Tataaa

    2 years ago

    How can I download simpleSDaudio library????????????

    0
    ssolheim2000
    ssolheim2000

    Reply 3 months ago

    Here's how I was able to download it...
    Go to: https://github.com/isramos/mico-shield
    Click on "Clone or Download" button.
    Click on "Download ZIP"
    Browse to "mico-shield-master (1).zip\mico-shield-master\libraries" within the ZIP.
    Copy the "SimpleSDAudio" folder into: C:\Program Files (x86)\Arduino\libraries

    0
    TarekA37
    TarekA37

    2 years ago

    Bro, this is very nice one, however I have a simple question...

    where did you place the output to pin 9.. is it in the library and how to change it to the Tx pin..??

    I am trying to transfer the audio before i receive it to the speakers directly...

    0
    ssolheim2000
    ssolheim2000

    Reply 3 months ago

    My guess is in the "SimpleSDAudioDefs.h" file.

    0
    cholinmaung
    cholinmaung

    11 months ago

    Please reply me SimpleSDAudio does not work on nodemcu boardmanager.When I upload program show avr error message

    0
    BradSabbath
    BradSabbath

    1 year ago

    int inPin = 7; // choose the input pin (for a pushbutton)
    int val = 0; // variable for reading the pin status
    void setup() {
    pinMode(inPin, INPUT); // declare pushbutton as input
    }
    void loop(){
    val = digitalRead(inPin); // read input value
    if (val == HIGH) { // check if the input is HIGH (button released)
    [Code to play sound];
    } else {
    [Code to stop sound];
    }
    }

    To add a button, you'd have to add something like this?


    1
    swany34
    swany34

    2 years ago

    "How to play an Mp3 on Arduino: Convert Mp3 to .wav"

    this is not playing an Mp3 then...

    0
    suneththu
    suneththu

    2 years ago

    can i change the speaker pin to 2,3 or 1

    0
    jnh123
    jnh123

    3 years ago

    tried and tried again , really started over 3 times got a little noice one time is all.

    0
    KunalK6
    KunalK6

    3 years ago

    To which pins can I connect the Speaker

    0
    AntunN1
    AntunN1

    Reply 3 years ago

    to digital pin 9 and gnd!!!

    0
    AntunN1
    AntunN1

    3 years ago

    i will make it ,but, where is WProgram.h and Arduino.h?

    please contact me!!!!!!!!!

    0
    UMAR B
    UMAR B

    3 years ago

    iam getting an error of"Arduino: 1.6.7 (Windows 10), Board: "Arduino/Genuino Uno"

    C:\Users\4G\Documents\Arduino\sketch_feb28b\sketch_feb28b.ino: In function 'void setup()':

    sketch_feb28b:7: error: 'SSDA_MODE_AUTOWORKER' was not declared in this scope

    if (!SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO | SSDA_MODE_AUTOWORKER))

    ^

    exit status 1

    'SSDA_MODE_AUTOWORKER' was not declared in this scope

    This report would have more information with

    "Show verbose output during compilation"

    please help me and tel me what to do

    enabled in File > Preferences."