DFPlayer를 사용하면 Micro SD 카드에 담긴 MP3 파일을 재생할 수 있다.
이 때, 파일명은 '0001.mp3, 0002.mp3, 0003.mp3, ....., ' 와 같이 지정해준다.
https://drive.google.com/file/d/1zfwc0YLR6hvMUwR9QaWn2VMKKQCBWP9s/view?usp=sharing
Sketch Code
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
SoftwareSerial MP3Module(10, 11); // 노이즈 방지를 위해 1kΩ 저항을 달아준다
DFRobotDFPlayerMini MP3Player;
void setup () {
Serial.begin (9600);
MP3Module.begin(9600);
// MP3 모듈을 초기화
// 초기화에 실패하면 오류를 발생
if (!MP3Player.begin(MP3Module)) {
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while (true);
}
delay(1);
MP3Player.volume(30); // 볼륨을 조절 (0~30까지 설정 가능)
}
void loop () {
MP3Player.play(1); // 0001.mp3를 재생
delay (3000);
MP3Player.play(2); // 0002.mp3를 재생
delay (3000);
MP3Player.play(3); // 0003.mp3를 재생
delay (3000);
}