MP3 Player Module
This module is a compact and cost-effective MP3 module that can be directly connected to a speaker. The module, along with a power battery, speaker, and buttons, can be used independently, or it can be controlled via serial communication as a module for Arduino UNO or any microcontroller with serial ports. The module itself integrates hardware decoding for MP3, WAV, and WMA formats. It also supports TF card drivers and FAT16, FAT32 file systems. By using simple serial commands, users can play specific music and control playback features without the need for complex low-level operations, making it convenient, stable, and reliable.
Module Source
Purchase Link: https://detail.tmall.com/item.htm?_u=52t4uge5124c&id=609592993876&spm=a1z09.2.0.0.47582e8dqqFD4i
Baidu Netdisk Download Link:
https://pan.baidu.com/s/17W4AL9TKMVLN4h5OCZWRTA
Password: 6bb7
Specifications
Operating Voltage:3.3V~5V
Rated Current: 15mA
Control Method: Serial
Dimensions: 21mm (Length)*21mm (Width)
Instructions for Use
Hardware interface
- VCC (DFPlayer's positive power terminal) connects to the 5V pin of the development board.
- GND (DFPlayer's negative power terminal) connects to the GND pin of the development board.
- TX (DFPlayer's transmit pin) connects to the digital pin 10 (RX) of the development board.
- RX (DFPlayer's receive pin) connects to the digital pin 11 (TX) of the development board.
Usage Method
Install Library
Search for the DFRobotDFPlayerMini
ibrary and install in arduino IDE.
Enter the code:
/******************************************************************************
* Test Hardware: LCSC ColorEasyDuino Development Board
* Version Number: V1.0
* Modified By: www.lckfb.com
* Modification Date: April 17, 2024
* Function Overview:
*****************************************************************************
* Open-source development board hardware and software information and related projects hardware and software information on official website
* Development board official website: www.lckfb.com
* Technical support resident forum, any technical problems are welcome at any time to exchange learning
* LCSC Forum: club.szlcsc.com
* Follow our Bilibili account: [立创开发板], stay toned to our latest news!
* We focus on cultivating Chinese engineers rather than profiting from board sales.
******************************************************************************/
#include <SoftwareSerial.h>
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySerial(10, 11); // Arduino的10和11引脚分别作为RX和TX
DFRobotDFPlayerMini myDFPlayer;
void setup() {
mySerial.begin(9600);
Serial.begin(9600); // 开始串行通信,用于调试信息的输出
if (!myDFPlayer.begin(mySerial)) {
Serial.println(F("DFPlayer Mini 初始化失败!"));
Serial.println(F("请检查连线,或确保SD卡正确插入。"));
while (true);
}
myDFPlayer.volume(10); // 设置初始音量为10
Serial.println(F("DFPlayer Mini 准备就绪。"));
Serial.println(F("发送命令:'p' - 播放, 's' - 停止, '+': 增大音量, '-': 减小音量, 'n': 下一曲, 't <track>': 播放指定曲目。"));
}
void loop() {
if (Serial.available()) {
String command = Serial.readStringUntil('\n'); // 读取串行端口接收到的完整命令行
if (command == "p") {
myDFPlayer.play();
Serial.println("播放音乐");
} else if (command == "s") {
myDFPlayer.pause();
Serial.println("暂停播放");
} else if (command == "+") {
myDFPlayer.volumeUp();
Serial.println("增加音量");
} else if (command == "-") {
myDFPlayer.volumeDown();
Serial.println("减小音量");
} else if (command == "n") {
myDFPlayer.next();
Serial.println("下一曲");
} else if (command.startsWith("t ")) {
int track = command.substring(2).toInt(); // 提取曲目编号
if (track > 0) {
myDFPlayer.play(track);
Serial.print("播放指定曲目:");
Serial.println(track);
} else {
Serial.println("无效的曲目编号");
}
} else {
Serial.println("未知命令");
}
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Usage Testing
Save two MP3 songs in the SD card.
Play the music after the power is on.