Project in progress
Newbie Music Player

Newbie Music Player © GPL3+

A simple, yet somehow uncomplete music player from a newcomer.

  • 4,066 views
  • 2 comments
  • 13 respects

Components and supplies

Apps and online services

About this project

Intro

Hello there! My name is Michael and I'm completely new to the world of programming and of course, the world of Arduino.

Project

As you've already seen, I've built a noob-ish music player (currently loaded with only 2 short songs), that is controlled via a Remote Controller. The project, as a circuit is complete, but I'm still trying to figure out how to make the code even better and tweek it a little bit. I'll explain that later.

The only puprose for me making this simple project, is to make myself better at using the Arduino board and code and to say that I've made something that I find a little cool :)

Breaking The Code

The libraries I've included:

#include <IRremote.h>
#include <LiquidCrystal.h> 

Pin Initialization

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int speakerPin = 9; 
int RECV_PIN = 13;

Defining different notes

#define cL 129
#define cLS 139 
#define dL 146 
#define dLS 156 
#define eL 163 
#define fL 173 
#define fLS 185 
#define gL 194 
#define gLS 207 
#define aL 219 
#define aLS 228 
#define bL 232 
#define c 261 
#define cS 277 
#define d 294 
#define dS 311 
#define e 329 
#define f 349 
#define fS 370 
#define g 391 
#define gS 415 
#define a 440 
#define aS 455 
#define b 466 
#define cH 523 
#define cHS 554 
#define dH 587 
#define dHS 622 
#define eH 659 
#define fH 698 
#define fHS 740 
#define gH 784 
#define gHS 830 
#define aH 880 
#define aHS 910 
#define bH 933 

Buzzer Code

void beep (int speakerPin, int freqHz, long timeMs)
{ 
 double timeDelay = (double)(1000000/freqHz); 
 double timeLoop = (double)((timeMs*1000)/(timeDelay*2)); 
 for(int i = 0; i < timeLoop; i++) 
 { 
   digitalWrite(speakerPin, HIGH); 
   delayMicroseconds(timeDelay); 
   digitalWrite(speakerPin, LOW); 
   delayMicroseconds(timeDelay); 
 } 
 delay(20); 
} 

Songs

void Smoke()
{ 
 beep(speakerPin, cH, 500); 
 beep(speakerPin, dHS, 500); 
 beep(speakerPin, fH, 500); 
 delay(250); 
 beep(speakerPin, cH, 500); 
 beep(speakerPin, dHS, 500); 
 beep(speakerPin, fHS, 250); 
 beep(speakerPin, fH, 550); 
 delay(350); 
 beep(speakerPin, cH, 500); 
 beep(speakerPin, dHS, 500); 
 beep(speakerPin, fH, 500); 
 delay(250); 
 beep(speakerPin, dHS, 500); 
 beep(speakerPin, cH, 1500); 
 delay(250); 
} 

void Jingle() 
{ 
 beep(speakerPin, e, 300); 
 beep(speakerPin, e, 300); 
 beep(speakerPin, e, 500); 
 delay(250); 
 beep(speakerPin, e, 300); 
 beep(speakerPin, e, 300); 
 beep(speakerPin, e, 500); 
 delay(350); 
 beep(speakerPin, e, 350); 
 beep(speakerPin, g, 350); 
 beep(speakerPin, c, 350);     
 beep(speakerPin, d, 350); 
 beep(speakerPin, e, 1000); 
 delay(250); 
 beep(speakerPin, f, 350); 
 beep(speakerPin, f, 350); 
 beep(speakerPin, f, 350);     
 beep(speakerPin, f, 300); 
 beep(speakerPin, f, 300); 
 beep(speakerPin, e, 320); 
 beep(speakerPin, e, 320); 
 beep(speakerPin, e, 150); 
 beep(speakerPin, e, 150); 
 beep(speakerPin, e, 150); 
 beep(speakerPin, d, 340); 
 beep(speakerPin, d, 340); 
 beep(speakerPin, e, 440); 
 beep(speakerPin, d, 540); 
 beep(speakerPin, g, 440); 
delay(2000);  
} 

Printing the loading message

void setup()
{ 
 lcd.begin(16,2); 
 irrecv.enableIRIn(); 
 pinMode(speakerPin,OUTPUT); 
 lcd.print("Mike Player"); 
 lcd.setCursor(0,1); 
 lcd.print("Loading."); 
 delay(1000); 
 lcd.print("."); 
 delay(1000); 
 lcd.print("."); 
 delay(1000); 
 lcd.print("."); 
 delay(1000); 
 lcd.print("."); 
 delay(1000); 
 lcd.clear(); 
 lcd.print("Press Play"); 
} 

And the short menu I've made (needs improvement)

void loop()
{ 
 if (irrecv.decode(&results)) 
 { 
   lcd.clear(); 
   lcd.print("Select Song"); 
   lcd.setCursor(0,1); 
   lcd.print("+:Song List"); 
   if (results.value==0xA3C8EDDB) //+ 
   { 
     lcd.clear(); 
     lcd.setCursor(0,0); 
     lcd.print("Smoke On The Water: 1   Jingle Bells: 2"); 
     for (int positionCounter = 0; positionCounter < 64; positionCounter++) 
     { 
       lcd.scrollDisplayLeft(); 
       delay(300); 
     } 
   } 
   if (results.value == 0x9716BE3F) //1 
   { 
     Smoke(); 
   } 
   if (results.value == 0x3D9AE3F7) //2 
   { 
     Jingle(); 
   } 
   irrecv.resume(); 
 } 
} 

Result

Conclusion

I'm really satisfied with what I've done here, although this projects needs a lot of improvements. Criticize freely! Any ideas are really appreciated! Thank you for your time!

Credits

For Smoke On The Water song: YouTube member: AndruxMX

Code

Mike_PlayerArduino
The code for the project
#include <IRremote.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int speakerPin = 9;
int RECV_PIN = 13;
#define cL 129
#define cLS 139
#define dL 146
#define dLS 156
#define eL 163
#define fL 173
#define fLS 185
#define gL 194
#define gLS 207
#define aL 219
#define aLS 228
#define bL 232

#define c 261
#define cS 277
#define d 294
#define dS 311
#define e 329
#define f 349
#define fS 370
#define g 391
#define gS 415
#define a 440
#define aS 455
#define b 466

#define cH 523
#define cHS 554
#define dH 587
#define dHS 622
#define eH 659
#define fH 698
#define fHS 740
#define gH 784
#define gHS 830
#define aH 880
#define aHS 910
#define bH 933

IRrecv irrecv(RECV_PIN);
decode_results results;


void beep (int speakerPin, int freqHz, long timeMs)
{
  
  double timeDelay = (double)(1000000/freqHz);
  double timeLoop = (double)((timeMs*1000)/(timeDelay*2));
  
  for(int i = 0; i < timeLoop; i++)
  {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(timeDelay);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(timeDelay);
  }
  
  delay(20);
}


void Smoke()
{
  beep(speakerPin, cH, 500);
  beep(speakerPin, dHS, 500);
  beep(speakerPin, fH, 500);
  
  delay(250);
  
  beep(speakerPin, cH, 500);
  beep(speakerPin, dHS, 500);
  beep(speakerPin, fHS, 250);
  beep(speakerPin, fH, 550);
  
  delay(350);
  
  beep(speakerPin, cH, 500);
  beep(speakerPin, dHS, 500);
  beep(speakerPin, fH, 500);
  
  delay(250);
  
  beep(speakerPin, dHS, 500);
  beep(speakerPin, cH, 1500);
  
  delay(250);
}


void Jingle()
{
  beep(speakerPin, e, 300);
  beep(speakerPin, e, 300);
  beep(speakerPin, e, 500);
  
  delay(250);
  
  beep(speakerPin, e, 300);
  beep(speakerPin, e, 300);
  beep(speakerPin, e, 500);
  
  delay(350);
  
  beep(speakerPin, e, 350);
  beep(speakerPin, g, 350);
  beep(speakerPin, c, 350);    
  beep(speakerPin, d, 350);
  beep(speakerPin, e, 1000);
  
  delay(250);

  beep(speakerPin, f, 350);
  beep(speakerPin, f, 350);
  beep(speakerPin, f, 350);    
  beep(speakerPin, f, 300);
  beep(speakerPin, f, 300);
  beep(speakerPin, e, 320);
  beep(speakerPin, e, 320);
 

  beep(speakerPin, e, 150);
  beep(speakerPin, e, 150);
  beep(speakerPin, e, 150);
  beep(speakerPin, d, 340);
  beep(speakerPin, d, 340);
  beep(speakerPin, e, 440);
  beep(speakerPin, d, 540);
  beep(speakerPin, g, 440);

 delay(2000); 
}


void setup()
{
  lcd.begin(16,2);
  irrecv.enableIRIn();
  pinMode(speakerPin,OUTPUT);
  lcd.print("Mike Player");
  lcd.setCursor(0,1);
  lcd.print("Loading.");
  delay(1000);
  lcd.print(".");
  delay(1000);
  lcd.print(".");
  delay(1000);
  lcd.print(".");
  delay(1000);
  lcd.print(".");
  delay(1000);
  lcd.clear();
  lcd.print("Press Play");
}

void loop()
{
  if (irrecv.decode(&results))
  {
    lcd.clear();
    lcd.print("Select Song");
    lcd.setCursor(0,1);
    lcd.print("+:Song List");

    if (results.value==0xA3C8EDDB) //+
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Smoke On The Water: 1   Jingle Bells: 2");
      for (int positionCounter = 0; positionCounter < 64; positionCounter++)
      {
        lcd.scrollDisplayLeft();
        delay(300);
      }

      
    }

    if (results.value == 0x9716BE3F) //1
    {
      Smoke();
    }

    if (results.value == 0x3D9AE3F7) //2
    {
      Jingle();
    }

    irrecv.resume();
  }
}

Schematics

Mike_Player_Schematic
Mike%20player

Comments

Similar projects you might like

Play Music With Your Remote

Project tutorial by Simone Adobs

  • 6,966 views
  • 21 comments
  • 27 respects

Wifi Arduino-based Music Player

Project showcase by Vaughn Kottler

  • 3,970 views
  • 2 comments
  • 9 respects

Music Adaptive RGB LED with Arduino and Processing

Project in progress by ounane mohamed elfarouk

  • 2,953 views
  • 8 comments
  • 24 respects

Arduino - Web-Based MP3 Player

Project tutorial by khanhhs

  • 7,747 views
  • 4 comments
  • 27 respects

Control Music Volume and Ledbar Using Slider of 1Sheeld

Project tutorial by ahmed ismail

  • 1,464 views
  • 2 comments
  • 11 respects

Displaying Sensor Values on LCD

by Wimpie van den Berg

  • 42,769 views
  • 4 comments
  • 36 respects
Add projectSign up / Login