Audio Player Using Arduino With Micro SD Card

139,481

101

144

Introduction: Audio Player Using Arduino With Micro SD Card

About: i believe to help people and share my knowledge i always want to build creative thing some of them for learning and some of them is very useful.

Please SUBSCRIBE my channel for more projects.........................

Many of People want to interface the SD card with arduino or want some audio output via arduino.

So here is easiest and cheapest way to interface SD card with arduino . you can use the audio output from arduino via a switch or sensor .

you can play any type of sound ,music and recording but that audio will be in to .wav file. If it is in .mp3 or any other audio type then we will convert it into .wav file.

Step 1: Components & ​Requirements

  • arduino uno
  • micro SD card Adapter module
  • micro SD
  • Card Reader
  • Speaker or earphone speaker
  • woofer or amplifier

Step 2: Convert Audio to .wav

Go to the Link to convert the audio into .wav .

http://audio.online-convert.com/convert-to-wav

  1. Go to The Link
  2. Upload your audio you want to convert to WAV
  3. Change bit resolution to " 8bit ".

  4. Change sampling rate to " 16000Hz ".

  5. Change audio channels " mono " .

  6. Click on " Show advanced options ".

  7. PCM format " unsigned 8 bit ".

  8. Convert file.

At next page click on "direct download link"

Step 3: Prepare SD Card

Download the Zip file and Extract it.

Here you will get the " SD formatter "

install the SD formatter in your PC.

Now, Connect your card with PC via USB card reader.

Open SD card formatter.

Select the drive of sd card then click on format .

In Next Step Open your SD card Drive .

Past the Audio file that we have converted in .wav file

Rename the file to "test.wav".

mirror :- https://codeload.github.com/vishalsoniindia/Audio...

Step 4: Add Library in Arduino

Open The arduino Software

Click on then Sketch >> Include Library >> Add zip Library

Select "TMRpcm.zip" that is in zip folder.

Step 5: Upload the Codes

Download the code from link below or i have already mentioned in zip file .

Connect your arduino with pc and upload the Codes.

https://github.com/vishalsoniindia/Audio-Player-Us...

Step 6: ​Circuit Connections

Insert the card in micro sd adapter module.

Connect the circuit as given below.

CS ---------------------->> 10

SCK ---------------------->> 13

MOSI -------------------->> 11

MISO--------------------->> 12

VCC --------------------->> +5v

GND--------------------->> Arduino's Ground

Speaker Connection

one pin is in to 9 pin of Arduino and other is GND of Arduino

Step 7: Play the Audio

Now , It's Ready...............................

Click Reset button to play audio every time.

The OUTPUT sound is very Low so you can use woofer or amplifier for batter Output.

Microcontroller Contest 2017

Participated in the
Microcontroller Contest 2017

3 People Made This Project!

Recommendations

  • For the Home Contest

    For the Home Contest
  • Big and Small Contest

    Big and Small Contest
  • Game Design: Student Design Challenge

    Game Design: Student Design Challenge

144 Comments

0
hseruscute
hseruscute

3 months ago

can someone help me how to code in arduino
sd card with speaker
and it will play on a specific time everyday
i have rtc and i try to code it but its not running
i try also millis but still its not playing

0
harutyunyananna0213
harutyunyananna0213

4 months ago

Hi Dear friends . We have a project with arduino, but it works wrong. We have three Ultrasonic sensors, one CD card and one audioplayer. We need to read the file from CD and send it to the audioplayer everytime at least one of ultrasonic sensors detects movement.
You can see my code below. It doesn't work correct. Please, if it's possible help to find my mistake or suggest me another code.
Thanks a lot for your time.
We’ll be looking forward to hearing from you!
Best regards,
#include "SD.h"
#define SD_ChipSelectPin 4
#include "TMRpcm.h"
#include "SPI.h"

TMRpcm tmrpcm;

//define Pins
int trigPin1 = A0;
int echoPin1 = A1;

int trigPin2 = A2;
int echoPin2 = A3;

int trigPin3 = A4;
int echoPin3 = A5;

// defines variables
long duration1;
int distance1;

long duration2;
int distance2;

long duration3;
int distance3;

void setup()
{

// Sets the trigPin as an Output
pinMode(trigPin1, OUTPUT);
pinMode(trigPin2, OUTPUT);
pinMode(trigPin3, OUTPUT);
// Sets the echoPin as an Input
pinMode(echoPin1, INPUT);
pinMode(echoPin2, INPUT);
pinMode(echoPin3, INPUT);
// Starts the serial communication
Serial.begin(9600);

tmrpcm.speakerPin=9;
Serial.begin(9600);
if(!SD.begin(SD_ChipSelectPin))
{
Serial.println("SD fail");
return;
}

}


void loop()
{
// Clears the trigPin
digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration1 = pulseIn(echoPin1, HIGH);
// Calculating the distance
distance1= duration1*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance1: ");
Serial.println(distance1);

//2
// Clears the trigPin
digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration2 = pulseIn(echoPin2, HIGH);
// Calculating the distance
distance2= duration2*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance2: ");
Serial.println(distance2);

//3
// Clears the trigPin
digitalWrite(trigPin3, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin3, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin3, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration3 = pulseIn(echoPin3, HIGH);
// Calculating the distance
distance3= duration3*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance3: ");
Serial.println(distance3);

if (distance1 < 25)
{
delay(1000);
tmrpcm.setVolume(6);
tmrpcm.play("test.wav");
}

}
0
ShannonM119
ShannonM119

4 months ago

Hooked it up as shown, used a cheap speaker which maybe explains why I don't get anything out of it but white noise.

0
olivertaylorrrr
olivertaylorrrr

Question 3 years ago

Does the micro SD card have to be a certain size? I bought a 64gb micro SD and i put everything together properly (supposedly) and it still wont work.

0
ShannonM119
ShannonM119

Answer 4 months ago

Yeah, 64GB is too big. I think the Arduino can handle 16GB max.

0
jamilamossa99
jamilamossa99

Question 1 year ago on Introduction

Asalamulikum sir
Asalamulikum
My project topics simple arduino player and amplifier with lifi so I asked about which programming are use in this arduino and SD chep. Plzz contact me my email ID. Thank you.

0
vishalsoniindia
vishalsoniindia

Answer 1 year ago

I already answered of this question, read above tutorial where you find code.

0
jamilamossa99
jamilamossa99

1 year ago

Asalamulikum
My project topics simple arduino player and amplifier with lifi so I asked about which programming are use in this arduino and SD chep. Plzz contact me my email ID. Thank you

0
Ale Varghese Ninan
Ale Varghese Ninan

2 years ago

Hi , I had done the circuit as shown . I have a doubt can the vcc of the adapter module directly connected to the 5 V of arduino ?

0
Avali123
Avali123

Question 2 years ago on Step 7

I got everything exactly the same, copied the code, added the library and checked if the sd card worked, and it does and yet I cant get it to work, what am I doing wrong ?

0
yodizf
yodizf

2 years ago

Brother...
how to make an SD card for the Murottal Al Quran speaker

0
vishalsoniindia
vishalsoniindia

Reply 2 years ago

Very easy...
Play one song from my tutorial and then as same as you can play many songs

0
jonatanko666
jonatanko666

2 years ago on Step 7

i try to make SD card file read on button press and LED blink with delay ....i want to make cosplay laster gun on shot push make laser sound and light on button hold make stronger charging laser sound and im new i try to make some code but almost always have some errors cause im newbe in this and i know i forgot add library or something to make works as shuld and i dont know where to begin and cant find any similar schematic or manual on web any ideas ?

0
RyuWhite
RyuWhite

Question 2 years ago

I've been done this with $1 speaker. Sound quality was pretty bad. Any recommendations for speakers?

0
PrinceY9
PrinceY9

Question 3 years ago

I have done everything right but the voice is not at all coming from the speaker

0
aswtang
aswtang

Question 3 years ago

Hi, I managed to get the circuit working and playing music, but I'm struggling to get it to work with a sensor. I want to use a microphone sensor to start the music. I've tried merging this code with code for the sensor, but I'm relatively unfamiliar with Arduino and can't get it to work.

The code I've used is;

#include "SD.h"
#define SD_ChipSelectPin 10
#include "TMRpcm.h"
#include "SPI.h"
const int speaker = 9;
const int mic = A0;
const int threshold = 10;
int sensorReading =0;
TMRpcm tmrpcm;
void setup()
{
pinMode (speaker, OUTPUT);
tmrpcm.speakerPin=9;
Serial.begin(9600);
}
void loop() {
{ // put your main code here, to run repeatedly:
if (sensorReading >= threshold)
{(!SD.begin(SD_ChipSelectPin));
{
Serial.println("SD fail");
return;
}
tmrpcm.setVolume(10);
tmrpcm.play("test.wav");
}
delay(100);
}}

0
ShivaS68
ShivaS68

4 years ago

sir i mixed both backgroud music file and a text audio file and converted to wav. After doing all the uploading work ,when i tried to play in the speaker it just sounds buzzz.

But when i tried to play the files individually , it plays
help....i need to play both files in one time......ASAP

0
tamias47
tamias47

Reply 3 years ago

If the two (or more) tracks are always sync'd the same, you could just combine them into a single .wav file using the free program Audacity.

0
LiutaurasM
LiutaurasM

Reply 3 years ago

Heyy, same was to me, i just changed few things, just try to use pin 9 for speaker and also use PROGMEM in this code, it will play more clearlier and moreover for me actually playing :D

/* Example sketch using progmem to store wav filenames. Uses
program memory to store filenames instead of ram when playing
many different wav files.
See http://arduino.cc/en/Reference/PROGMEM for more info.
Sketch below based on the above link
*/
#include <avr/pgmspace.h>
#include <TMRpcm.h>
#include <SPI.h>
TMRpcm wav;
#include <SD.h>
#define SD_ChipSelectPin 10
static const char wav_1[] PROGMEM = "beeps/beep-8";
static const char wav_2[] PROGMEM = "warning.wav";
static const char wav_3[] PROGMEM = "verified.wav";
static const char wav_4[] PROGMEM = "engage.wav";
static const char wav_5[] PROGMEM = "link.wav";
const char *wav_table[] =
{
wav_1,
wav_2,
wav_3,
wav_4,
wav_5
//etc..
};
void setup(){
Serial.begin(9600);
wav.speakerPin = 9;
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD fail");
return;
}else{ Serial.println("SD ok"); }
}
void loop(){
if(Serial.available()){
char wavFile[33];
switch(Serial.read()){
case 'P': strcpy_P(wavFile, wav_table[0]);
wav.play(wavFile);
break;
case 'd': strcpy_P(wavFile, wav_table[1]);
wav.play(wavFile);
break;
case 't': strcpy_P(wavFile, wav_table[3]);
wav.play(wavFile);
break;
//etc.. etc...
}
}
}