Music Player Using Arduino

15,985

11

4

Introduction: Music Player Using Arduino

About: Hi, I'm Nemeen, Electronics Enthusiast! I have seen a huge decline in electronics hobbyist in past few years. I started this channel in order to inspire you to create. Hopefully, you will find something that …

Arduino Music Player is a simple and fun Arduino project which can be build in 10–15 minutes. Once we have the hardware. The project is very simple. An Arduino audio player that plays “.wav” files. It consists of a speaker, a amplifier, and a micro-SD card adapter for a micro-SD card that holds the .wav files.

This project is Sponsored by JLCPCB

They provide high quality PCB at very low prices. You can order 2 to 6 layer pcbs from them. Starting at only $2 for 2 layer PCB. You can also add SMD stencil along side with your order only for additional $7

Check them out! - https://jlcpcb.com

Supplies

Parts List:

  1. Arduino Nano
  2. SD Card Module
  3. Speaker

Arduino Library:

Additionally we need and Arduino library, In Arduino IDE, go to Tools Manage Libraries, and search for “TMRpcm” and click on install.

Step 1: Watch the Video

If you dont wish to read all the steps you can watch my video tutorial!

Step 2: Schematic & Code

#include <SD.h> // need to include the SD library
#define SD_ChipSelectPin 4 //connect pin 4 of arduino to cs pin of sd card
#include <TMRpcm.h> //Arduino library for asynchronous playback of PCM/WAV files
#include <SPI.h> //  need to include the SPI library

TMRpcm tmrpcm; // create an object for use in this sketch
int temp=1;
int pp=5;
int next=6;
int prev=7;
void setup()
{ 
 pinMode(pp,INPUT_PULLUP);
 pinMode(next,INPUT_PULLUP);
 pinMode(prev,INPUT_PULLUP);
 
 tmrpcm.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
 Serial.begin(9600);
 if (!SD.begin(SD_ChipSelectPin)) // returns 1 if the card is present
 {
  Serial.println("SD fail");
  return;
 }

 tmrpcm.setVolume(5); //
 tmrpcm.play("song1.wav"); //the sound file "song" will play each time the arduino powers up, or is reset
                          //try to provide the file name with extension
                     
}


void loop()
{  
  while(digitalRead(pp)==0 || digitalRead(next)==0 || digitalRead(prev)==0)
  {
    if(digitalRead(pp)==0)
    {
      tmrpcm.pause();
      while(digitalRead(pp)==0);
      delay(200);
    }
    else if(digitalRead(next)==0)
    {
      if(temp<4)//temp should be lesser than no. of songs 
      temp=temp+1;
      while(digitalRead(next)==0);
      delay(200);
      song();
    }
    else if(digitalRead(prev)==0)
    {
      if(temp>1)
      temp=temp-1;
      while(digitalRead(prev)==0);
      delay(200);
      song();
    }
  }
}

void song (void)
{
  if(temp==1)
  {
    tmrpcm.play("Song1.wav");  
  }
  else if(temp==2)
  {
    tmrpcm.play("Song2.wav");  
  }
  else if(temp==3)
  {
    tmrpcm.play("Song3.wav");  
  }
  else if(temp==4)
  {
    tmrpcm.play("Song4.wav");  
  }
}

Step 3: Soldering & Coding!

Firstly, solder all parts as shown about in the circuit diagram. The SD card Module in the circuit shown above loads the .wav files. From the micro-SD card. Which is interfaced with arduino using SPI protocol.

Secondly the arduino processes the information on SD card and generates the signal and outputs it through the speaker connected to digital pin 9 on ARDUINO NANO & UNO. Also Digital pin 5,6,11 or 46 on Arduino Mega, This allows the speaker to create sounds and play Audio.

Once soldering is done upload the code provided in above step.

Step 4: Converting Music Files

Now we need to convert music into desirable format. Accordingly the WAV files used in this circuit have a slight limitation in playing audio. Since a Arduino is used, it cannot read complex .wav files. Therefore, the .wav files should be converted to have these dimensions:

  • Samples Per second (Hz): 16000
  • Channel: Mono
  • Bits Per Sample: 8PCM
  • format: PCM unsigned 8-bit

Therefore to convert the Music into desirable formant we will use this website – https://audio.online-convert.com/convert-to-wav

Once, the conversion is done rename the songs as song1, song2, song3 etc. Also don’t forget to, format the microSD Card as FAT using any formatting software like SD Memory Card Formatter and copy all the WAV audio files to the card.

Step 5: That's All!

By default, the first song (i.e. song1.wav) will play automatically once the Arduino is reset. We can use the Play / Pause Button to well, play or pause the current track. Use Next Button to play the next track and Prev Button to play the previous track. with that being done you have your own Arduino Based Music Player.

with that being done you have your own Arduino Based Music Player.

Be the First to Share

    Recommendations

    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • Make It Bridge

      Make It Bridge
    • Big and Small Contest

      Big and Small Contest

    4 Comments

    0
    williamG
    williamG

    Question 4 months ago on Introduction

    Hello. I have the Arduino Uno R3, I'm wondering if the function of the buttons in this music player, can be done programmatically. This is what I'm trying to achieve: My SD card will have say 15 separate audio files (song 1, song 2, etc.), I will trigger the Play function with an Motion Sensor, I always want to play the first file (Song 1) first, after sensing motion, After Song 1 is complete I want to automatically play Randomly, any one of the other 14 files (songs 2 to 15), After playing the second file the unit will stop playing and return to an initialized state, waiting for another Motion Sensor trigger. Any thoughts on if this is achievable? Appreciate your time and help.

    0
    mileycyrustaku
    mileycyrustaku

    Question 2 years ago

    How about LM386? do we need it or it will work without it?

    0
    Alex in NZ
    Alex in NZ

    2 years ago

    Nice! I was wanting something just exactly like this! Thank you for sharing your work :-)