Summary of Arduino playing the melody with the Sd card
This project enables an Arduino UNO to play stolen melodies stored on an SD card via serial commands. Users send specific characters (1-6) through the serial monitor to trigger corresponding audio files. The system relies on the TMRpcm library for playback and requires the SD card files to match the code's expected filenames exactly.
Parts used in Arduino Melody Player:
- Arduino UNO
- SD card reader
- Speakerphone
This project is in SD card loaded stolen melody is provided by command sent from the serial monitor.
If you want to add the application var.siz 6-melody melody melody file must be the same as the name of the specified code name.
The components are used:
Arduino UNO
SD card reader
speakerphone
Step 1: Arduino Code
//pin in sd card input module ** MOSI – pin 11 ** MISO – pin 12** CLK – pin 13** CS – pin 4
#include <SD.h>// SD card library
#define Sd_Chip_pin 4
#include <TMRpcm.h>// playing the melody library
char val;TMRpcm tmrpcm; // Create a melody function
void setup()
{ Serial.begin(9600);
tmrpcm.speakerPin = 9; // 9 pin to attach digital speakers + leg
if (!SD.begin(Sd_Chip_pin)) {
// sd module bağlanma return; } }
void loop()
{ if (Serial.available())
{ delay(100);
while(Serial.available() > 0)
{ val = Serial.read();
if (val == ‘1’) { // 1 steal 1.wav file sends data
tmrpcm.play(“1.wav”);
}
else if(val == ‘2’)
{ // 2.wav 2 sends data to steal files
tmrpcm.play(“2.wav”); }
else if(val == ‘3’)
{ // 3.wav sends data to steal files
tmrpcm.play(“3.wav”); }
else if(val == ‘4’)
{ // 4.wav 4 sends data to steal files
tmrpcm.play(“4.wav”); }
else if(val == ‘5’)
{ // 5.wav 5 sends data to steal files
tmrpcm.play(“5.wav”); }
else if(val == ‘6’){ //6.wav 6 sends data to steal files
tmrpcm.play(“6.wav”);
}
}
}
}
For More Details: Arduino playing the melody with the Sd card
- How do I control which melody plays?
Send a number from 1 to 6 via the serial monitor to trigger the corresponding .wav file. - What pin is used for the SD card chip select?
Pin 4 is defined as the Sd_Chip_pin for the SD card module. - Which library is required to play the melodies?
The TMRpcm library must be included to handle the audio playback. - How should the SD card files be named?
The application files must have the same name as the specified code names, such as 1.wav or 2.wav. - What pin connects to the speaker?
The digital speaker positive leg attaches to pin 9. - How does the code detect incoming data?
The loop checks if Serial.available() is true before reading the input value. - What happens if the SD card fails to initialize?
The setup function returns immediately without proceeding if SD.begin fails.

