New Project

CONNECT

MP3 audio file playback from SD Card with Arduino

  • Page Views 4977
  • Spread the love
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  

    Hello friends will play reading extension wav mp3 audio files from SD card to use this module in our application. Using our previous projects we have done this wtv020 mp3 module. In this application, we’ll play them the same way audio files without using this module.

    Materials:

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

     

    Electronic Section:

     

    You can download fritzing drawing of the circuit here.Let’s make our connection circuit as shown in Fig. 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. Mp3 file as follows: 8-bit 32000 Hz in stereo set, click on the convert button net. the files you download, install directly to your SD card.

     

    Software Part:
    We use the library to play audio as mp3 wav sound files from the SD card using the module. You can download the library from the link below.

    Library: SimpleSDAudio library

    Sample code:

    #include <SimpleSDAudio.h>
    
    void setup()
    {
    
    SdPlay.setSDCSPin(4); // sd kart cs pini
    
    if (!SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO | SSDA_MODE_AUTOWORKER))
    {
    while(1);
    }
    
    if(!SdPlay.setFile("music.wav")) // müzik dosya adı
    {
    while(1); //dosya bulunamassa durdur
    }
    }
    
    void loop(void) {
    
    SdPlay.play(); // seçilen dosyayı çal
    
    while(!SdPlay.isStopped()) { // müzik bittiğinde tekrar çal
    ;
    }
    }

     

    Except arduino mega-plus pin 9 pin to digital speakers on other models, 44. Insert the pin on the digital mega arduino. We do not specify the speaker pins in the code. Library automatically provide output from these pins. Our application so. We did voice our previous projects color reader. But I use them wtv020 mp3 module. I adapt to this application. You can get the code.

    // Voice Colour Robot project by Robie to 2015
    // Software license by Robimek
    // www.robimek.com
    #include <SimpleSDAudio.h>
    #include "Wire.h"
    #include "Adafruit_TCS34725.h"
    
    Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_1X);
    void setup() {
    Serial.begin(9600);
    
    if (!SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO | SSDA_MODE_AUTOWORKER)) {
    while(1);
    }
    SdPlay.setSDCSPin(4);
    if (tcs.begin()) {+-
    Serial.println("Sensör bulundu");
    } else {
    Serial.println("TCS34725 Sensör bulunamadı !");
    while (1); // Dur!
    }
    delay(1000);
    
    }
    void loop() {
    
    uint16_t clearcol, red, green, blue;
    float average, r, g, b;
    tcs.getRawData(&red, &green, &blue, &clearcol);
    
    average = (red+green+blue)/3;
    r = red/average;
    g = green/average;
    b = blue/average;
    Serial.print("\tTEMİZ:"); Serial.print(clearcol);
    Serial.print("\tKIRMIZI:"); Serial.print(r);
    Serial.print("\tYEŞİL:"); Serial.print(g);
    Serial.print("\tMAVİ:"); Serial.print(b);
    
    if ((r > 1.4) && (g < 0.9) && (b < 0.9)) { // kırmızı algılama
    Serial.print("\tKIRMIZI");
    SdPlay.setFile("kırmızı.wav");
    SdPlay.play();
    }
    else if ((r < 0.95) && (g > 1.4) && (b < 0.9)) { // yeşil algılama
    Serial.print("\tYEŞİL"); // yeşil söyle
    SdPlay.setFile("yesil.wav");
    SdPlay.play();
    }
    else if ((r < 0.8) && (g < 1.2) && (b > 1.2)) { // mavi algılama
    Serial.print("\tMAVİ"); // mavi söyle
    SdPlay.setFile("mavi.wav");
    SdPlay.play();
    }
    else if ((r > 1.15) && (g > 1.15) && (b < 0.7)) { // sarı algılama Serial.print("\tSARI"); // sarı söyle } else if ((r > 1.4) && (g < 1.0) && (b < 0.7)) { // turuncu algılama
    Serial.print("\tTURUNCU"); // turuncu söyle
    SdPlay.setFile("turuncu.wav");
    SdPlay.play();
    }
    else {
    Serial.print("\tRENK ALGILANMADI");
    
    }
    Serial.println("");
    
    
    }

    Share

    What did they say ?

    4 Comment - "MP3 audio file playback from SD Card with Arduino"

    avatar
    Sort:   The Newests | Ancients | Likes
    Rokib Hasan
    Visitor
    Rokib Hasan

    what should i do? when i try to add library arduino IDE shows this message.
    Specified folder/zip file does not contain a valid library
    Invalid library found in C:\Users\Rokib hasan\Documents\Arduino\libraries\arduino: C:\Users\Rokib hasan\Documents\Arduino\libraries\arduino
    Invalid library found in C:\Users\Rokib hasan\Documents\Arduino\libraries\arduino: C:\Users\Rokib hasan\Documents\Arduino\libraries\arduino

    Medjai
    Visitor
    Medjai

    Greetings!
    Good decision, but please help.
    How to make that sound starts when you press the button? And stops after its release as a car horn.
    And whether it is possible to make some buttons with different sounds?
    Thanks for the help!

    wpDiscuz

    BE A FACEBOOK FAN

    Instagram