Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO and DFPlayer Mini Audio Playback System with Button Control

View and Edit Project In Cirkit DesignerImage of Arduino UNO and DFPlayer Mini Audio Playback System with Button Control

Circuit Documentation

Summary

This circuit is designed to play audio files from a DFPlayer Mini module when a button is pressed. The audio output is sent to a TRRS 3.5mm jack, which can be connected to headphones or an external speaker. The circuit is powered by a 5V power supply and controlled by an Arduino UNO microcontroller.

Component List

  1. DFPlayer MINI

    • Description: A small MP3 player module that can play audio files from a microSD card.
    • Pins: VCC, BUSY, RX, USB -, TX, USB +, DAC_R, K2/ADC_KEY, DAC_L, K1/ADC_KEY, SPK1, IO 2, GND, SPK2, IO 1
  2. TRRS 3.5mm Jack Breakout

    • Description: A breakout board for a 3.5mm TRRS jack, used for audio output.
    • Pins: Sleeve, Ring2, Ring1, Tip
  3. POWER SUPPLY 5V 5AMP

    • Description: A power supply module that provides 5V DC output.
    • Pins: 220V Positive Pole (AC), 220V Negative Pole (AC), GND, GND (DC), 12V-24V Output (DC)
  4. KY-004 Key Switch Module

    • Description: A simple key switch module used as a button input.
    • Pins: S, Middle, -
  5. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P, used to control the circuit.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0

Wiring Details

DFPlayer MINI

TRRS 3.5mm Jack Breakout

POWER SUPPLY 5V 5AMP

KY-004 Key Switch Module

Arduino UNO

Code Documentation

#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

// Define software serial for DFPlayer Mini communication
SoftwareSerial mySerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;

// Pin for button
const int buttonPin = 2;
bool buttonState = false;

void setup() {
  // Start Serial Monitor for debugging
  Serial.begin(9600);
  Serial.println("Initializing...");

  // Initialize button pin
  pinMode(buttonPin, INPUT_PULLUP); // Enable internal pull-up resistor
  Serial.println("Button pin set as INPUT with pull-up.");

  // Initialize DFPlayer Mini
  mySerial.begin(9600); // Start communication with DFPlayer Mini
  if (!myDFPlayer.begin(mySerial)) {
    Serial.println("DFPlayer Mini initialization failed!");
    Serial.println("1. Check wiring (RX, TX, VCC, GND).");
    Serial.println("2. Ensure SD card is formatted as FAT32 and files are loaded.");
    while (true); // Halt execution if DFPlayer Mini fails to initialize
  }
  Serial.println("DFPlayer Mini initialized successfully.");

  // Configure DFPlayer Mini settings
  myDFPlayer.volume(20); // Set volume (0-30)
  Serial.println("Volume set to 20.");
  myDFPlayer.EQ(DFPLAYER_EQ_NORMAL); // Set EQ mode
  Serial.println("EQ set to normal.");
  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD); // Set SD card as the audio source
  Serial.println("Output device set to SD card.");
}

void loop() {
  // Read button state
  if (digitalRead(buttonPin) == LOW) { // Button is pressed
    if (!buttonState) { // Prevent multiple triggers
      buttonState = true;
      Serial.println("Button pressed. Playing sound...");
      myDFPlayer.play(1); // Play the first file (001.mp3)
      Serial.println("Playing track 001.mp3...");
    }
  } else {
    // Reset button state when released
    if (buttonState) {
      Serial.println("Button released.");
    }
    buttonState = false;
  }

  // Optional: Add a delay for debouncing if needed
  delay(50);
}

This code initializes the DFPlayer Mini and sets up a button input. When the button is pressed, the DFPlayer Mini plays the first audio file on the SD card. The code also includes serial output for debugging purposes.