Arduino Tutorials – Lesson 33 – DF Player mini using Arduino MEGA2560

Creating DF Player mini test program using Arduino UNO

Required Components

  1. DF Player mini -1 no
  2. Data Cable -1 no
  3. Connecting Wires -1 set
  4. Arduino Uno -1 no
  5. Speaker -1 no
  6. Resistor 1000ohm -1 no

Circuit

Steps

  1. Make sure the components are working properly.
  2. Fix DF Player mini board to the bread board.
  3. Connect Arduino board 5V and GND pin to the DF Player Mini VCC and GND by using wires.
  4. Resistor one end connect to the DF Player Mini RX and the other end connect to the Arduino Uno Board 1 or TX.
  5. The second Resistor one end connect to the DF Player Mini TX and the other end connect to the Arduino Uno Board 0 or RX.
  6. Connect DF Player Mini SPK-1 & SPK-2 pins to the Speker.
  7. Check the Arduino program.
  8. Check the circuit connections.
  9. Run the Arduino program.

Arduino Program

#include "SoftwareSerial.h"
#include <DFMiniMp3.h> 
#define DEBUG 0
class Mp3Notify
{
public:
 static void OnError(uint16_t errorCode)
 {
  Serial.println();
  Serial.print("Com Error ");
  Serial.println(errorCode);
 }
 static void OnPlayFinished(uint16_t track)
 {
  Serial.print("Play finished for #");
  Serial.println(track);
 }
 static void OnCardOnline(uint16_t code)
 {
  Serial.println("Card online ");
 }
 static void OnCardInserted(uint16_t code)
 {
  Serial.println("Card inserted ");
 }
 static void OnCardRemoved(uint16_t code)
 {
  Serial.println("Card removed ");
 }
};
SoftwareSerial secondarySerial(10, 11); 
DFMiniMp3<SoftwareSerial, Mp3Notify> mp3(secondarySerial);
const int LDRpin = A0; 
const int LEDpin = 13; 
int Song=1; 
int ldrStatus;
boolean onStatus = true;
boolean takeLowTime;
long unsigned int timeoutTimer = 0, resetCount = 0;
long unsigned int pause = 2000;

void setup()
{
 Serial.begin(115200);
 if (DEBUG) Serial.println("initializing...");
 pinMode(LDRpin, INPUT); 
 pinMode(LEDpin, OUTPUT);
 mp3.begin();
 mp3.reset();
 uint16_t volume = mp3.getVolume();
 Serial.print("volume ");
 Serial.println(volume);
 mp3.setVolume(20);
 uint16_t count = mp3.getTotalTrackCount();
 Serial.print("files ");
 Serial.println(count);
 uint16_t mode = mp3.getPlaybackMode();
 Serial.print("playback mode ");
 Serial.println(mode);
 if (DEBUG) Serial.println("starting...");
 mp3.playFolderTrack(6, Song);
}

void loop()
{
 ldrStatus = analogRead(LDRpin);
 if (ldrStatus >=300)
  {
    digitalWrite(LEDpin, HIGH);
    mp3.start();
    onStatus = true;
  }
 else 
  {
    digitalWrite(LEDpin, LOW);
    mp3.pause();
  }

 mp3.loop(); 
}

Usage

  1. Fire alarm voice prompts.
  2. Car navigation voice broadcast.
  3. Railway station, bus safety inspection voice prompts.
  4. Electricity, communications, financial business hall voice prompts

Leave a Reply

Your email address will not be published. Required fields are marked *