Introduction: Arduino MP3 Shield
Hi , I would today to share my experiment with MP3 Shield from ELECHOUSE , this Shield have Inboard Keys which is can control the Audio file very easy , Support FAT16 And FAT32 , And can read MP3 , WAV Format from SD Card , U disk , and from Build in SPI Flash memory , that Give you an ability to save your Audio file on the Board and play it later, so no need to External Storage device .
as I mentioned before , this shield Has Inboard Keys to control the Audio file , and You can Control the Audio File by Programming from Arduino , You can program your Audio when it's begin , Switch between file and Control the Volume Up and Down very easy .
I want to Show you How we can Play Audio from SD Card and U Disk .
The component that we need is :
1) Arduino Board .
2) Arduino USB-SD MP3 Shield From ELECHOUSE You can buy it from here .
3) SD Card With adapter.Or USB Flash .
4) Speakers Or Headset .
Step 1: Arduino MP3 Shield
The Arduino MP3 Shield Have many Advantages such like Control by Serial UART interface or keys onboard , Have Build in Audio Amplifier 3W , and has On board 64MBit SPI-FLASH, which you can Save Your Audio file , and play it later .
This Shield can controlled from Arduino By Hardware Serial "Rx D0 , Tx D1 " and By Software Serial " RX D7 , Tx D8" So at first You can Use Hardware serial , easy to use but you must remove the shield when you want to Upload new sketch .
You can change The Serial interface pin by solder tools , Just remove the solder from Upper 2 pads and solder a small bridge between the 2 pads below to active Software serial Pin . look to the image attached to see these 3 pads .
You can also Bridge amplifier control bridge so you can turn on or Off by solder Amplifier Control pin , so This pin attached to arduino D9 Pin , I didn't use it in this experiment
You can also Solder Pin header on This shield "Look at the Picture" So You can connect Speakers to this shield
Step 2: Prepare Your Audio File
You can play 2 audio file format , MP3 And WAV , Before you can play your Audio file on this shield you must :
1) Copy your Audio File to SD Card or U- disk storage Device .
2) Add prefix 0000~9999 to the file names like 0000-My music.mp3 So the shield deal with the Files number , Not with Names .
3) insert Storage device on the shield , power it on .
So let's see how we can control the audio file .
Step 3: Play the Audio File
What ever if you are modify This shield to control it via Software serial or leave it as Hardware serial , Just you need is upload the sketch below to your arduino , in this step You can control the Audio file , Play , pause , Volume up and down , and Put the shield in sleep mode , through The button on Board .
This code for play sond from SD Card , you can change it to play U Disk , read the code below .
Upload this code if you are Using Software serial :
//..............................................................................................
//Written by : Mohannad Rawashdeh
// this code For MP3 Shield Elechosue
// Software serial interface
// For product : http://www.elechouse.com/elechouse/index.php?main_page=product_info&cPath=168_170&products_id=2193
//https://www.instructables.com/member/Mohannad+Rawashdeh/
#include <SoftwareSerial.h>
SoftwareSerial Geno(7,8); // Rx , Tx
unsigned char cmd_buf[10];
unsigned char i;
void ArduinoMP3Shield_SendCMD(unsigned char *cmd_buf, unsigned len)
{
unsigned i;
for(i=0; i<len; i++){
Geno.write(cmd_buf[i]);
}
}
void setup(void)
{
/** wait until arduino mp3 shield get ready */
delay(1000);
Geno.begin(9600);
/** set volume */
cmd_buf[0] = 0x7E; // START
cmd_buf[1] = 0x03; // Length
cmd_buf[2] = 0xA7; // Command
cmd_buf[3] = 0x0F; // new volume
cmd_buf[4] = 0x7E; // END
ArduinoMP3Shield_SendCMD(cmd_buf, 5);
/** set play mode repeat all */
cmd_buf[0] = 0x7E; // START
cmd_buf[1] = 0x03; // Length
cmd_buf[2] = 0xA9; // Command SET MODE
cmd_buf[3] = 0x02; // set mode
cmd_buf[4] = 0x7E; // END
ArduinoMP3Shield_SendCMD(cmd_buf, 5);
/** select SD card first music and play */
cmd_buf[0] = 0x7E; // START
cmd_buf[1] = 0x04; // Length
cmd_buf[2] = 0xA0; // For U Disk change this line to 0xA2
cmd_buf[3] = 0x00; // file number high byte
cmd_buf[4] = 0x01; // file number low byte
cmd_buf[5] = 0x7E; // END
ArduinoMP3Shield_SendCMD(cmd_buf, 6);
}
void loop(void)
{
}
//..............................................................................................
Upload this code if you are Using Hardware serial :
//.......................................................................
// this code For MP3 Shield Elechosue
// Software serial interface
// For product : http://www.elechouse.com/elechouse/index.php?main_page=product_info&cPath=168_170&products_id=2193
//https://www.instructables.com/member/Mohannad+Rawashdeh/
unsigned char cmd_buf[10];
unsigned char i;
void ArduinoMP3Shield_SendCMD(unsigned char *cmd_buf, unsigned len)
{
unsigned i;
for(i=0; i<len; i++){
Serial.write(cmd_buf[i]);
}
}
void setup(void)
{
/** wait until arduino mp3 shield get ready */
delay(1000);
Serial.begin(9600);
/** set volume */
cmd_buf[0] = 0x7E; // START
cmd_buf[1] = 0x03; // Length
cmd_buf[2] = 0xA7; // Command
cmd_buf[3] = 0x0F; // new volume
cmd_buf[4] = 0x7E; // END
ArduinoMP3Shield_SendCMD(cmd_buf, 5);
/** set play mode repeat all */
cmd_buf[0] = 0x7E; // START
cmd_buf[1] = 0x03; // Length
cmd_buf[2] = 0xA9; // Command SET MODE
cmd_buf[3] = 0x02; // set mode
cmd_buf[4] = 0x7E; // END
ArduinoMP3Shield_SendCMD(cmd_buf, 5);
/** select SD card first music and play */
cmd_buf[0] = 0x7E; // START
cmd_buf[1] = 0x04; // Length
cmd_buf[2] = 0xA0; // Command For U Disk change this line to 0xA2
cmd_buf[3] = 0x00; // file number high byte
cmd_buf[4] = 0x01; // file number low byte
cmd_buf[5] = 0x7E; // END
ArduinoMP3Shield_SendCMD(cmd_buf, 6);
}
void loop(void)
{
}
Step 4: Control the Audio Using Aduino
No need to library to program it , But if you want there is a Library for this Shield you can Download it from Here
//..............................................................................
// Mohannad Rawashdeh
// MP3 1.2V Shield test .
#include <SoftwareSerial.h>
SoftwareSerial Geno(7,8); // Rx , Tx
unsigned char Data[10];
unsigned char i;
void setup() {
// put your setup code here, to run once:
Geno.begin(9600);
SetVolume(20); // set volume from 0-31
delay(1000);
FileSource('SD_card',0x05);
SetPlayMode('Single_play');
delay(5000);
play_pause();// Pause
delay(3000);
FileSource('SD_card',0x01);
play_pause(); // play
delay(5000);
Next();
delay(5000);
Next();
for(int v=15;v>0;v--){
SetVolume(v); // set volume from 0-31
delay(1000);
}
for(int j=0;j<15;j++){
SetVolume(j); // set volume from 0-31
delay(500);
}
delay(1000);
FileSource('SD_card',0x04);
delay(5000);
FileSource('SD_card',0x05);
// FileSource('SD_card',0x03);
//Stop();
}
void loop() {
// put your main code here, to run repeatedly:
}
// Select File sorce "SD Card, SPI Flash , U Disk "
void FileSource( char type, byte track ){
play_pause();// Pause
Data[0] = 0x7E;
Data[5] = 0x7E;
switch (type){
case 'SD_card':
// START
Data[1] = 0x04; // Length
Data[2] = 0xA0; // Command
Data[3] = 0x00; // file number high byte
Data[4] = track; // file number low byte
break;
case 'SPI_Flash':
Data[1] = 0x04; // Length
Data[2] = 0xA1; // Command spi flash 0XA1
Data[3] = 0x00; // file number high byte
Data[4] = track;
break;
case 'U_Disk':
Data[1] = 0x04; // Length
Data[2] = 0xA2; // Command
Data[3] = 0x00; // file number high byte
Data[4] = track; // file number low byte
break;
}
Command(Data,5);
play_pause();// Pause
}
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 SetPlayMode(char type){
Data[0] = 0x7E; // START
Data[4] = 0x7E; // START
switch (type){
case 'Single_play':
Data[1] = 0x02; // Length
Data[2] = 0xA9; // Command
Data[3] = 0x00; //Mode parameter
break;
case 'Repeat_single':
Data[1] = 0x02; // Length
Data[2] = 0xA9; // Command
Data[3] = 0x01; //Mode parameter
break;
case 'Repeat_all':
Data[1] = 0x02; // Length
Data[2] = 0xA9; // Command
Data[3] = 0x02; //Mode parameter
break;
case 'Play_Random':
Data[1] = 0x02; // Length
Data[2] = 0xA9; // Command
Data[3] = 0x03; //Mode parameter
break;
}
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 Stop(){
Data[0] = 0x7E; // START
Data[1] = 0x02; // Length
Data[2] = 0xA4; // Command
Data[3] = 0x7E; //Mode parameter
Command(Data,4);
}
void Next(){
Data[0] = 0x7E; // START
Data[1] = 0x02; // Length
Data[2] = 0xA5; // Command
Data[3] = 0x7E; //Mode parameter
Command(Data,4);
}
void Previous(){
Data[0] = 0x7E; // START
Data[1] = 0x02; // Length
Data[2] = 0xA6; // 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]);
}
}
The video Below show to you how it worked .
Step 5: Final , Document , Helpful Links
For more information about this shield You can return to the Manual of this shield , From Here You can Find all commands for this shield , And how you can save your audio file on Board SPI Flash memory
I will prepare some projects about this shield and share it with you .
Thank you
25 Comments
Question 1 year ago on Step 5
Want to add browsability with lcd
5 years ago
Can I make mp3 random?
5 years ago
Can I make mp4 random?
5 years ago
Can I make random mp3?
7 years ago
Thanks so much for all the info!
I am trying to make a super over engineered alarm clock.
Following your instructions I can get everything working just fine.
But I would like to make a certain .mp3 play at specific times...
Is there a command I can use to make a specific .mp3 to start playing in a if statement???
Cheers
7 years ago
hello so can I have the ardunio board call up a spesfic file from the sd and play it as part of my fuctions as in set it up so I have 3 tracks 3 buttons each button plays a spesfic track on the sd ?
7 years ago
hi man! good tutorial.
Can this shield play several audio files simultaneously?
7 years ago
hi, excellent tutorial. i have one doubt, have any possible to transform this shield in a hot swappable device? i have one, but when i unplug pen drive, the same stop playing, and when i reconnct, the shield doesnt start playing again, and then i have to reboot. have any thing that can i make to change this? thanks
7 years ago
Hello and thank you for your project, it is
clearer than the official manual! I want to put in a box the arduino , so is it possible to
add switches, through the other Arduino pins (through the shield), to control
with a code, play pause next volume functions? (in software serial mode).
Thank you for your answer.
Best.
7 years ago
Hi! I am new to arduino, I have a pretty good background in electronic in general, I've programmed automat in ladder and such, and decided to give a try to arduino. I was wondering if it is possible to connect this screen on top of the mp3 shiel, on top of the arduino: https://www.adafruit.com/products/1651
So this way I could use a touch interface to tell the arduino board to control the volume and such from the mp3 shield. Could anyone confirm me that this is possible please?
8 years ago on Introduction
Great tutorial
Is it possible to run through folders?
8 years ago on Introduction
Hi. Can i know whether the bluetooth HC-05 module still can be attached to the arduino and mp3 shield? I want to use android phone to control and i saw mp3 shield has consumed the Tx and Rx pins. Sorry i am a beginner to this.
9 years ago on Introduction
great tutorial...is it possible to play specific musics automaticly for different sensors? im working on a project that for hot tempreture or cold tempreture i wanna have different set of musics played randomly..how would that work? thank you
Reply 8 years ago on Introduction
Curious if you found an answer. I am looking for something similar!
Reply 8 years ago on Introduction
Sure, just program it into your .ino file. Only pins 7 and 8 are used, so put your sensors into other pins.
8 years ago on Introduction
to play it in certain time like an alarm ?!
need help please
8 years ago on Introduction
Very useful tutorial - the official instructions were crazy.
Still having trouble triggering specific tracks, but play pause next etc work.
Any idea about specific tracks - does this project do it (seems to)?
9 years ago on Introduction
Arduino mega, I cannot run, could you help !!!
error code :
avrdude: stk500v2_getsync(): communicating with timeout programmer
Reply 8 years ago on Introduction
try to press your reset button while uploading the code, also you could try reflashing the arduino bootloader. I got that error once. For me it was caused by overcurrent, i was trying to drive 1amp from the usb without an external psu which could cause that error. It can mean many things (your chip could be fried).
9 years ago on Step 5
Thank you for such a great tutorial! I am new to this and just installed my mp3 shield on my arduino UNO. I can't seem to get it to work. The user guide seems to suggest that an iSound.mp3 file needs to be the last file on the SD card. Is this correct? If so what text should be in the file?
Do you have any other tutorials? Thanks again for your help.