Audio Wav Media Player Making Using Arduino in Bangla Tutorial
📌JLCPCB $2 for 5 pcs 2layer pcb prototype/ 4 layer pcb prototype : https://jlcpcb.com
The PCB board will be needed to make this circuit board like the picture above. I made my PCB board from http://www.jlcpcb.com. Gerber file is required to order on this website. If you want to get the Gerber file of this PCB, enter this link https://youtu.be/tpIZDV5NqpI. And if you want to design a PCB yourself, then go. at http://easyeda.com.
In this blog, I will teach you how Audio Wav Media Player Making Using Arduino in Bangla Tutorial.
Components:
1. JLC PCB
2. ATmega328p IC 1p
3. 28pin IC base 1p
4. Micro SD card adapter 1p
5. Micro SD card 1p
6. L7805 regulator ic
7. 60 MHz crystal 1p
8. power socket 1p
9.push button 2p
10. 10uf, 50v capacitor 1p
11.RED LED 1p
12. 22pf ceramic cap 2p
13. 10K resistor 1p
14.1k resistor 2p
15. F to M IC base 1p
Arduino Programming Code
_____________________________________________________________________________________________________________________________________________________________________
// include the library
#include <SPI.h> // include Arduino SPI library
#include <SD.h> // include Arduino SD library
#include "TMRpcm.h" // include TMRpcm library
#define next 2
#define _pause 3
TMRpcm audio;
File root;
void setup(void) {
Serial.begin(9600);
pinMode(next, INPUT_PULLUP);
pinMode(_pause, INPUT_PULLUP);
Serial.print("Initializing SD card...");
if (!SD.begin()) {
Serial.println("failed!");
while(true); // stay here.
}
Serial.println("OK!");
audio.speakerPin = 9; // set speaker output to pin 9
root = SD.open("/"); // open SD card main root
printDirectory(root, 0); // print all files names and sizes
audio.setVolume(5); // 0 to 7. Set volume level
audio.quality(1); // Set 1 for 2x oversampling Set 0 for normal
}
// main loop
void loop() {
if ( !audio.isPlaying() ) {
// no audio file is playing
File entry = root.openNextFile(); // open next file
if (! entry) {
// no more files
root.rewindDirectory(); // go to start of the folder
return;
}
uint8_t nameSize = String(entry.name()).length(); // get file name size
String str1 = String(entry.name()).substring( nameSize - 4 ); // save the last 4 characters (file extension)
if ( str1.equalsIgnoreCase(".wav") ) {
// the opened file has '.wav' extension
audio.play( entry.name() ); // play the audio file
Serial.print("Playing file: ");
Serial.println( entry.name() );
}
else {
// not '.wav' format file
entry.close();
return;
}
while( debounce(next) ) ; // wait until 'next' button is released
}
if ( !digitalRead(next) ) {
// 'next' button is pressed
audio.stopPlayback(); // stop playing
return;
}
if ( !digitalRead(_pause) ) {
// '_pause' button is pressed
audio.pause(); // pauses/unpauses playback
while( debounce(_pause) ) ; // wait until '_pause' button is released
}
}
// a small function for buttons debounce
bool debounce (int bt)
{
byte count = 0;
for(byte i = 0; i < 5; i++)
{
if ( !digitalRead(bt) )
count++;
delay(10);
}
if(count > 2) return 1;
else return 0;
}
void printDirectory(File dir, int numTabs) {
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
}
// end of code.
No comments