Built-in project · Arduino Uno R3

Jukebox on an Arduino Uno

A DFPlayer Mini over SoftwareSerial with DFRobot’s library: it plays the microSD card’s files one after another, hears each one end, and watches BUSY. The whole build, an Arduino Uno and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Intermediate Runs in your browser. Free, and no account needed.

The parts retail for about $33. On Mokxi they're free.

Step by step, with the wiring and the common mistakes: Arduino DFPlayer Mini MP3 Player: Wiring and Code

Jukebox · Arduino Uno R3live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// Jukebox: a DFPlayer Mini plays the files on its microSD card one after
// another, driven with DFRobot's library over a software serial port.
//
//   DFPlayer   VCC -> 5 V   GND -> GND
//              RX  <- 1 k <- pin 11   (the module's inputs are 3.3 V)
//              TX  -> pin 10
//              BUSY -> pin 3          (low while a file plays)
//
// The module does the decoding itself: the sketch only sends it ten-byte
// commands, "play file 1", "volume 20", and hears back when a file ends. The
// card on the canvas holds four files of three seconds each; there is no sound,
// but the module shows what it is playing.

#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>

const int BUSY_PIN = 3;

SoftwareSerial link(10, 11);
DFRobotDFPlayerMini player;
int track = 1;
int files = 0;
bool wasBusy = false;

void setup() {
  Serial.begin(9600);
  link.begin(9600);
  pinMode(BUSY_PIN, INPUT);
  if (!player.begin(link)) {
    Serial.println("Unable to begin: check the wiring and the card");
    while (true) {
    }
  }
  player.volume(20);
  files = player.readFileCounts();
  Serial.print("Jukebox ready, ");
  Serial.print(files);
  Serial.println(" files");
  player.play(track);
}

void loop() {
  bool busy = digitalRead(BUSY_PIN) == LOW;
  if (busy != wasBusy) {
    wasBusy = busy;
    Serial.println(busy ? "playing" : "quiet");
  }
  // The module reports the end of a file twice; only the report for the
  // file that is playing moves on.
  if (player.available() && player.readType() == DFPlayerPlayFinished && (int)player.read() == track) {
    Serial.print("finished file ");
    Serial.println(track);
    track = track % files + 1;
    delay(200);
    player.play(track);
  }
}

Parts list

4 parts, plus the jumper wires. They retail for about $33; on Mokxi they're free.

How it is wired

6 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • Arduino Uno R3 pin 11; Resistor, 1k Ω pin 1
  • Arduino Uno R3 pin 10; DFPlayer Mini MP3 module pin TX
  • Arduino Uno R3 pin 3; DFPlayer Mini MP3 module pin BUSY
  • Arduino Uno R3 pin 5V; DFPlayer Mini MP3 module pin VCC
  • Ground: Arduino Uno R3 pin GND; DFPlayer Mini MP3 module pin GND
  • DFPlayer Mini MP3 module pin RX; Resistor, 1k Ω pin 2

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.