Incorporating sounds or music into our project will reliably increase its attractiveness and make it more visually appealing. If your Arduino has many pins to spare, you can easily incorporate sound effects into your project by using an extra SD card module and a standard speaker. This article will show how easy it is to play music or add sound effects using your Arduino Board. The Arduino community is credited for developing specific libraries that streamline the construction of this project. In this configuration, we have employed IC LM386 for amplification as well as for reducing noise.
Hardware Required:
- Arduino UNO
- SD Card Reader module
- SD card
- LM386 Audio Amplifier
- 10uf Capacitor (2 Nos)
- 100uf Capacitor (2 Nos)
- 1K,10K Resistor
- Push buttons (2 Nos)
- Breadboard
- Connecting Wires
Getting ready with your WAV audio files:
To play sounds from an SD Card using Arduino, the audio files need to be in .wav format because the Arduino Board is only capable of playing audio in wav format. Numerous mp3 shields are available for use with an arduino in order to build an mp3 player. You can also use online platforms to convert audio files from your computer to WAV format so you can play mp3 files on Arduino.
To convert an audio file into wav format, adhere to these instructions:
Step 1: Click on “Online Wav Converter” to enter into the website.
Step 2: Arduino is capable of playing a wav file in the specified format. You have the option to adjust the settings afterwards, however, these settings were specifically designed for optimal quality.
Bit Resolution |
8 Bit |
Sampling Rate |
16000 Hz |
Audio Channel |
Mono |
PCM format |
PCM unsigned 8-bit |
Step 3:On the website, you should select “choose file” and pick the file you wish to convert. Next, enter the settings mentioned above. After finishing, it should appear similar to what is shown in the image below.
Step 4: Next, select “Convert File” and your Audio file will be converted to .Wav file format. Once the conversion is finished, it will be downloaded.
Step 5: In the end, format your SD card and save your .wav audio file on it. Make sure to format it before you insert this document. Remember to include the title in your audio recording. Similarly, you can select any of your four audio files and designate them as 1, 2, 3, and 4 (Titles must stay the same). I have converted four songs and saved them as 1.wav, 2.wav, 3.wav, and 4.wav as specified.
Circuit and Hardware:
Circuit Diagram for this Arduino Audio File Player is simple. The complete circuit diagram is shown in the Image below.
Because our audio files are saved on the SD card, we attach an SD card reader module to our Arduino. The Arduino communicates with the SD card via the SPI communication protocol. Hence, the Module is linked to the SPI pins of the Arduino as shown in the above diagram. It is also listed in the table provided.
Arduino |
SD card module |
+5V |
Vcc |
Gnd |
Gnd |
Pin 12 |
MISO (Master In Slave out) |
Pin 11 |
MOSI (Master Out Slave In) |
Pin 13 |
SCK (Synchronous Clock) |
Pin 4 |
CS (Chip Select) |
Now the Arduino will be able to read the music file from the SD card and play it on the pin number 9. But the audio signals produced by the Arduino on pin 9 will not be audible much. Hence we amplify it by using the LM386 Low voltage Audio amplifier IC.
The amplifier shown above is designed for a Gain of 200 and the Vdd (pin 6) is powered by the 5V pin of the Arduino. If you want to increase/decrease the sound you can increase/decrease the voltage provided to this pin. It can withstand a maximum of 15V. Learn more about this 200 gain amplification configuration for LM386 here.
Additionally, there are two push buttons connected to pins 2 and 3 of the Arduino. These switches are used for moving to the next song track and either starting or stopping the music. I have used these buttons just to demonstrate their capabilities; feel free to start the song whenever you want. View the demo video at the end.
You can choose to build this circuit exclusively on a Breadboard, as shown in the accompanying picture.
Programming your Arduino:
Once the Hardware and SD card are prepared, we are only one more step from being able to play those songs. Put the card into the module for the SD card and then proceed with the steps provided.
Step 1: We will use a library to guarantee the project’s success as mentioned before. Here is the provided link to the library. Choose “Clone or download” and click on it, then opt for downloading as a ZIP file.
Step 2: We will use a library to guarantee the project’s success as mentioned before. Here is the provided link to the library. Choose “Clone or download” and click on it, then opt for downloading as a ZIP file.
Step 3:
By the end of this article, the complete schedule for the arduino music player project will be provided. Simply duplicate and insert it within the Arduino Program. Afterward, choose Upload and get ready to begin listening to your audio files.
The comments in the program are helpful in aiding comprehension. Nevertheless, the TMRpcm library’s capability has also been outlined in the next section.
Playing an audio file:
You can play any audio that is stored in Wav format inside the SD card module by using the line below.
music.play(“3.wav”);
//object name.play (“FileName.wav”);
You can use this line at places where you want to trigger the Audio
Pause an audio File:
To pause an Audio file, you can simply call the line below.
music.pause();
//objectname.pause();
Forwarding/Rewinding an Audio:
There are not direct ways to forward or rewind an Audio file, but you can use the line below to play a song at a particular time. This can be used to forward/rewind with some additional programming.
music.play(“2.wav”,33); //Plays the song from 33rd second
//objectname.play(“Filename.wav”,time in second);
Setting the quality of the audio:
The library gives us two qualities to play the music, one is to play as normal mode the other to play with 2X oversampling.
music.quality(0); //Normal Mode
music.quality(1); //2X over sampling mode
Setting the Volume of the audio:
Certainly, you have the ability to adjust the audio volume using software. Just use the line below to easily adjust the volume. Increased music levels can impact audio quality, so it is recommended to utilize hardware control when available.
music.setVolume(5); //Plays the song at volume 5
//objectname.setVolume(Volume level);
Working of this Arduino Music Player:
After coding your Arduino, simply push the button connected to pin 2 in order to hear the first song (called 1.wav) on your Arduino board. Now, you can choose to press the button again to switch to the next track, scheduled to play as 2.wav. All four songs can be accessed in a similar manner.
Pushing the button linked to pin 3 enables you to control the song’s playback. Push the button once to pause the song and push it again to continue playing from where it stopped. Watch the video for a complete demonstration (or just relax with some music).
I believe that you valued the project. Now it’s time for you to use your imagination and incorporate them into your projects. You can make a talking clock, voice-controlled assistant, chatty robot, vocal warning security system, and various other creations. Please let me know how you plan to use it in the comment section and if you have any problems, feel free to reach out to me on the forums or in the comment section.