Arduino Music Player - With Skip, Mute, and Rewind
by 708930 in Circuits > Arduino
536 Views, 3 Favorites, 0 Comments
Arduino Music Player - With Skip, Mute, and Rewind


Hello all! Today I will be explaining to you all how to make your own mini music player with an Arduino, with the added functions of skipping a song, resetting the playlist, rewinding to a previous song, and temporarily muting the buzzer.
Supplies

- 1 breadboard, for this project I used a mini breadboard but a normal one is alright too
- 1 arduino, an arduino uno was used for this project
- 1 I2C LCD
- 1 piezo
- 1 potentiometer
- 4 buttons
- 4 LEDs
- 4 330 ohm resistors
- 4 10k ohm resistors
- 4 male to female wires
- and a couple of wires cut to your preferred lengths
Setting Up the Resistors

This step is extremely straight forward, on the bottom rail, attach your 10k ohm resistors to the ground rail. Try to keep them around 3 to 4 slots apart for a compact but simple design
Attach your 330 ohm resistors to the top ground rail of your breadboard, make sure they’re about one slot to the right of your 10k resistors
First Wiring

For this step, make sure to connect your top and bottom ground and power rails to each other. Connect a few small wires, preferably red, next to the 10k resistors, around 2 slots to the right from each one.
Pick a spot for your piezo and potentiometer as well, and mark those areas using your wires.
Wiring to Arduino

Finally adding in our Arduino! For this step, make sure to connect 5 volts to your power rail and the ground pin to the ground rail. After that’s connected, go in with your wires and connect your pins to the rails you plan to use for your buttons and potentiometer, you don’t need to worry about the LEDs as they’ll get power from the buttons, and your buzzer will get its power from the potentiometer!
For this project, the pins are wired as the following
- pin 3 to the potentiometer
- pin 8 to the skip button
- pin 9 to the mute button
- pin 10 to the rewind button
- pin 11 to the reset button
Adding in the LEDs


Now it’s time to add your lights! These are here to inform you when the buttons are pressed so that you aren’t confused if a signal is being sent out. I personally put these LEDs in diagonally, just to make my design more compact.
As you can see in the image above, the ground leg of LED is in the same rail as the resistor, while the other is in the same rail as the wire to the Arduino. If this does not work for you, try flipping the LED the other way.
Inserting the Buttons

The buttons are what I consider the easiest step out of the entire circuit, simply add them so that the buttons line up with the resistor and power wires from the bottom rails, and the wires from the Arduino on the top. This is also why your LEDs only require connection to ground as when your button is pushed, it’ll send power to the LED.
The Potentiometer and Buzzer

Add in your potentiometer and buzzer so that the middle pin of the potentiometer is connected to the power pin of your buzzer. Make sure that your buzzer and potentiometer both are connected to ground, and that your potentiometer is connected to the Arduino.
LCD Display


This LCD display is already connected to an I2C device. This is where you connect the male side of your male-female wires.
- Connect the GND to your ground rail
- Connect VCC to your power rail
- Connect SDA to A4 on your Arduino
- Connect SCL to A5 on your Arduino
Gather Your Songs
To gather your songs, or to create them, I highly recommend using some software that can convert your music into an XML file.
For this project I used Musescore to gather and recreate my songs so that I have the melody I want to use on my buzzer, and then opened the files in this custom software that converts your file to Arduino code. From this, you can take your melody and note durations and paste them into any of the melodies and durations that are in my code. Remember to also scroll down and change the displayed song title!
Edit and Upload the Code
The code is inserted below, all that’s left is to upload it onto your Arduino! Congrats! You’ve succeeded in creating your own music player!
When it comes to adding your own songs, please note that there is a limit to the amount of music that can be stored as the songs use arrays, which are stored in global variables. For the best results I recommend only playing 30-45 seconds of the song that you want
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int MELODY_PIN = 3;
int BUTTON_MUTE = 9;
int BUTTON_SKIP = 8;
int BUTTON_REWIND = 10;
int BUTTON_RESET = 11;
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int melody1[] = {392, 587, 784, 740, 587, 392, 440, 466, 587, 392, 392, 440, 466, 587, 392, 392, 440, 466, 440, 392, 370, 294, 370, 392, 587, 784, 740, 587, 392, 440, 466, 587, 392, 392, 440, 466, 440, 392, 370, 294, 370, 392, 392, 587, 784, 740, 587, 392, 440, 466, 587, 392, 392, 440, 466, 587, 392, 392, 440, 466, 440, 392, 370, 294, 370, 392, 587, 784, 740, 587, 392, 440, 466, 587, 392, 392, 440, 466, 440, 392, 370, 294, 370, 392, 0}; //blackboxwarrior notes
const int melody2[] = {0, 0, 0, 622, 0, 0, 220, 349, 349, 349, 349, 349, 349, 311, 349, 349, 349, 311, 0, 233, 0, 349, 349, 349, 349, 349, 349, 311, 349, 349, 311, 0, 311, 311, 440, 392, 349, 349, 0, 0, 233, 233, 233, 440, 349, 349, 392, 311, 311, 0, 0, 349, 349, 349, 349, 349, 349, 311, 349, 349, 311, 0, 0, 233, 349, 349, 349, 349, 349, 349, 311, 349, 349, 0 }; //call me what you like notes
const int melody3[] = {277, 277, 277, 277, 311, 311, 311, 311, 311, 311, 208, 208, 208, 208, 175, 175, 175, 175, 175, 175, 277, 277, 277, 277, 311, 311, 311, 311, 311, 311, 208, 208, 208, 208, 175, 175, 175, 175, 175, 175, 0, 0, 523, 523, 523, 554, 466, 466, 0, 466, 466, 415, 466, 466, 466, 523, 277, 349, 349, 523, 523, 523, 523, 523, 523, 554, 466, 466, 0, 466, 466, 311, 466, 466, 466, 523, 415, 392, 0, 0}; //viva la vida notes
const int melodyDurations1[] = {125, 125, 125, 125, 250, 125, 125, 250, 250, 250, 125, 125, 250, 250, 250, 125, 125, 125, 125, 125, 125, 250, 250, 125, 125, 125, 125, 250, 125, 125, 250, 250, 250, 125, 125, 125, 125, 125, 125, 250, 250, 1000, 125, 125, 125, 125, 250, 125, 125, 250, 250, 250, 125, 125, 250, 250, 250, 125, 125, 125, 125, 125, 125, 250, 250, 125, 125, 125, 125, 250, 125, 125, 250, 250, 250, 125, 125, 125, 125, 125, 125, 250, 250, 1000, 0}; //blackboxwarrior durations
const int melodyDurations2[] = {500, 500, 500, 500, 1000, 750, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 750, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 750, 250, 500, 500, 250, 250, 1000, 1000, 250, 250, 250, 250, 500, 250, 500, 500, 250, 500, 500, 1000, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 500, 750, 250, 250, 250, 250, 250, 250, 250, 250, 250, 500, 0}; //call me what you like durations
const int melodyDurations3[] = {500, 500, 500, 250, 250, 250, 500, 250, 500, 500, 500, 500, 500, 250, 250, 250, 500, 250, 500, 500, 500, 500, 500, 250, 250, 250, 500, 250, 500, 500, 500, 500, 500, 250, 250, 250, 500, 250, 500, 500, 250, 500, 250, 500, 500, 250, 250, 1000, 250, 250, 250, 250, 500, 250, 250, 500, 250, 250, 250, 250, 250, 250, 250, 250, 500, 250, 250, 1000, 250, 250, 250, 250, 500, 500, 500, 250, 250, 250, 250, 0}; //viva la vida durations
int currentTrack = 1; // initial track number
int mute=1;
void setup() {
pinMode(BUTTON_MUTE, INPUT);
pinMode(BUTTON_SKIP, INPUT);
pinMode(BUTTON_REWIND, INPUT);
pinMode(BUTTON_RESET, INPUT);
lcd.init(); //initialize the lcd
lcd.backlight(); //open the backlight
pinMode(MELODY_PIN, OUTPUT);
}
void loop(){
if (currentTrack==0){
currentTrack=3;}
if (currentTrack==1){
songOneTime();}
if (currentTrack==2){
songTwoTime();}
if (currentTrack==3){
songThreeTime();}
if (currentTrack==4){
currentTrack=1;}
}
void buttoncheck(){
//Mute button
if(digitalRead(BUTTON_MUTE)==HIGH){
noTone(MELODY_PIN);
lcd.setCursor(0, 1);
lcd.print("Status: Muted ");}
else{
mute=0;
lcd.setCursor(0, 1);
lcd.print("Status: Playing");}
updateLCD();
//Skip button
if(digitalRead(BUTTON_SKIP)==HIGH)
currentTrack=currentTrack+1;
if(currentTrack>3)
currentTrack=1;
updateLCD();
//Rewind button
if(digitalRead(BUTTON_REWIND)==HIGH)
currentTrack=currentTrack-1;
if(currentTrack<0)
currentTrack=3;
updateLCD();
//Reset button
if(digitalRead(BUTTON_RESET)==HIGH)
currentTrack=1;
updateLCD();
}
void updateLCD() {
lcd.setCursor(0, 0);
String songName;
if(currentTrack==1){
songName = "BlackBoxWarrior ";}
else if(currentTrack==2)
songName = "Call Me What You Like ";
else if(currentTrack==3)
songName = "Viva La Vida ";
lcd.setCursor(0, 0);
lcd.print(songName);
}
void songOneTime(){
for (int thisNote = 0; thisNote < sizeof(melody1) / sizeof(int); thisNote++)
{
tone(3, melody1[thisNote]);
buttoncheck();
delay(melodyDurations1[thisNote] * .3);
noTone(MELODY_PIN);
if (currentTrack!=1){
break;
}
}
if (currentTrack==1){
currentTrack=2;}
}
void songTwoTime(){
for (int thisNote = 0; thisNote < sizeof(melody2) / sizeof(int); thisNote++)
{
tone(3, melody2[thisNote]);
buttoncheck();
delay(melodyDurations2[thisNote] * .4);
noTone(MELODY_PIN);
if (currentTrack!=2){
break;
}
}
if (currentTrack==2){
currentTrack=3;}
}
void songThreeTime(){
for (int thisNote = 0; thisNote < sizeof(melody3) / sizeof(int); thisNote++)
{
tone(3, melody3[thisNote]);
buttoncheck();
delay(melodyDurations3[thisNote] * .5);
noTone(MELODY_PIN);
if (currentTrack!=3){
break;
}
}
if (currentTrack==3){
currentTrack=1;}
}