Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

Using DFPlayer Mini with Arduino for Audio Playback

The DFPlayer Mini is a small and affordable MP3 module that can be used with Arduino to play audio files from a microSD card. This module is highly useful for projects that require sound output, such as alarms, voice notifications, or interactive installations. Integrating the DFPlayer Mini with Arduino is straightforward, and this article will guide you through the process, providing a detailed project example.

Project: In this project, we will create an audio playback system using the DFPlayer Mini and Arduino. The system will play specific audio files stored on a microSD card when a button is pressed. This project can be adapted for various applications, such as creating a talking clock, an interactive museum exhibit, or a custom alarm system.

Components List:

  1. Arduino Uno - 1
  2. DFPlayer Mini MP3 Player Module - 1
  3. MicroSD Card (formatted to FAT32) - 1
  4. Push Button - 1
  5. 1kΩ Resistor - 1
  6. Speaker (4Ω or 8Ω) - 1
  7. Breadboard and Jumper Wires

Examples:

  1. Wiring the Components:

    • Connect the VCC pin of the DFPlayer Mini to the 5V pin of the Arduino.
    • Connect the GND pin of the DFPlayer Mini to the GND pin of the Arduino.
    • Connect the RX pin of the DFPlayer Mini to pin 10 of the Arduino (through a 1kΩ resistor).
    • Connect the TX pin of the DFPlayer Mini to pin 11 of the Arduino.
    • Connect the SPK_1 and SPK_2 pins of the DFPlayer Mini to the speaker.
    • Connect one terminal of the push button to pin 2 of the Arduino and the other terminal to GND.
  2. Arduino Code:

    #include <SoftwareSerial.h>
    #include <DFPlayer_Mini_Mp3.h>
    
    // Define the software serial pins
    SoftwareSerial mySerial(10, 11); // RX, TX
    
    // Define the button pin
    const int buttonPin = 2;
    int buttonState = 0;
    
    void setup() {
     // Initialize the serial communication
     Serial.begin(9600);
     mySerial.begin(9600);
    
     // Initialize the DFPlayer Mini
     mp3_set_serial(mySerial); // Set the software serial for DFPlayer Mini
     mp3_set_volume(20); // Set volume (0 to 30)
    
     // Initialize the button pin as input
     pinMode(buttonPin, INPUT);
    }
    
    void loop() {
     // Read the state of the button
     buttonState = digitalRead(buttonPin);
    
     // Check if the button is pressed
     if (buttonState == HIGH) {
       // Play the first audio file on the microSD card
       mp3_play(1);
       delay(1000); // Debounce delay
     }
    }

    Explanation:

    • #include <SoftwareSerial.h>: Includes the SoftwareSerial library to create a serial communication on digital pins.
    • #include <DFPlayer_Mini_Mp3.h>: Includes the DFPlayer Mini library for controlling the module.
    • SoftwareSerial mySerial(10, 11);: Defines the software serial communication on pins 10 (RX) and 11 (TX).
    • const int buttonPin = 2;: Defines the pin connected to the button.
    • void setup(): Initializes serial communication, sets up the DFPlayer Mini, and configures the button pin as input.
    • void loop(): Continuously checks the button state and plays the first audio file when the button is pressed.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.