Mp3 Shield Code

This tutorial shows you how to use the cheap mp3 shield from Ebay to add music or a robot voice to your next Arduino Project. I am going to try to do more of these tutorials for beginners so let me know in the comments what you want to see next. This elechouse mp3 shield allows your Arduino to talk, pulling files from an SD card. We will use the technique called speech store and forward, rather than using some kind of text to speech module or library.

Music: Voice Over Under - Kevin Macleod



#include <SoftwareSerial.h>
SoftwareSerial Geno(7,8); // Rx , Tx

unsigned char Data[10];
unsigned char i;

void setup() {
  delay(1000);
  Geno.begin(9600);
  delay(1000);
  SetVolume(30); 

}

void playTrack(int num){

    delay(1000);
    
    Data[0] = 0x7E; 
    Data[1] = 0x04; 
    Data[2] = 0xA0; 
    Data[3] = 0x00;
    Data[4] = 0x00 + num;
    Data[5] = 0x7E;
   Command(Data,5);

    play_pause();
    
    delay(3000);
 
}

void SetVolume( int vol){
   Data[0] = 0x7E;          // START
   Data[1] = 0x03;          // Length Not 0x02
   Data[2] = 0xA7;          // Command
   Data[3] = vol;          // new volume
   Data[4] = 0x7E;          // END
   Command(Data,5);
}

void play_pause(){
  Data[0] = 0x7E;          // START
  Data[1] = 0x02;          // Length
  Data[2] = 0xA3;          // Command
  Data[3] = 0x7E;          //Mode parameter
  Command(Data,4);
}

void Command(unsigned char *Data, int length){
    for(int i=0; i<length; i++){ 
    Geno.write(Data[i]);
    }
    
    }

void loop() {


playTrack(1);

playTrack(2);

}

Hey !!!

about us (me).

My name is Matthew, I am 26, and I attend the University of Pittsurgh. Currently I am a junior, going for a bachelors in Information Science. I am always looking for someone that would like to embark on a new project or startup. I work as a food server when I am not at school, but would love something a little more technical, if anyone is hiring.

  • Pittsburgh, PA
  • MatthewHallberg@gmail.com

Drop us a line