Df player mini

Hi,

I am a little familiar with the basics of arduino now.
I am an electrician and electronics was always an interest of me.
So for my project I am trying to add sound.
I followed a video and I got it to work with softwareserial.h.

But I want to play sound when I push a button on input 2.

Problem is I don’t really understand the coding yet.
Can someone help me with the basics here.

If input 2 is high.

I’d like to play sound 01.

How do I do that exactly?

Thanks ahead!

https://forum.arduino.cc/index.php?topic=672620.msg4530157#msg4530157

Follow this link. Download the Mini Fast Library- DO NOT USE the included library for DF Mini- its way too complex for what the Player needs. The link is in that post.

Hi,
Thanks for the link, I downloaded the library but I still don’t really know how to begin with it.

I don’t where to start with the code to say if constinbutton(2) is high playmp3(01) or something like that? I know the forum is about learning but could you give me a quick code so I can get something working? If I have that I can start adding buttons with different sounds but I just don’t know where to start. Even with the more simple library

So luckily for you I built a program for a Halloween Prop of mine that pretty much meets your specs:

#include <SoftwareSerial.h>
#include <DFPlayerMini_Fast.h>
int buttonPin = 3;  // Toggle Switch to trigger prop
int relay1 = 6;  //relay for solenoid
int relay2 = 7;  // relay for LED Bulb
SoftwareSerial mySerial(10, 11); // RX, TX
DFPlayerMini_Fast myMP3;

void setup()
{
  pinMode(3, INPUT_PULLUP);  // pushbutton pin
  pinMode(relay1, OUTPUT);  //relay 1 on solenoid
  pinMode(relay2, OUTPUT); // relay 2 for LED bulb
  Serial.begin(115200);
  mySerial.begin(9600);

  myMP3.begin(mySerial);
  
  Serial.println("Setting volume to max");
  myMP3.volume(30);
  delay(20);
  
  
}

void loop(){
  // put your main code here, to run repeatedly:
if (digitalRead(buttonPin) == LOW){
  delay(100);
 
  myMP3.playNext();  //Play the first mp3
  Serial.println("1st MP3 playing");
  digitalWrite(relay1, HIGH);
  Serial.println("Solenoid Relay ON");
  digitalWrite(relay2, HIGH);
  delay(12000); // Give the DFPlayer some time
}
 else {
  myMP3.sleep();  //turn off MP3 Player
  delay (10);
   Serial.println("MP3 player off");
   digitalWrite(relay1,LOW);
   digitalWrite(relay2,LOW);


  //do nothing
}
}

Now TRY this and the Mini Fast example on your own. Play with it. You can change the button pin to Input 2 (is what I think you are trying to say.) and delete the relays. I would wire your setup first and ensure that it is working with the DF Mini Fast example first then move to this to ensure you are moving step by step. Try to learn slowly- walk first, then you can begin to run.

@ halloweenrick
Thanks for your answer but:-
Remember that code without a schematic is meaningless. For example how are the switches wired up? An experienced person might be able to guess but a beginner will not be able to do that. :confused:

Also the relay? Very few relays can be driven directly from an Arduino pin so are we talking about a relay board with a builtin amplifier or driving the relay with a transistor?

 delay(12000); // Give the DFPlayer some time

Well in fact do nothing for two minutes. So if the file lasts 30 seconds you have a long wait for the next one. In his library is there not a call that sees if the player is busy? You could put that in a loop to wait until the file had finished.

@Eunexeus in the IDE (the program you use to program the Arduino ) under the file menu there is an examples option follow that and select the top option until you come to to fine simple examples to learn from.

hi I tried this but it didn't work? what am I doing wrong?

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

const int buttonPin = 2;
int buttonState = 0;

SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;

void setup()
{
mySoftwareSerial.begin(9600);
Serial.begin(115200);
myDFPlayer.volume(30); //Set volume value (0~30).
pinMode(buttonPin, INPUT_PULLUP);
}

void loop(){
buttonState = digitalRead(buttonPin);

if (buttonState == HIGH) {

} else {
myDFPlayer.playMp3Folder(1);
}
}

Have you wired it up and tried the Mini Fast example from the DF Mini Fast Library in my first reply? In this example you gave, you are using the old library. And yes, your code has errors. Try the Mini Fast example, get that working ( hear that 5 second snippet of music and more) and then we'll touch base again. Please use code tags when you post.

As halloweenrick has mentioned, making sure your Hardware is wired correctly and working as it should is the first thing to do and test it using a known working example such as the Mini Fast example from the DF Mini Fast Library.

If that works but you still have issues with your Sketch, one easy thing to try is to swap the Tx/Rx in your sketch.

i.e. Swap

SoftwareSerial mySoftwareSerial(10, 11); // RX, TX

For ...

SoftwareSerial mySoftwareSerial(11, 10); // RX, TX

There are only the two connections on the Serial Connection, but it's amazing how many times they can be the wrong way around :slight_smile:

Hello,

Few relays can be driven directly from an Arduino pin so are we talking about a relay board with a builtin amplifier or driving the relay with a transistor? Kroger Feed

Getting a little off the original topic- but the prop is just a simple air popup- a halloween mask on an air cylinder with a LED bulb and music that goes off when it is triggered. I used a SEEED relay shield.

The OP asked to see a program using the DF Mini Fast Library in use, so I threw that one out there. Not really intended to be more than that.