Playing Sound Effects

The music player reads mp3 audio files from the microSD module, so of course we can play music, but we can also play sound effects as long as they’re in mp3 format!

This is great for making a custom sound effects board for pranks or whenever you need audio effects. Here are the sample sound effects that we’ll be using in this tutorial:

Download Sample Sound Effects

We’re going to need to access the microSD card. To do this, we’re going to have to move the buttons to make room for our fingers to eject the SD card from the mp3 module. Lets begin by removing all the buttons and placing them back on the breadboard closer to each other and more to the left side of the breadboard. Remember to change the wires that correspond to each button.

NOTE: Its good practice to turn off the music player while circuit changes are being made. This prevents any damages to the circuit in case something is plugged in where it’s not supposed to be.

This is the result of having all the buttons shifted to the left.

Now its time to change the sound files. First, make sure the device is disconnected and powered off. Now remove the microSD card, replace any existing files on the microSD card with the sample sound effect files, eject the microSD card, then reinsert into the mp3 module.

Once the microSD card is inserted, and everything is hooked up correctly, power on the device by connecting the mini USB cable to your computer and test out your sound effects player!

Here is a clip of the working sound effects demo:

Feel free to change the mp3 files on the microSD card so you can play whatever you want!

Adding an Extra Button

Now we’re going to begin diving more into how to customize the actual code and circuit of our music player. For this example, we’ll be adding an extra button to our music player and reprogramming the microcontroller with a new sample program so that all the buttons have different functions.

Download Music Player Arduino Code and Libraries

If you’d like to check out our tutorial on Arduino Coding Basics, click here.

Here are the new functions for our buttons are based on color:

Button Color Function
Red Toggle pause/play
Green Previous track
Yellow Next track
Blue Volume down
White Volume up

The following breadboard wiring diagram shows the connection of a new, fifth button that we’ll be able to add functionality to.

Just as the first four buttons are wired to the microcontroller, our new fifth button needs to be connected to a digital pin too. First, add the new button to the breadboard. Now lets connect the top left leg to pin 3 on our Arduino and the top right leg to the negative rail of the breadboard.

Now that we added the extra button to our circuit, lets upload a new sample program which will assign the new functions to our buttons. Here is the new code:

Download Customized Sample Code

Open it and upload it to the Arduino board. If you need a reminder on how to do this, click here.

The following clip shows the new button functions:

New Code Breakdown

There are a few major differences between the original code and this new one lets see what they are:

Copy to Clipboard

Because we are assigning new functions to each button, each button had its name changed based on what it does. We’ll also notice that a new button was added on pin 3.

Copy to Clipboard

Our toggleButton is going to play audio when we press it, and pause it when we press it again. We create this variable which will to keep track of when to pause and play.

Copy to Clipboard

This is an integer value that holds our volume level from 0 ~ 30. We’re going to use this later in the code to increase or decrease the volume of the played audio files.

Copy to Clipboard

This if condition is for our toggleButton. It checks if the button pin 7 is pressed and then released. Upon releasing it, it checks the ‘checker’ variable we created earlier. Based on the value of ‘checker’, the mp3 file will either start or pause. Then, we see the line “checker = !checker”. This line sets checker to the opposite value of itself. So if “checker” is true, now its set to false. So next time we press and release the toggleButton, its going to read our ‘checker’ variable which is going to be false, then the audio will pause.

Copy to Clipboard

These lines of code are for our volume down button. Once its pressed and released, it will subtract 5 from our ‘myVolume’ integer variable, then the music player’s volume is set to myVolume.

Copy to Clipboard

These lines of code are for our increase volume button. This code does the opposite of the last one. Once its pressed and released, it will add 5 to our ‘myVolume’ integer variable, then the music player’s volume is set to myVolume.

Extra Functions

Here is a list of many different functions you can use in your code to make your music/sound effects player do what you want!

Copy to Clipboard
6) Wiring the Audio Jack Module