Bukit Mertajam, Penang

Cytron MP3 shield with NEW library!

Hello everyone! Cytron MP3 shield library has been revised so now you can run other tasks on the microcontroller while you are enjoying your favorite music!

About this library….

This library allows you to execute your main tasks while playing the musics stored in SD card. A few functionalities has been added to this library to allow more flexibility to control the flow of music while the main task is being executed.


  1. Tolerate with MP3 files up to 260kbps bitrate only. This library uses TimerOne interrupt to play the files. Higher the bitrate the MP3 file, the more frequent the program enters the TimerOne interrupt and may cause the the program in main loop unstable. MP3 files with 200kbps or lower bitrate are preferable.
  2. TimerOne interrupt cannot be used for other purposes while playing MP3 files.
  3. Time critical programs in main loop might be affected if the bitrate of MP3 files are high(close to or exceeds 260kbps).

MP3 File bitrate estimation:

bitrate(kbps) = filesize(in kbit)/total time of MP3 file(in s)

For example: xxx.song with 5MB and total playtime 4 min

bitrate = 5 x 1024 x 8 / (4 x60) = 171 kbps

Other libraries requirement:

  1. SdFat (latest version)
  2. SPI
  3. TimerOne

Included functionalities:

Functions Description
mp3.Init (SS,ASD) Initialise mp3, returns true if successful e.g. mp3.Init(3,2);

– SS pin is connected to D3 on arduino

– ASD pin is connected to D2 on arduino

mp3.setVolume (byte volume) Set the volume of file playedRange: 0 (lowest) – 255 (highest)default value is 220 if mp3 initialisation is successful
mp3.Pause() Pause the song played
mp3.Resume() Resume the song played
mp3.Mute() Mute the song
mp3.Unmute() Unmute the song
mp3.Next() Play next song (only available when playing all mp3 songs in a folder)
mp3.Previous() Play previous song (only available when playing all mp3 songs in a folder)
mp3.Stop() Stop any playing songs
mp3.On() Turn on amplifier (amplifier is turned on by default after mp3.Init is successful)
mp3.Off() Turn off amplifier
mp3.PlayTrack(const char* dirName,const char* track_name) Play a single song with track_name from directory called dirName e.g. play a song named xxx.mp3 stored in Favourites/Part I folder 

mp3.PlayTrack(“Favourites/Part I”,”xxx.mp3″);

mp3.PlayTrack(const char* track_name) Play a single song with track_name from root directory
mp3.PlayTrack(const char* dirName,int track_no) Play a single song positioned at track_no from dirName directory e.g: play 5th song stored in Favourites Folder 


mp3.PlayTrack(int track_no) Play a single song positioned at track_no from root directory
mp3.PlayFolder() Play all songs in root directory
mp3.PlayFolder(const char*dirName) Play all songs in dirName directory
mp3.PlayFolderStartFrom(int start_index) Play all songs in root directory starting from song with position start_index 
mp3.PlayFolderStartFrom(const char* dirName, int start_index) Play all songs in dirName directory starting from song with position start_index e.g. play 5th song and onwards from xxx folder


mp3.PlayFolderStartFrom(const char* start_track) Play all songs from root directory starting with song named start_track
mp3.PlayFolderStartFrom(const char* dirName, const char* start_track) Play all songs from dirName directory starting with song named start_track e.g. play song named aaa.mp3 and onwards from bbb folder 


mp3.lsFiles(const char*dirName) List all mp3 files in dirName directory (requires Serial function)
mp3.isPlaying() Returns true if a song is played
mp3.isPause() Returns true if a song is paused
mp3.isMute() Returns true is a song is muted
mp3.getName() Returns the name of current song played in String
mp3.getVol() Returns the current volume of song played in byte
mp3.getCurrentDir() Returns the name of current directory where the song is played in String
mp3.getTrackNo() Returns the track number of the current song played in Integer

How to install?

Step 1:

Download MP3Player and SdFat library here.

Step 2:

Copy both files to Arduino libraries folder. NOTE: If you already have older version of SdFat Library in libraries folder, please delete it first before copying the new one to the folder.

Let’s give it a test!

Before you proceed, make sure at least you have the items listed below

Arduino Uno or other Arduino board (stackable)

USB cable (to connect the Arduino board to PC

MicroSD card

Speaker or Earphone

Step 1:

First put sta013 configuration file (sta013.cfg) inside your microSD card. sta013.cfg is a must to initialise the MP3 shield. Make sure it is in root directory (don’t need to make a folder to store it). You can download the file here.

Step 2:

Put your MP3 files inside your microSD card. You can put them directly in root directory or make a folder to store them. Just make sure names for MP3 files are not more than 80 characters and folder name not more than 20 characters.

Step 3:

Insert microSD card into microSD card slot on MP3 shield. Check the jumpers on the shield. Take a look on which pins are SS and ASD connecting to, we are going to use those numbers in MP3 initialisation later. In picture below SS is connected to D3 (Arduino board pin 3) and ASD to D2 (Arduino board pin 2).

Step 4: 

Now stack your MP3 shield on your Arduino board. Plug your earphone or speaker to DC jack on MP3 shield. Connect Arduino board to your PC using USB cable. Then start Arduino IDE.

Step 5: 

Go to File > Examples > MP3Player > ListMP3Files and open the sketch. Upload the sketch after you have done with necessary settings (selecting your board, choosing correct COM port etc).

Step 6:

Open serial monitor. You will see a request to enter the folder name that contains the songs you want to play and click send (send / if you want to play root directory). If you sent wrong, just restart serial monitor and try again. A list of MP3 files should be shown. Enter a track number to start the song. Now you are free to do anything with this player, volume up, jump to another song, mute,etc.


This new library for Cytron MP3 shield is designed to allow the program to do other tasks while playing MP3 files. Do enjoy and feel free to experiment!

If you have any inquiries, please post in our technical forum as we seldom check the comments section in tutorial site


Related Posts

Leave a comment