Example Code for Arduino-Playback
Last revision 2025/12/19
The article provides example code for Arduino playback, enabling users to control music files by playing, pausing, and navigating tracks, perfect for those learning Arduino programming.
Hardware Preparation
- DFR0216 DFRduino UNO R3 x 1
- DFR0781 Audio & BLE/SPP Pass-through Module x 1
- FIT0449 Speaker with Amplifier x 1
- FIT0916-FF DuPont Wires x4
Software Preparation
- Download Arduino IDE: Click to download Arduino IDE
- Download the DFRobot_BT401 library: DFRobot_BT401 library
- About how to install the library?
Wiring Diagram

Other Preparation Work
It is recommended to use hardware serial to drive this module, since it may be unstable when using software serial, which may result in unknown errors.It is suggested to reduce the module's baud rate to 9600 when using software serial driver. Delay 2s for the BT401 to start before initializing.
Sample Code
/*!
* @file playMusic.ino.ino
* @brief Play song in TF card
* @n Experiment Phenomenon:play music and do the related actions
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @licence The MIT License (MIT)
* @author [Eddard]([email protected])
* @version V1.0
* @date 2020-12-29
* @get from https://www.dfrobot.com
* @url https://github.com/cdjq/DFRobot_ID809
*/
#include <DFRobot_BT401.h>
#include <SoftwareSerial.h>
SoftwareSerial btSerial(2, 3); //RX TX
DFRobot_BT401 bt;
void setup(){
btSerial.begin(115200);
/*Delay 2s for the BT401 to start*/
delay(2000);
while(!bt.begin(btSerial)){
Serial.println("Init failed, please check wire connection!");
delay(1000);
}
bt.setVOl(30);
bt.switchFunction(bt.eTFCard);
bt.setPlayMode(bt.eDeviceCycle);
}
void loop(){
//Play
bt.playControl(bt.ePlay);
delay(3000);
//Pause
bt.playControl(bt.ePause);
delay(3000);
//Next
bt.next();
delay(3000);
//Last
bt.last();
delay(3000);
//Play song in the first file
bt.playFileNum(1);
while(1);
/*Delete the currently playing file*/
//bt.delCurFile();
}
Result
The module will enter music mode on power-up, play the last recorded file, pause after 3 seconds, play the next song after another 3 seconds, play the previous song after 3 seconds, and finally play the first file copied into the device.
Additional Information
Ensure the TF card has music files and is properly inserted before powering on the module.
Was this article helpful?
