Play soundfiles

I´ve got a project where i want to play three different soundfiles.
It is a gatling laser from Fallout 4
I run it on a UNO

File 1 when a reed switch is on (turns the gatling on, turns on a LED, when i put in a fusion core. Sound will be starup sound)

File 2 when the same switch goes off (Turns the gatling off, turns off LED, when i remove the fusion core, sound will be shutdown sound)

File 3 in a loop as long as a button is pressed (Button starts barrelmotor and blinking leds in barrels, sound will be the gatling firing)

The other things, like LEDs and so on that happens whit the reed switch and with the button and i got that working fine.

const int fcpin = 2;     // the number of the fusioncore (reedswitch) pin
const int trigger = 3;     // the number of the trigger pin

const int boxled =  5;      // the number of the box LED pin
const int barrel1 =  6;      // the number of the bottom barrel pin
const int barrel2 =  7;      // the number of the top barrel pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // set output pins
  pinMode(boxled, OUTPUT);
  pinMode(barrel1, OUTPUT);
  pinMode(barrel2, OUTPUT);
  // set output pins
  pinMode(fcpin, INPUT);
  pinMode(trigger, INPUT);
}


void loop() {
 // read the state of the fusioncore value:
  buttonState = digitalRead(fcpin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(boxled, HIGH);
  } else {
    // turn LED off:
    digitalWrite(boxled, LOW);
    }


   // read the state of the trigger value:
  buttonState = digitalRead(trigger);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(barrel1, HIGH);
    delay(100);               // wait for a second
    digitalWrite(barrel1, LOW);    // turn the LED off by making the voltage LOW
    delay(100); 
  } else {
    // turn LED off:
    digitalWrite(barrel1, LOW);
    }

    // read the state of the trigger value:
  buttonState = digitalRead(trigger);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    delay(100);
    digitalWrite(barrel2, HIGH);
    delay(100);               // wait for a second
    digitalWrite(barrel2, LOW);    // turn the LED off by making the voltage LOW
     
  } else {
    // turn LED off:
    digitalWrite(barrel2, LOW);
    }
  
  }

Get an MP3 player board (search ebay for mp3 player arduino), and look up instructions for using the board you choose to see how to tell it to play the file - the Arduino Uno itself can't do audio, but mp3-player boards are available for less than the price of a cup of coffee.

Thank you!

Would the YX5300 work?

I've ordered the above player and looked into the code to add to my previous code.
I will test it as soon as i can, but inluce what i got below.
If anyone is willing to give feedback i would appreciate it.
Do i need to set pins 8 and 9 as outpup pins too?

#include <SoftwareSerial.h>
#define ARDUINO_RX 8//should connect to TX of the Serial MP3 Player module
#define ARDUINO_TX 9//connect to RX of the module
SoftwareSerial mySerial(ARDUINO_RX, ARDUINO_TX);//init the serial protocol, tell to myserial wich pins are TX and RX
#define NEXT_SONG 0X01 
#define PREV_SONG 0X02 
#define CMD_PLAY_W_INDEX 0X03 //DATA IS REQUIRED (number of song)
#define VOLUME_UP_ONE 0X04
#define VOLUME_DOWN_ONE 0X05
#define CMD_SET_VOLUME 0X06//DATA IS REQUIRED (number of volume from 0 up to 30(0x1E))
#define SET_DAC 0X17
#define CMD_PLAY_WITHVOLUME 0X22 //data is needed  0x7E 06 22 00 xx yy EF;(xx volume)(yy number of song)
#define CMD_SEL_DEV 0X09 //SELECT STORAGE DEVICE, DATA IS REQUIRED
#define DEV_TF 0X02 //HELLO,IM THE DATA REQUIRED
#define SLEEP_MODE_START 0X0A
#define SLEEP_MODE_WAKEUP 0X0B
#define CMD_RESET 0X0C//CHIP RESET
#define CMD_PLAY 0X0D //RESUME PLAYBACK
#define CMD_PAUSE 0X0E //PLAYBACK IS PAUSED
#define CMD_PLAY_WITHFOLDER 0X0F//DATA IS NEEDED, 0x7E 06 0F 00 01 02 EF;(play the song with the directory \01\002xxxxxx.mp3
#define STOP_PLAY 0X16
#define PLAY_FOLDER 0X17// data is needed 0x7E 06 17 00 01 XX EF;(play the 01 folder)(value xx we dont care)
#define SET_CYCLEPLAY 0X19//data is needed 00 start; 01 close
#define SET_DAC 0X17//data is needed 00 start DAC OUTPUT;01 DAC no output

const int fcpin = 2;     // the number of the fusioncore (reedswitch) pin
const int trigger = 3;     // the number of the trigger pin

const int boxled =  5;      // the number of the box LED pin
const int barrel1 =  6;      // the number of the bottom barrel pin
const int barrel2 =  7;      // the number of the top barrel pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // set output pins
  pinMode(boxled, OUTPUT);
  pinMode(barrel1, OUTPUT);
  pinMode(barrel2, OUTPUT);
  // set output pins
  pinMode(fcpin, INPUT);
  pinMode(trigger, INPUT);
}



void loop() {
 // read the state of the fusioncore value:
  buttonState = digitalRead(fcpin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(boxled, HIGH);
CMD_PLAY_WITHFOLDER 0X0F 0x7E 06 0F 00 01 01 EF  //AND PLAY SOUND 001.mp3 in folder 01
  } else {
    // turn LED off:
    digitalWrite(boxled, LOW);
CMD_PLAY_WITHFOLDER 0X0F 0x7E 06 0F 00 02 01 EF  //AND PLAY SOUND 002.mp3 in folder 01

{Serial.begin(9600); //Start our Serial coms for serial monitor in our pc
mySerial.begin(9600); //Start our Serial coms for THE MP3
delay(500); //Wait chip initialization is complete
sendCommand(CMD_SEL_DEV, DEV_TF); //select the TF card  
delay(200);//wait for 200ms
}
}


   // read the state of the trigger value:
  buttonState = digitalRead(trigger);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(barrel1, HIGH);
    delay(100);               // wait for a second
    digitalWrite(barrel1, LOW);    // turn the LED off by making the voltage LOW
    delay(100); 
CMD_PLAY_WITHFOLDER 0X0F 0x7E 06 0F 00 03 01 EF  //AND PLAY SOUND 00.mp3 in folder 01

  } else {
    // turn LED off:
    digitalWrite(barrel1, LOW);
STOP_PLAY 0X16 //AND TURN OFF SOUND
    }

    // read the state of the trigger value:
  buttonState = digitalRead(trigger);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    delay(100);
    digitalWrite(barrel2, HIGH);
    delay(100);               // wait for a second
    digitalWrite(barrel2, LOW);    // turn the LED off by making the voltage LOW
     
  } else {
    // turn LED off:
    digitalWrite(barrel2, LOW);
    }
  
  }

void sendCommand(int8_t command, int16_t dat)
{
 delay(20);
 Send_buf[0] = 0x7e; //starting byte
 Send_buf[1] = 0xff; //version
 Send_buf[2] = 0x06; //the number of bytes of the command without starting byte and ending byte
 Send_buf[3] = command; //
 Send_buf[4] = 0x00;//0x00 = no feedback, 0x01 = feedback
 Send_buf[5] = (int8_t)(dat >> 8);//datah
 Send_buf[6] = (int8_t)(dat); //datal
 Send_buf[7] = 0xef; //ending byte
 for(uint8_t i=0; i<8; i++)//
 {
   mySerial.write(Send_buf[i]) ;//send bit to serial mp3
   Serial.print(Send_buf[i],HEX);//send bit to serial monitor in pc
 }
 Serial.println();
}

Have a google for “Arduino Diesel engine” or “ Arduino RC engine sound “ - there is some great software out there using sampled sounds and still running on an Arduino .
You should be able to change the sound .

So i got the player and have tested it.
Got it working and the code seems to work when i use it separately.
But when i want to add it to my other code it gives me some error messages.
Expected ) before numerical constant

#include <SoftwareSerial.h>

#define ARDUINO_RX 8//should connect to TX of the Serial MP3 Player module
#define ARDUINO_TX 9//connect to RX of the module
SoftwareSerial mySerial(ARDUINO_RX, ARDUINO_TX);//init the serial protocol, tell to myserial wich pins are TX and RX

////////////////////////////////////////////////////////////////////////////////////
//all the commands needed in the datasheet(http://geekmatic.in.ua/pdf/Catalex_MP3_board.pdf)
static int8_t Send_buf[8] = {0} ;//The MP3 player undestands orders in a 8 int string
                                 //0X7E FF 06 command 00 00 00 EF;(if command =01 next song order) 
#define NEXT_SONG 0X01 
#define PREV_SONG 0X02 

#define CMD_PLAY_W_INDEX 0X03 //DATA IS REQUIRED (number of song)

#define VOLUME_UP_ONE 0X04
#define VOLUME_DOWN_ONE 0X05
#define CMD_SET_VOLUME 0X06//DATA IS REQUIRED (number of volume from 0 up to 30(0x1E))
#define SET_DAC 0X17
#define CMD_PLAY_WITHVOLUME 0X22 //data is needed  0x7E 06 22 00 xx yy EF;(xx volume)(yy number of song)

#define CMD_SEL_DEV 0X09 //SELECT STORAGE DEVICE, DATA IS REQUIRED
                #define DEV_TF 0X02 //HELLO,IM THE DATA REQUIRED
                
#define SLEEP_MODE_START 0X0A
#define SLEEP_MODE_WAKEUP 0X0B

#define CMD_RESET 0X0C//CHIP RESET
#define CMD_PLAY 0X0D //RESUME PLAYBACK
#define CMD_PAUSE 0X0E //PLAYBACK IS PAUSED

#define CMD_PLAY_WITHFOLDER 0X0F//DATA IS NEEDED, 0x7E 06 0F 00 01 02 EF;(play the song with the directory \01\002xxxxxx.mp3

#define STOP_PLAY 0X16

#define PLAY_FOLDER 0X17// data is needed 0x7E 06 17 00 01 XX EF;(play the 01 folder)(value xx we dont care)

#define SET_CYCLEPLAY 0X19//data is needed 00 start; 01 close

#define SET_DAC 0X17//data is needed 00 start DAC OUTPUT;01 DAC no output
////////////////////////////////////////////////////////////////////////////////////
// constants won't change. They're used here to set pin numbers:
const int fcpin = 2;     // the number of the fusioncore (reedswitch) pin
const int trigger = 3;     // the number of the trigger pin

const int boxled =  5;      // the number of the box LED pin
const int barrel1 =  6;      // the number of the bottom barrel pin
const int barrel2 =  7;      // the number of the top barrel pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status


void setup()
{
  Serial.begin(9600);//Start our Serial coms for serial monitor in our pc
mySerial.begin(9600);//Start our Serial coms for THE MP3
delay(500);//Wait chip initialization is complete
   sendCommand(CMD_SEL_DEV, DEV_TF);//select the TF card  
delay(200);//wait for 200ms
// set output pins
  pinMode(boxled, OUTPUT);
  pinMode(barrel1, OUTPUT);
  pinMode(barrel2, OUTPUT);
  // set output pins
  pinMode(fcpin, INPUT);
  pinMode(trigger, INPUT);

}
void loop()
{// read the state of the fusioncore value:
  buttonState = digitalRead(fcpin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(boxled, HIGH);
sendCommand(CMD_PLAY_WITHVOLUME, 0x1E01);//play the first song with volume 15 class
delay(1000000);//the programm will send the play option each 100 seconds to the catalex chip
} else {{
    // turn LED off:
    digitalWrite(boxled, LOW);
    sendCommand(CMD_PLAY_WITHVOLUME, 0x1E02);//play the first song with volume 15 class
delay(1000000);//the programm will send the play option each 100 seconds to the catalex chip
}
}

buttonState = digitalRead(trigger);
if (buttonState == HIGH) 
{sendCommand(CMD_PLAY_WITHVOLUME, 0x1E03);//play the first song with volume 15 class
delay(1000000);//the programm will send the play option each 100 seconds to the catalex chip
} else {
  sendCommand(STOP_PLAY 0X16)
}

// read the state of the trigger value:
  buttonState = digitalRead(trigger);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(barrel1, HIGH);
    delay(100);               // wait for a second
    digitalWrite(barrel1, LOW);    // turn the LED off by making the voltage LOW
    delay(100); 
  } else {
    // turn LED off:
    digitalWrite(barrel1, LOW);
    }

    // read the state of the trigger value:
  buttonState = digitalRead(trigger);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    delay(100);
    digitalWrite(barrel2, HIGH);
    delay(100);               // wait for a second
    digitalWrite(barrel2, LOW);    // turn the LED off by making the voltage LOW
     
  } else {
    // turn LED off:
    digitalWrite(barrel2, LOW);
    }
  
  }



void sendCommand(int8_t command, int16_t dat)
{
 delay(20);
 Send_buf[0] = 0x7e; //starting byte
 Send_buf[1] = 0xff; //version
 Send_buf[2] = 0x06; //the number of bytes of the command without starting byte and ending byte
 Send_buf[3] = command; //
 Send_buf[4] = 0x00;//0x00 = no feedback, 0x01 = feedback
 Send_buf[5] = (int8_t)(dat >> 8);//datah
 Send_buf[6] = (int8_t)(dat); //datal
 Send_buf[7] = 0xef; //ending byte
 for(uint8_t i=0; i<8; i++)//
 {
   mySerial.write(Send_buf[i]) ;//send bit to serial mp3
   Serial.print(Send_buf[i],HEX);//send bit to serial monitor in pc
 }
 Serial.println();
}