DFRobot DFPlayer Mini suddenly stops

Mod edit:
The earlier topic the OP is referring to is this one:

Hi everyone:

My earlier post got kind of out of hand, and branched out into too many paths (sorry). I am posting a new post which specifically addresses my main issue. The earlier post is obsolete.

This project is basically a skeleton that (when an IR Remote is pressed) turns his head, says an MP3 file, and turns his head back. The current version of my sketch is attached. It works perfectly (no complier errors); when button 1 is pressed, the servo turns, and the MP3 plays, and the servo turns back. This happens every time I try it (which is good), until all of a sudden, when button 1 is pressed, the servo turns, and the MP3 only plays and buzzes for a second. I thought I had this fixed, but it still fails once in a while. It will work perfectly maybe a dozen times, and then stop. When it fails, the IR receiver still lights, and the blue light on the MP3 player lights, but the MP3 player just gives a one second buzz and stops. The only way to fix this is to re-load the sketch. The wiring has not changed, the code has not changed. and the board was not moved.
I am using:
Arduino Uno R3
DFRobot DFPlayer Mini
Infrared IR Wireless Remote Control Module HX1838 with a 38 KHZ infrared receiving module
Hitec HS425BB servo

Here is the wiring:

and here is the code:

#include <SoftwareSerial.h>  //Allows us to assign different pins for serial use
#include <DFRobotDFPlayerMini.h>
#include <IRremote.h>
#include <Servo.h>

//THIS WORKS - EACH BUTTON PRESS PLAYS TRACK FOR THAT BUTTON
int rxPin = 3;
int txPin = 2;                          //Sets up the send/receive from the Mp3 player
int track = 0001;                       //This is the track number on the micro SD card
SoftwareSerial fxSerial(rxPin, txPin);  //calls the Mp3 player fxSerial
DFRobotDFPlayerMini fxPlayer;

int remoteStatus = 0;  //This sets the trigger to start the talking as zero (no talking, just shoveling).
int remoteState = 0;   //This is the label of the current remote status (on or off)
int IRPin = 11;        //for the ir remote

Servo HeadTurnServo;
int servoHeadPin = 12;  //This is the servo that rotates the head. Does this need to be a squiggly pin? NO it does not


void setup() {
  // put your setup code here, to run once:

  HeadTurnServo.attach(servoHeadPin);
  HeadTurnServo.write(90);  //Zeroes the head to straight ahead.


  pinMode(IRPin, INPUT);  //sets the pin from the IR Remote to input
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);    // Tells Arduino what the Mp3 pins are doing
  fxSerial.begin(9600);      //Sets up the serial function for the Mp3 player
  fxPlayer.begin(fxSerial);  //this tells Arduino that the serial path for the Mp3 player is fxSerial (the name of the MP3 player)
  Serial.begin(9600);        // Do I need this?
  fxPlayer.volume(20);       // Volume can be 10 to 30).  Set this to 20 to use less power

  Serial.println("Enabling IRin");               //for the IR remote
  IrReceiver.begin(IRPin, ENABLE_LED_FEEDBACK);  //for the IR remote
  Serial.println("Enabled IRin");                //for the IR remote
  delay(1000);                                   //Gives things a chance to stabilize
}

void loop() {
  // put your main code here, to run repeatedly:


  if (IrReceiver.decode()) {                                      //TRUE if an IR button was pressed, FALSE if not //for the IR remote
    Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX); /*prints the decoded raw IR data to the serial monitor in hexadecimal format. The decodedRawData field holds the raw, unprocessed IR signal. */
    if (IrReceiver.decodedIRData.decodedRawData == 0xBA45FF00) {  //add the next rows to try other buttons
      Serial.println("Button 1 was pressed");

      HeadTurnServo.write(170);  //turns the head to the right

      fxPlayer.play(1);                                             // plays message 1 because button 1 was pressed
      delay(10000);                                                 //gives the head a short pause before turning back.
      HeadTurnServo.write(90);                                      //turns the head back to straight ahead
    }                                                               //end of IF statement
                                                                    //
    if (IrReceiver.decode()) {                                      //TRUE if an IR button was pressed, FALSE if not //for the IR remote
      if (IrReceiver.decodedIRData.decodedRawData == 0xB946FF00) {  //add the next rows to try other buttons
        Serial.println("Button 2 was pressed");
        //fxplayer.play(2)// plays message 2 because button 2 was pressed
      }  //end of IF statement
    }
    //fxPlayer.play(2);// Plays track 2
    //delay(10000); //this plays track  for 10 seconds.  The speech must be less than 10 seconds long -Does this need to be in the loop?

    IrReceiver.resume(); /*prepares the IR receiver to start listening for the next IR signal. It essentially tells the IR receiver to reset its internal state and prepare for a new incoming signal.*/
  }
}  //End  of void loop

These facts may be irrelevant but I include in case they are important.
When the code uploads, the speaker buzzes for a brief spurt.
The servo is constantly whirring/clicking.

Thanks.

If forum members are thinking about helping you, how do they know you won't suddenly decide that this post is also obsolete and their time has been wasted?

1 Like

Do not cross post.

1 Like

You haven't followed my advice from the earlier, 'obsolete' post. The return path for the motor current is still routed through the breadboard, which isn't designed to deal with large currents.

Why are you using a breadboard anyway? I see at least 2 components (the player and the IR receiver), that could be plugged into it but for some reason are not, making the breadboard pointless.

1 Like

For the historians... one prolific ManuFacturer... of dead ends.

All regarding same subject.

1 Like

Did you check the IR transmitter battery level?

Does DFPlayerMini have errors?

if (myDFPlayer.available()) {
    printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
  }

That is a strong indicator that some part of your code is walking on memory. Very difficult to debug, but there are techniques that assist.

I will try to address each comment:
I said the previous post is obsolete because I received feedback that it was too all-over-place (I agree). I revised my question to be more concise, and wanted folks to know that they need not wade through the poor earlier post.

By cross post, I assume you meant to post in more than one topic? I was told (again, I agree) that my earlier post was not headed correctly, so I tried to fix that by posting a new post.

As for routing the servo ground through the breadboard, I guess I misunderstood. I was using the breadboard as the common ground for all devices. Should I not use the breadboard for that? I got that idea from watching tutorials.

I do take all replies to heart, and try to correct or change my posts to comply.

I will try the suggestion about the DFPlayerMini have errors. I had not thought of that.

I believe the IR transmitter battery is good. It is brand new, and every time I press it, the receiver lights up.

I do appreciate all the replies and do not want to waste anyone's time. I will get better at posting as the forum wishes.

To clarify, both the IR receiver and the Mini player are plugged into the breadboard. When I tried to show the actual breadboard connections I was told it was too confusing and folks could not determine how the components were wired, so I drew a schematic type sketch.

Hi @hauntp ,

I do not know if this is causing the problems but you are calling

if (IrReceiver.decode())

inside another if (IrReceiver.decode()) clause.

I suggest to remove this second function call. Check "IrReceiver.decodedIRData.decodedRawData" whether it's button 1 or 2 only.

Good luck!
ec2021

Thanks! I will try that and get back to the forum with the results.

Thanks again.

If you want to avoid confusing, draw an actual schematic! Hand-drawn is fine, if drawn neatly.

Yes, you should. But you don't want high currents like the motor current to go through the breadboard, so route that back to the power supply ground directly with a separate ground wire. Don't forget that a high current flows from the power supply +V to the motor, and that same current has to flow back to the power supply ground. You don't want that going through the breadboard in either direction.

That points to a servo power problem.
The servo and DFPlayer could draw close to 2Amp peak.
Tell us more about that 5volt supply.
How is the Uno powered.
Leo..

Yet another thread on the same project!

So my carefully prepared questions in #11 of your ‘obsolete post’ was wasting my time?

@hauntp ,
Please don't keep starting new topics on the same subject. Usually I merge them but in this case I've put a link at the top of this one back to the old one.

By creating new topics you are just wasting the time of the people trying to help you, which is why it's against the forum rules, you are also discouraging people from helping you.

Thank you.

Hi everyone:

I have been going through all the suggestions I received. Thank you all for the input. I now have a working IR remote and DF player mini. Apparently, the problem was either the breadboard or loose wires (as was suggested). I used a new breadboard and rewired the project with different wires. The IR remote and DF Mini player have now worked repeatedly for two days.

Thank you PaulRB for your suggestions on the servo ground wire. I now have a dedicated ground wire from the servo back to its power supply. The servo is powered by a 5 V 1 amp wall power supply. I checked, and it is putting out 5 volts. It has a Current Draw at Idle of 8 mA, a No Load Operating Current Draw of 150 mA, and a Stall Current Draw of 800 mA. Unfortunately, the servo is still whirring constantly. The whirring stops if I remove the signal wire from the Arduino Uno, so that is what I am working on now. I am using pin 12 for the signal wire, but numerous sources say I don’t have to use a PWM pin (they will be in short supply on the project). The Uno is currently powered with the USB cable from my desktop (is that a problem?). I tried a 100 uf capacitor across the servo’s power leads, but it made no difference.

I will not start new topics on the same subject. I had received comments that my original post was varying from the subject heading, so I thought a new post was what folks wanted. My apologies.

I was asked to draw an actual schematic, instead of the drawings earlier.

This is my current code which works.

#include <SoftwareSerial.h>  //Allows us to assign different pins for serial use
#include <DFRobotDFPlayerMini.h>
#include <IRremote.h>
#include <Servo.h>
//This sketch is an upgraded sketch that adds the IR Remote triggering the MP3 player
//It tries some ideas form DeBaros video, substituting the IR remote for the PIR
//THIS WORKS - EACH BUTTON PRESS PLAYS TRACK FOR THAT BUTTON
int rxPin = 3;
int txPin = 2;                          //Sets up the send/receive from the Mp3 player
int track = 0001;                       //This is the track number on the micro SD card
SoftwareSerial fxSerial(rxPin, txPin);  //calls the Mp3 player fxSerial
DFRobotDFPlayerMini fxPlayer;

int remoteStatus = 0;  //This sets the trigger to start the talking as zero (no talking, just shoveling).
int remoteState = 0;   //This is the label of the current remote status (on or off)
int IRPin = 11;        //for the ir remote

Servo HeadTurnServo;
int servoHeadPin = 12;  //This is the servo that rotates the head. Does this need to be a squiggly pin? NO it does not


void setup() {
  // put your setup code here, to run once:

  HeadTurnServo.attach(servoHeadPin);
  HeadTurnServo.write(90);  //Zeroes the head to straight ahead.


  pinMode(IRPin, INPUT);  //sets the pin from the IR Remote to input
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);    // Tells Arduino what the Mp3 pins are doing
  fxSerial.begin(9600);      //Sets up the serial function for the Mp3 player
  fxPlayer.begin(fxSerial);  //this tells Arduino that the serial path for the Mp3 player is fxSerial (the name of the MP3 player)
  Serial.begin(9600);        // Do I need this?
  fxPlayer.volume(20);       // Volume can be 10 to 30).  Set this to 20 to use less power

  Serial.println("Enabling IRin");               //for the IR remote
  IrReceiver.begin(IRPin, ENABLE_LED_FEEDBACK);  //for the IR remote
  Serial.println("Enabled IRin");                //for the IR remote
  delay(1000);                                   //Gives things a chance to stabilize
}

void loop() {
 

  if (IrReceiver.decode()) {                                      //TRUE if an IR button was pressed, FALSE if not //for the IR remote
    Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX); /*prints the decoded raw IR data to the serial monitor in hexadecimal format. The decodedRawData field holds the raw, unprocessed IR signal. */
    if (IrReceiver.decodedIRData.decodedRawData == 0xBA45FF00) {  //add the next rows to try other buttons
      Serial.println("Button 1 was pressed");

      HeadTurnServo.write(170);  //turns the head to the right

if (fxPlayer.available()) {
    //printDetail(fxPlayer.readType(), fxPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
  }


      fxPlayer.play(1);                                             // plays message 1 because button 1 was pressed
      delay(10000);                                                 //gives the head a short pause before turning back.
      HeadTurnServo.write(90);                                      //turns the head back to straight ahead
    }                                                               //end of IF statement
                                                                    //
    if (IrReceiver.decode()) {                                      //TRUE if an IR button was pressed, FALSE if not //for the IR remote
      if (IrReceiver.decodedIRData.decodedRawData == 0xB946FF00) {  //add the next rows to try other buttons
        Serial.println("Button 2 was pressed");
        //fxplayer.play(2)// plays message 2 because button 2 was pressed
      }  //end of IF statement
    }
    //fxPlayer.play(2);// Plays track 2
    //delay(10000); //this plays track  for 10 seconds.  The speech must be less than 10 seconds long -Does this need to be in the loop?

    IrReceiver.resume(); /*prepares the IR receiver to start listening for the next IR signal. It essentially tells the IR receiver to reset its internal state and prepare for a new incoming signal.*/
  }
}  //End  of void loop

If anyone has any ideas on the whirring servo, please let me know.
I think I have addressed all concerns. Believe me, the last thing I want to do is waste the forum's time.

Thank you.

This isn't the problem right now, but don't do this.

When you put a leading zero on a number like that, C takes it to mean that the number is in Octal (base 8). With the value "0001", this doesn't make any difference, but if you put, for example, "0013" that would mean 11 in decimal, not 13. How confused would you have been when the player insists on playing track 11 when you wanted track 13?

It's possible that one of those other libraries is interfering with the Servo library because they are both trying to use the same internal hardware timer on the Uno. This might cause the signal going to the servo to jitter, causing it to whirr.

EDIT: look at this:

Thanks PaulRB. Thanks for catching the 0001 naming. Man, that would have been a head scratcher for me when it asked for track 11. You know, I originally had 001 as the file name, but I saw a tutorial somewhere that said I must use 0001. I will change it back to 001.

As for the servo info you sent, me, I will research it and it will hopefully lead to a solution for me.

Take care.