IOT

Arduino Powered MP3 Player

Several projects require sound reproduction to add some functionality. Among these projects, we highlight: accessibility for the visually impaired, MP3 music players and the execution of voice sounds by robots, for example.

In all of these systems, we need an MP3 sound reproduction device to connect to the Arduino.

What is the DF Mini Player MP3 Module?

A compact, inexpensive MP3 module with a streamlined audio output that can be directly attached to a speaker or an earphone jack is called the DFplayer mini. A microcontroller or development board like the Arduino can be used in conjunction with the module to play music and perform other tasks like playing the next and previous song, shuffle, pausing the song currently playing, and so on. The module comes with a battery, speaker, and push buttons and can be used as a standalone module. The SDcard slot on the module accommodates both the FAT16 and FAT32 file systems.

Features

  • Support for 8 KHz, 11.025 KHz, 12 KHz, 16 KHz, 22.05 KHz, and up to 48 KHz sampling rates
  • Dynamic range support of 90 dB, SNR support of 85 dB, and 24-bit DAC output
  • Maximum 32GB TF card support, FAT16 and FAT32 file systems supported.
  • There are numerous control modes, serial mode, and AD key control mode.
  • The background music can be stopped using the broadcast language spots function.
  • Integrated 3W amplifier
  • The audio data is organised into folders; this feature supports up to 100 folders, each of which may hold close to 1000 songs.
  • 10 levels of EQ adjustment and 30 levels of loudness.

This article aims to show how to utilize this module with an Arduino board by using the push buttons to tell the board to transmit serial commands to the module and operate an MP3 player. To accomplish this, we’ll press three buttons. We can play the previous song by pressing the first button, which will act as the “previous” button. The current file being played can be “played/paused” using the second button, and the next file can be played with the third button.

Required Components

The following components are required to build this project;

  • DFPlayer Mini
  • Cheap Arduino Uno
  • Small Breadboard
  • Buttons
  • Speaker
  • Resistor
  • Wires
  • Jumper wires

Circuit Diagram

As can be seen above, there are just two pins other than VCC and GND that need to be connected in order to connect the Arduino to the DFplayer mini. The 1k resistor that was inserted between the module’s Rx pin and the Arduino was there to reduce noise, but it wasn’t necessary if your module setup didn’t have noise on the Rx line. For clarification, the relationship is explained below.

DFplayer Mini – Arduino

  • Rx – D11
  • Tx – D10
  • VCC – 5v
  • Gnd – Gnd

Check the connections once again to make sure everything is in working order. Because we will activate the internal pull-up resistors on the Arduino, our switches are purposefully linked without pull-up (or pull-down) resistors.

CODE

/// MP3 PLAYER PROJECT
/// http://educ8s.tv/arduino-mp3-player/
//////////////////////////////////////////


#include “SoftwareSerial.h”
SoftwareSerial mySerial(10, 11);
# define Start_Byte 0x7E
# define Version_Byte 0xFF
# define Command_Length 0x06
# define End_Byte 0
xEF
# define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]

# define ACTIVATED LOW

int buttonNext = 2;
int buttonPause = 3;
int buttonPrevious = 4;
boolean isPlaying = false;



void setup () {

pinMode(buttonPause, INPUT);
digitalWrite(buttonPause,HIGH);
pinMode(buttonNext, INPUT);
digitalWrite(buttonNext,HIGH);
pinMode(buttonPrevious, INPUT);
digitalWrite(buttonPrevious,HIGH);

mySerial.begin (9600);
delay(1000);
playFirst();
isPlaying = true;


}



void loop () {

if (digitalRead(buttonPause) == ACTIVATED)
{
if(isPlaying)
{
pause();
isPlaying = false;
}else
{
isPlaying = true;
play();
}
}


if (digitalRead(buttonNext) == ACTIVATED)
{
if(isPlaying)
{
playNext();
}
}

if (digitalRead(buttonPrevious) == ACTIVATED)
{
if(isPlaying)
{
playPrevious();
}
}
}

void playFirst()
{
execute_CMD(0x3F, 0, 0);
delay(500);
setVolume(20);
delay(500);
execute_CMD(0x11,0,1);
delay(500);
}

void pause()
{
execute_CMD(0x0E,0,0);
delay(500);
}

void play()
{
execute_CMD(0x0D,0,1);
delay(500);

}

void playNext()
{
execute_CMD(0x01,0,1);
delay(500);
}

void playPrevious()
{
execute_CMD(0x02,0,1);
delay(500);
}

void setVolume(int volume)
{
execute_CMD(0x06, 0, volume); // Set the volume (0x00~0x30)
delay(2000);
}

void execute_CMD(byte CMD, byte Par1, byte Par2)
// Excecute the command and parameters
{
// Calculate the checksum (2 bytes)
word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
// Build the command line
byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge,
Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte};
//Send the command line to the module
for (byte k=0; k<10; k++)
{
mySerial.write( Command_line[k]);
}
}



DEMO

Place a song-filled SD card into the DFPlayer Mini, upload the code to your Arduino, then attach speaker wires to the DFPlayer Mini’s speaker pins. From the connected speaker, music should begin to stream. The graphic below should represent your final configuration.

Applications

  • Fire alarm voice prompts
  • Toll station’s voice prompts
  • Electricity, communications, financial business hall voice prompts
  • Multi-channel voice alarm or equipment operating guide voice

Conclusion

I hope all of you have understood How to Design Arduino Powered MP3 Player. We MATHA ELECTRONICS will be back soon with more informative blogs soon.

Leave a Reply

Your email address will not be published.