#include <SD.h>
#include <TMRpcm.h>
#include <SPI.h>
#define SD_ChipSelectPin 10 // CS pin for the SD card
#define SpeakerPin 9 // Pin for the speaker (use pin 9 on the Arduino Uno)
TMRpcm audioPlayer; // Create an object for the speaker control library
void setup() {
// Start the serial communication for debugging purposes
Serial.begin(9600);
// Check if the SD card is present and initialized
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD card initialization failed!");
return; // Stop if it's not initialized
}
audioPlayer.speakerPin = SpeakerPin; // Define the speaker pin
audioPlayer.setVolume(7); // Set the volume (0 to 7)
audioPlayer.quality(1); // Set audio quality (0 for low, 1 for high)
Serial.println("SD card initialized.");
}
void loop() {
Serial.println("Playing audio...");
audioPlayer.play("1.wav"); // Play the audio file named "1.wav" from the SD card
delay(3000); // Delay to allow the audio to play
audioPlayer.disable(); // Disable the audio player
delay(2000); // Delay before the next loop iteration
}