Trouble using a SD card

I am working on a project where I am attempting to use a SD card to play an audio file through speakers. The trigger for this is a magnetic door alert. I also have an LED wired to flash.

The general wiring is that the MOSI, MISO, CK, Ground and 5V ports are connected from the SD Card reader to the appropriate pins of the arduino. The speaker is wired through a MOSFET to ground and the OUTPUT pin (9). Both the SD Card reader and the speaker are connected to the 5V pin on the arduino through the breadboard.

The LED's are connected to the arduino through pin 2 and are connected to ground.

When I separate the sensors, the LED's flash as programmed, the speaker clicks indicating that it is receiving some sort of impulse, and the serial monitor is reading "SD Fail"

I am new to this and am completely lost. Any insight would be helpful.

code-

#include <SD.h>
#include <TMRpcm.h>
#include <SPI.h>

#define SDOUT 11 //MOSI
#define SDIN 12 //MISO
#define SDCLK 13 //SCK
#define SDSLAVE 10 //SS

#define LEDOUT 7 //LED OUPUT

#define SPEAKEROUT 9 //Speaker OUTPUT

#define SWITCHPIN 2 //Switch input

TMRpcm tmrpcm;

void setup(){
  pinMode(SDCLK, OUTPUT);
  pinMode(SDOUT, OUTPUT);
  pinMode(SDSLAVE, OUTPUT);
  pinMode(SDIN, INPUT);
  pinMode(LEDOUT, OUTPUT);
  pinMode(SPEAKEROUT, OUTPUT);
  pinMode(SWITCHPIN, INPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
if(digitalRead(SWITCHPIN) == LOW){
  digitalWrite(LEDOUT, LOW);
}
else{
  {
    digitalWrite(LEDOUT, HIGH);
    delay(1000);
    digitalWrite(LEDOUT, LOW);

   tmrpcm.speakerPin = 9;
   Serial.begin(9600);
  if(!SD.begin(SPEAKEROUT));
  {
    Serial.println("SD FAIL");
    return;
  }
  tmrpcm.setVolume(50);
  tmrpcm.play("lasttime.wav");
  }
  }
}

Change SD.begin(SPEAKEROUT) to SD.begin(SDSLAVE) and see if that helps.

Also, one thing to note is that if you are trying to play a high fidelity audio signal such as speech or music, you can't use an Arduino, it's way too slow. For instance, music files have a sample rate of around 44kHz, which is usually too fast for a 16MHz MCU. The best thing to do is to get an MP3 player that can be interfaced with an Arduino. This is a good one. I've used it myself and am quite happy with it's performance.

Now I am not even getting the speaker click.

Can you at least get this tutorial to work?

Initially it was not working, but I double checked the MISO and MOSI, and novice me had them switched. It then did work, and displayed the files on the card. I noticed that the display had all of the files capitalized, so I capitalized them in the code. That did not work.

maxyoder:
Initially it was not working, but I double checked the MISO and MOSI, and novice me had them switched. It then did work, and displayed the files on the card. I noticed that the display had all of the files capitalized, so I capitalized them in the code. That did not work.

Ok, and? Did you get the tutorial to work?

Yes, the tutorial works.

So now take the tutorial code and add the functionality of your project and test it.

I'm not exactly sure how to do that... again. I'm a novice at this. I tried mashing the codes together, but was not getting any farther in the project.