DF player to play sound on button press/position

Hi everyone,
I'm a total Noob at this; beginner doesn't even begin to describe me.
This is my first project & I'm really groping in the dark.

I'm making a Ghostbusters proton pack for my son for Halloween. I've had some help setting the lighting up, but want add a couple of sounds on actions too.
There's two switches; a 'flick' switch for on/off, & a momentary switch for the trigger.
What I'd like is power up/down sounds to run with the power switch position, & a third sound (the proton gun firing) to run from the trigger. This sound should cut when the trigger is released & only play when the pack is powered on.

I have an Uno board, DF Player, & small speaker. I'm fairly sure everything is wired up right.

Is anyone able to help me with straightforward explanations & plain English? Thank you so much :+1::slightly_smiling_face:

The straight forward explanation is:
describe in more detail what you already have

  • does the lighting use a microcontroller too?
  • if there is a lighting microcontroller shall the lighting-microcontrollers code be expanded to control the DF-player?
  • in which near do you want to finish this project this year or next year?

beeing a real newcomer that has zero knowledge about programming and has zero knowledge about electronics finishing this project for halloween 2023 is little bit ambitious.

I did google for
df mini player demo-code
and found this

Do you have you a micro SD card with a mp3 directory in the root?
Do you have your sounds (mp3 files) in files in the mp3 directory?
Are the sound (mp3) files named 0001.mp3, 0002.mp3, 0003.mp3, etc.

What is a "flick switch"? In my 50+ years of electronics that is a new term for me.

If you want a sound to play on power up, put the play in setup() (see example code).

This example will play the sound in file mp3\0003.mp3 at startup and sound mp3\0002.mp3 once each time the button (pin 8) is pressed. Tested on real hardware.

The code makes use of the state change detection method. The button is wired to ground as shown in my state change detection for active low inputs tutorial. Wiring so the switch is active LOW is more accepted practice.

//#include <Arduino.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>

const byte buttonPin = 8;

SoftwareSerial ss(4, 5); // RX, TX
DFRobotDFPlayerMini myDFPlayer;

void setup()
{
   Serial.begin(115200);
   ss.begin(9600);

   pinMode(buttonPin, INPUT_PULLUP);

   Serial.println();
   Serial.println(F("DFRobot DFPlayer Mini play at startup"));

   if (!myDFPlayer.begin(ss))    //Use softwareSerial to communicate with mp3.
   {
      Serial.println(F("Unable to begin:"));
      Serial.println(F("1.Please recheck the connection!"));
      Serial.println(F("2.Please insert the SD card!"));
      while (true)  // wait forever
      {
         delay(0); // Code to compatible with ESP8266 watch dog.
      }
   }
   Serial.println(F("DFPlayer Mini online."));

   myDFPlayer.volume(25);  //Set volume value. From 0 to 30
   myDFPlayer.play(3);  //Play the 0003.mp3
}

void loop()
{
   static bool lastButtonState = HIGH;
   static unsigned long timer = 0;3
   unsigned long interval = 50;
   if (millis() - timer >= interval)
   {
      timer = millis();
      bool buttonState = digitalRead(buttonPin);
      if (buttonState != lastButtonState)
      {
         if (buttonState == LOW)
         {
            myDFPlayer.play(2);  //Play the 0002.mp3
         }
         lastButtonState = buttonState;
      }
   }
}

The ZAPSPLAT site is a great source for free sounds.

If you want a quick solution, you could buy greetings card, recordable chips / speaker pack. Here a link to the type of product on ebay:

you could record the sounds and place the switches presumably with no coding involved. I have not personally tested this product, so I'm not sure how well it works! but this could be an easier way to go

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.