Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Arduino
90 min
Share

Play music from sd card on 3W Speaker by arduino

Today audio players can commonly be found across many electronic products. Almost every mobile has an audio player. Audio technology gets a drastic improvement with rapid development in silicon technology. Previously audio data was stored on tape devices and CDs. But now, Flash memories are cheaper, store huge amounts of data, consume less power, and are much faster than CDs and tapes.

Project Video

Overview

In this tutorial, we will see how to play audio using the SD card Module and Arduino. We have to save the audio in .wav file and specifically command the Arduino to play the audio at the specific digital pin. The volume of the audio can also be adjusted in the coding as per the requirement, We will need an lm386 amplifier module to amplify the signal coming from the Arduino to power the speaker .

Getting the Items

Arduino Uno R3 (Voltaat Version)
Get Item
MicroSD Card Module
Get Item
LM386 Audio Power Amplifier Module
Get Item
4R 3W Speaker
Get Item
Jumper Wires – Male to Female (40 Pack)
Get Item

Steps

Wiring it Up

Before you begin wiring the sd card module and the LM386 Audio Power Amplifier module with your Arduino, let’s get some background on how does circut  works.

How Does it Work?

Simply the Arduino loads the .wav files from the micro-SD card. It then generates a signal and outputs it through the speaker connected to digital pin 9. This makes the speaker create sounds and play music. It can play many different songs saved on the micro-SD card. In this tutorial, we programmed the Arduino Audio Player to play )Muse – Butterflies and Hurricanes) you will find it in Resources section.

In order for the sound to be clear without any interference or confusion, we must convert the dimensions of the song to these dimensions :

  • Samples Per second (Hz): 16000
  • Channel: Mono
  • Bits Per Sample: 8

You don’t need to install any software in order to convert the songs to .wav files. There’s an online music converter to do the work.

Follow the steps given below to make songs compatible with your Arduino audio player:

    Upload a music file or enter a link for the song or audio file to be converted. You can even choose files from Dropbox or Google Drive. In optional settings, change bit resolution to 8 bit. Change sampling rate to 16000 Hz. Change audio channels to Mono. Click on “Show advanced options”. Set the PCM format as PCM unsigned 8-bit.Click on “Convert” and the files are converted Download the converted music file.

Formatting Your Micro-SD Card:

  1. Download the SD Formatter tool you will find it in Resources section .
  2. Run the tool as administrator.
  3. Select the proper drive to format. Give the card your favorite name by writing it on Volume label and click the “Format” button. It will prompt you with a couple of dialogues. Click on them and your card will be formatted perfectly!
  4. Add the previously converted .wav files to the card and save them with simple names such as ’Muse.wav’.

Wiring with Arduino:

Connections from the Arduino to the breadboard:

      • Arduino GND pin → Breadboard ground line

      • Arduino 5V pin → Breadboard 5V line

Connections from the LM368 to the breadboard:

  • Gnd→ Breadboard ground line
  • Gnd → Breadboard ground line
  • VCC→ Breadboard 5V line

Connections from the LM368 module to the Arduino:

      • IN→ Arduino pin 9

Connections from the speaker to the LM386 module:

  • Speaker positive wire → VCC terminal
  • Speaker negative wire → Gnd terminal

Connections from the SD card module:

  • GND pin  → Breadboard ground line
  • VCC pin  → Breadboard 5V line
  • MISO pin→ 12
  • MOSI pin→ 11
  • SCK pin  → 13
  • CS pin    → 10



*/

Coding

/*


Voltaat learn (http://learn.voltaat.com)


Link for full tutorial:

Tutorial: Play music from sd card on 3W Speaker by arduino!


SD Library:




The purpose of this sketch is to to play the song that you previously added to the sd card .

Connections from the Arduino to the breadboard:

      • Arduino GND pin → Breadboard ground line

      • Arduino 5V pin → Breadboard 5V line

Connections from the LM368 to the breadboard:

  • Gnd→ Breadboard ground line
  • Gnd → Breadboard ground line
  • VCC→ Breadboard 5V line

Connections from the LM368 module to the Arduino:

      • IN→ Arduino pin 9

Connections from the speaker to the LM386 module:

  • Speaker positive wire → VCC terminal
  • Speaker negative wire → Gnd terminal

Connections from the SD card module:

  • GND pin  → Breadboard ground line
  • VCC pin  → Breadboard 5V line
  • MISO pin→ 12
  • MOSI pin→ 11
  • SCK pin  → 13
  • CS pin    → 10



*/


#include "SD.h"
#define SD_ChipSelectPin 10
#include "TMRpcm.h"
#include "SPI.h"

TMRpcm tmrpcm;

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

tmrpcm.setVolume(5);
tmrpcm.play("Muse.wav");
}

void loop(){
}

 

Testing it Out

know when your plant needs watering

Plug in the power, and your Arduino audio player will successfully play a song.

Resources

No items found.