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");
}
}
}