New Project

CONNECT

Arduino playing melody with the Sd card

  • Page Views 1144
  • Spread the love
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  

    This project will do our Arduino playing melody with music files that we upload to the sd card.If you want to install a different tune, you must add the name of the melody code.

    The components are used:

    • Arduino UNO
    • SD card reader
    • speaker

    Arduino code:

    //pin in sd card input module ** MOSI – pin 11 ** MISO – pin 12** CLK – pin 13** CS – pin 4
    
    #include <SD.h>// SD card library
    
    #define Sd_Chip_pin 4
    
    #include <TMRpcm.h>// playing the melody library
    
    char val;TMRpcm tmrpcm; // Create a melody function
    
    void setup()
    
    { Serial.begin(9600);
    
    tmrpcm.speakerPin = 9; // 9 pin to attach digital speakers + leg
    
    if (!SD.begin(Sd_Chip_pin)) {
    
    // sd module bağlanma return; } }
    
    void loop()
    
    { if (Serial.available())
    
    { delay(100);
    
    while(Serial.available() > 0)
    
    { val = Serial.read();
    
    if (val == ‘1’) { // 1 steal 1.wav file sends data
    
    tmrpcm.play(“1.wav”);
    
    }
    
    else if(val == ‘2’)
    
    { // 2.wav 2 sends data to steal files
    
    tmrpcm.play(“2.wav”); }
    
    else if(val == ‘3’)
    
    { // 3.wav sends data to steal files
    
    tmrpcm.play(“3.wav”); }
    
    else if(val == ‘4’)
    
    { // 4.wav 4 sends data to steal files
    
    tmrpcm.play(“4.wav”); }
    
    else if(val == ‘5’)
    
    { // 5.wav 5 sends data to steal files
    
    tmrpcm.play(“5.wav”); }
    
    else if(val == ‘6’){ //6.wav 6 sends data to steal files
    
    tmrpcm.play(“6.wav”);
    
    }
    
    }
    
    }
    
    }

     

    Share

    One Comment For "Arduino playing melody with the Sd card"

    Leave a comment

    Your email address will not be published. Required fields are marked *

    BE A FACEBOOK FAN

    Instagram