Cut in an Ad while playing music_Mini MP3 Playe DFR0299
There is already many useful commands in the library on its wiki, it's a powerful mini MP3 module. But actually, recently I found something new from the Chinese version datasheetof the module——play an Ad file while playing background music, after finishing the Ad, it will go back to play the background music file. Pretty cool but there is supprisingly no discription on the manual book I guess it's because this function is not stable, after I test. See in the end.
Anyway, this post will show you how to make it! Include:
*The revised library
*Sample sketch
*Connection
*etc more details
Requirments:
*Arduino controller( Here I use Uno, others are ok, but you have to check its interrupt pin )
*Mini MP3 Player module
*SD/TF card
*A button( as an external interrupt ) (suggested one)
*A speaker
*Some Wires
*A USB cable for arduino
STEP
STEP 1 Download and Install the library first!
STEP 2 Place two folders and two music files( MP3/ WAV/ WMA) into seperate folders like this: The name of the folders and music files must be like with the picture shows.
STEP 3 Connection
STEP 4 Upload the sketch below, it's also in the attachment.
STEP 5 After all the steps above, if your SD card is no problem and the file name is correct (which start with number e.g. 0001Amazing Grace.mp3) the mp3 player should start to play the music, and if you press the button it will start to play the AD file in the ADVERT folder, after finish......That it! But sometimes, it will need to press the button several times to call the ad_play() function, I guess if use the millis() to replace delay() will help. More info seen in the arduino IDE sample sketch "blink without delay".
Thanks for your reading!
Anyway, this post will show you how to make it! Include:
*The revised library
*Sample sketch
*Connection
*etc more details
Requirments:
*Arduino controller( Here I use Uno, others are ok, but you have to check its interrupt pin )
*Mini MP3 Player module
*SD/TF card
*A button( as an external interrupt ) (suggested one)
*A speaker
*Some Wires
*A USB cable for arduino
STEP
STEP 1 Download and Install the library first!
STEP 2 Place two folders and two music files( MP3/ WAV/ WMA) into seperate folders like this: The name of the folders and music files must be like with the picture shows.
STEP 3 Connection
STEP 4 Upload the sketch below, it's also in the attachment.
Code: Select all
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3ad.h>
boolean play_state = HIGH; // module play state HIGH:NOT playing; LOW:playing
boolean adState = HIGH; // is the AD music playing? HIGH:NOT playing; LOW:playing
int playStatePin = 5; //digital pin5: read the module play state
SoftwareSerial mySerial(10, 11); // RX, TX (Serial wiring; RX-TX, TX-RX)
void setup () {
Serial.begin (9600);
mySerial.begin (9600);
mp3_set_serial (mySerial); //set softwareSerial for DFPlayer-mini mp3 module
mp3_set_volume (14); //value 0~30
delay(1000); //wait for the module setting finished
attachInterrupt(0, playAd, RISING ); //connect a button on Arduino interrupt 0
//check interrupt map https://www.arduino.cc/en/Reference/AttachInterrupt
}
// The delays are indispensible!!!
void loop () {
delay(1000);
play_state = digitalRead(playStatePin);
if (play_state == HIGH ) {
mp3_reset ();
delay(1000);
mp3_next ();
delay(100);
}
if (adState == LOW) {
delay(100);
play_state = digitalRead(playStatePin);
while (play_state == LOW)
play_state = digitalRead(playStatePin);
adState = HIGH;
ad_stop();
delay(100);
}
}
void playAd() {
ad_play (2);
adState = LOW;
}
STEP 5 After all the steps above, if your SD card is no problem and the file name is correct (which start with number e.g. 0001Amazing Grace.mp3) the mp3 player should start to play the music, and if you press the button it will start to play the AD file in the ADVERT folder, after finish......That it! But sometimes, it will need to press the button several times to call the ad_play() function, I guess if use the millis() to replace delay() will help. More info seen in the arduino IDE sample sketch "blink without delay".
Thanks for your reading!
DFPlayerMiniMp3ad.zip Download(0)
place MP3 files in seperate folders.png Download(0)
bitmap.png Download(0)
2019-05-28 01:27:54
Hi,
Which Arduino controller would be the best? I'm planning a project, but I'm not sure what specs to use - and which USB cable for Arduino - any best fits? Thanks. che.utexas
budiwahyunugroho92 wrote:
I do not know what happened with my project .. I've been followed the tutorial ... but the result is like this.
Leff wrote:
Hi,
Sorry for my belated reply!
The display error are ofen caused by the baud rate setting, please make it as corresponding as the setting in your code. Attachments downloaded at https://hireessaywriter.org/ more than 6100 times.
Hi,
Which Arduino controller would be the best? I'm planning a project, but I'm not sure what specs to use - and which USB cable for Arduino - any best fits? Thanks. che.utexas
2018-08-15 17:50:25 Do you want to use the mp3 without the microcontroller? Could you explain why you don't want to use a microcontroller? robert.chen
2018-08-15 02:44:34 Any idea or example circuit on How can i disable the long key press detection in using the AD KEY without using a microcontroller? Medina Ronel
2016-02-23 19:31:40
Hi,
Sorry for my belated reply!
The display error are ofen caused by the baud rate setting, please make it as corresponding as the setting in your code. Leff
budiwahyunugroho92 wrote:I do not know what happened with my project .. I've been followed the tutorial ... but the result is like this.
Hi,
Sorry for my belated reply!
The display error are ofen caused by the baud rate setting, please make it as corresponding as the setting in your code. Leff
2016-01-12 20:14:11 I do not know what happened with my project .. I've been followed the tutorial ... but the result is like this. budiwahyunugroho92
2015-11-26 21:17:09 i don't know why about this problem... can you help me [
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3ad.h>
boolean play_state = HIGH; // module play state HIGH:NOT playing; LOW:playing
boolean adState = HIGH; // is the AD music playing? HIGH:NOT playing; LOW:playing
int playStatePin = 5; //digital pin5: read the module play state
SoftwareSerial mySerial(10, 11); // RX, TX (Serial wiring; RX-TX, TX-RX)
void setup () {
Serial.begin (9600);
mySerial.begin (9600);
mp3_set_serial (mySerial); //set softwareSerial for DFPlayer-mini mp3 module
mp3_set_volume (14); //value 0~30
delay(1000); //wait for the module setting finished
attachInterrupt(0, playAd, RISING ); //connect a button on Arduino interrupt 0
//check interrupt map https://www.arduino.cc/en/Reference/AttachInterrupt
}
// The delays are indispensible!!!
void loop () {
delay(1000);
play_state = digitalRead(playStatePin);
if (play_state == HIGH ) {
mp3_reset ();
delay(1000);
mp3_next ();
delay(100);
}
if (adState == LOW) {
delay(100);
play_state = digitalRead(playStatePin);
while (play_state == LOW)
play_state = digitalRead(playStatePin);
adState = HIGH;
ad_stop();
delay(100);
}
}
void playAd() {
ad_play (2);
adState = LOW;
}
sketch_nov26a.ino: In function 'void setup()':
sketch_nov26a:13: error: 'mp3_set_serial' was not declared in this scope
sketch_nov26a:14: error: 'mp3_set_volume' was not declared in this scope
sketch_nov26a.ino: In function 'void loop()':
sketch_nov26a:25: error: 'mp3_reset' was not declared in this scope
sketch_nov26a:27: error: 'mp3_next' was not declared in this scope
sketch_nov26a:37: error: 'ad_stop' was not declared in this scope
sketch_nov26a.ino: In function 'void playAd()':
sketch_nov26a:43: error: 'ad_play' was not declared in this scope budiwahyunugroho92
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3ad.h>
boolean play_state = HIGH; // module play state HIGH:NOT playing; LOW:playing
boolean adState = HIGH; // is the AD music playing? HIGH:NOT playing; LOW:playing
int playStatePin = 5; //digital pin5: read the module play state
SoftwareSerial mySerial(10, 11); // RX, TX (Serial wiring; RX-TX, TX-RX)
void setup () {
Serial.begin (9600);
mySerial.begin (9600);
mp3_set_serial (mySerial); //set softwareSerial for DFPlayer-mini mp3 module
mp3_set_volume (14); //value 0~30
delay(1000); //wait for the module setting finished
attachInterrupt(0, playAd, RISING ); //connect a button on Arduino interrupt 0
//check interrupt map https://www.arduino.cc/en/Reference/AttachInterrupt
}
// The delays are indispensible!!!
void loop () {
delay(1000);
play_state = digitalRead(playStatePin);
if (play_state == HIGH ) {
mp3_reset ();
delay(1000);
mp3_next ();
delay(100);
}
if (adState == LOW) {
delay(100);
play_state = digitalRead(playStatePin);
while (play_state == LOW)
play_state = digitalRead(playStatePin);
adState = HIGH;
ad_stop();
delay(100);
}
}
void playAd() {
ad_play (2);
adState = LOW;
}
sketch_nov26a.ino: In function 'void setup()':
sketch_nov26a:13: error: 'mp3_set_serial' was not declared in this scope
sketch_nov26a:14: error: 'mp3_set_volume' was not declared in this scope
sketch_nov26a.ino: In function 'void loop()':
sketch_nov26a:25: error: 'mp3_reset' was not declared in this scope
sketch_nov26a:27: error: 'mp3_next' was not declared in this scope
sketch_nov26a:37: error: 'ad_stop' was not declared in this scope
sketch_nov26a.ino: In function 'void playAd()':
sketch_nov26a:43: error: 'ad_play' was not declared in this scope budiwahyunugroho92