Project tutorial
Play Music With Your Remote

Play Music With Your Remote © GPL3+

Choose a song with your remote and Arduino will play it. On the monitor will appear the musical note played.

  • 6,292 views
  • 21 comments
  • 26 respects

Components and supplies

Apps and online services

About this project

Hello Hackster community!

I'm Simone Adobs and this is my second project that I have released on this site.

The logic of this project is very simple:

  • Take your Remote Controller and select the melody you want to play;
  • Arduino with the Buzzer will play the melody;
  • On the LCD Screen you can see the musical note played.

Some code explanation:

This is a melody example, all the melody are written in this way:

void melody_example() { 
  lcd.clear(); 
  lcd.setCursor(0,0); 
  lcd.print("Song title"); 
  delay(1000); 
  lcd.clear(); 
  nota_mi(duration,pause); //musical note
  nota_do(duration,pause); //musical note
  lcd.clear(); 
  delay(100); 
  Reset_AVR(); //This command is used to reset the Arduino without push any button
}

To use "Reset_AVR()" command you must put this code to the top of the sketch:

#include <avr/io.h> 
#include <avr/wdt.h> 
#define Reset_AVR() wdt_enable(WDTO_30MS); while(1) {}

This is how Arduino understand which melody must be played:

if (result==12495) {  //12495 is the code that my Remote send when you press button 1
  melody_1(); 
  } 
  else if (result==6375) {  //6375 is the code of button 2
  melody_2(); 
  } 
  else if (result==31365) { //31365 is the code of button 3
  melody_3(); 
  } 
  else if (result==4335) {  //4335 is the code of button 4
  melody_4(); 
  } 
}
Here you can see how the musical note works:
void nota_example(int duration, int pause) { 
  shut();                    //This command call a function that I will explain down
  lcd.setCursor(0, 0); 
  lcd.print("Example    ");  //Print the musical note name
  NewTone(11,262,duration);  //11->Buzzer Pin - 262->note code
  delay(pause);              //wait some milliseconds
} 

Do you want to stop the melody when it is playing?

No problem, thanks to "shut()" function you can stop the melody everytime you want.

This is "shut()" Function:

void shut() { 
  if (irrecv.decode(&results)) {  //Receive the code of the button pressed
    result=results.value, HEX;    //Save the code received
    Serial.println(result); 
    if (result==-23971) {         //-23971 on my Remote represent the shutdown button
      Reset_AVR();                //Reset Arduino
    } 
  } 
  irrecv.resume();                //Allows Arduino to receive a new code from Remote
} 

I hope you will like this project and if it is, try to take a look to my previous project.

Have a nice day..

Simone from Italy <3

Code

Play MelodyC/C++
Copy this code in Arduino IDE
#include <LiquidCrystal.h>
#include <IRremote.h>
#include <NewTone.h>
#include <avr/io.h>
#include <avr/wdt.h>

#define Reset_AVR() wdt_enable(WDTO_30MS); while(1) {} 


#define buzzer 11     

LiquidCrystal lcd(9, 8, 7, 6, 5, 4);

int result;
int RECV_PIN=2;

IRrecv irrecv(RECV_PIN);

decode_results results;
  
void setup() {   
  Serial.begin(9600);               
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("-----Choose-----");
  lcd.setCursor(0,1);
  lcd.print("----A Song!!----");
  pinMode(buzzer, OUTPUT);
  irrecv.enableIRIn();
}  

void loop() {
  if (irrecv.decode(&results)) {
    result=results.value, HEX;
    Serial.println(result);
    if (result==12495) {
      ode();
    }
    else if (result==6375) {
      london();
    }
    else if (result==31365) {
      fur();
    }
    else if (result==4335) {
      pirate();
    }
    irrecv.resume();
  }
  delay(100);
} 

void fur() {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Fur Elise");
  delay(1000);
  lcd.clear();
  nota_mi(150,200);
  nota_rez(150,200);
  nota_mi(150,200);
  nota_rez(150,200);
  nota_mi(150,200);
  nota_si(150,200);
  nota_rez(150,200);
  nota_do(150,200);
  nota_la(450,300);
  nota_do(150,200);
  nota_mi(150,200);
  nota_la(150,200);
  nota_si(450,300);
  nota_mi(150,200);
  nota_solz(150,200);
  nota_si(150,200);
  nota_do(450,300);
  nota_mi(150,200);
  nota_mi(150,200);
  nota_rez(150,200);
  nota_mi(150,200);
  nota_rez(150,200);
  nota_mi(150,200);
  nota_si(150,200);
  nota_rez(150,200);
  nota_do(150,200);
  nota_la(450,300);
  nota_do(150,200);
  nota_mi(150,200);
  nota_la(150,200);
  nota_sol(450,300);
  nota_mi(150,200);
  nota_do(150,200);
  nota_si(150,200);
  nota_la(600,800);
  nota_mi(150,200);
  nota_rez(150,200);
  nota_mi(150,200);
  nota_rez(150,200);
  nota_mi(150,200);
  nota_si(150,200);
  nota_rez(150,200);
  nota_do(150,200);
  nota_la(450,300);
  nota_do(150,200);
  nota_mi(150,200);
  nota_la(150,200);
  nota_si(450,300);
  nota_mi(150,200);
  nota_solz(150,200);
  nota_si(150,200);
  nota_do(450,300);
  lcd.clear();
  delay(100);
  Reset_AVR();
}

void london() {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("London Bridge");
  lcd.setCursor(0,1);
  lcd.print("Is falling down");
  delay(1000);
  lcd.clear();
  nota_sol(450,600);
  nota_la(150,200);
  nota_sol(300,400);
  nota_fa(300,400);
  nota_mi(300,400);
  nota_fa(300,400);
  nota_sol(600,800);
  nota_re(300,400);
  nota_mi(300,400);
  nota_fa(600,800);
  nota_mi(300,400);
  nota_fa(300,400);
  nota_sol(600,800);
  nota_sol(450,600);
  nota_la(150,200);
  nota_sol(300,400);
  nota_fa(300,400);
  nota_mi(300,400);
  nota_fa(300,400);
  nota_sol(600,800);
  nota_re(600,800);
  nota_sol(600,800);
  nota_mi(300,400);
  nota_do(450,600);
  lcd.clear();
  delay(100);
  Reset_AVR();
}

void ode() {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Ode to Joy");
  delay(1000);
  lcd.clear();
  nota_mi(300,400);
  nota_mi(300,400);
  nota_fa(300,400);
  nota_sol(300,400);
  nota_sol(300,400);
  nota_fa(300,400);
  nota_mi(300,400);
  nota_re(300,400);
  nota_do(300,400);
  nota_do(300,400);
  nota_re(300,400);
  nota_mi(300,400);
  nota_mi(450,600);
  nota_re(150,200);
  nota_re(600,800);
  nota_mi(300,400);
  nota_mi(300,400);
  nota_fa(300,400);
  nota_sol(300,400);
  nota_sol(300,400);
  nota_fa(300,400);
  nota_mi(300,400);
  nota_re(300,400);
  nota_do(300,400);
  nota_do(300,400);
  nota_re(300,400);
  nota_mi(300,400);
  nota_re(450,600);
  nota_do(150,200);
  nota_do(600,800);
  nota_re(300,400);
  nota_re(300,400);
  nota_mi(300,400);
  nota_do(300,400);
  nota_re(300,400);
  nota_mi(150,200);
  nota_fa(150,200);
  nota_mi(300,400);
  nota_do(300,400);
  nota_re(300,400);
  nota_mi(150,200);
  nota_fa(150,200);
  nota_mi(300,400);
  nota_re(300,400);
  nota_do(300,400);
  nota_re(300,400);
  nota_sol(600,800);
  nota_mi(300,400);
  nota_mi(300,400);
  nota_fa(300,400);
  nota_sol(300,400);
  nota_sol(300,400);
  nota_fa(300,400);
  nota_mi(300,400);
  nota_re(300,400);
  nota_do(300,400);
  nota_do(300,400);
  nota_re(300,400);
  nota_mi(300,400);
  nota_re(450,600);
  nota_do(150,200);
  nota_do(600,800);
  lcd.clear();
  delay(100);
  Reset_AVR();
}

void pirate() {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("He's a Pirate");
  delay(1000);
  lcd.clear();
  nota_mi(150,200);
  nota_sol(150,200);
  nota_la(300,400);
  nota_la(300,400);
  nota_la(150,200);
  nota_si(150,200);
  nota_do(300,400);
  nota_do(300,400);
  nota_do(150,200);
  nota_re(150,200);
  nota_si(300,400);
  nota_si(300,400);
  nota_la(150,200);
  nota_sol(150,200);
  nota_sol(150,200);
  nota_la(450,600);
  nota_mi(150,200);
  nota_sol(150,200);
  nota_la(300,400);
  nota_la(300,400);
  nota_la(150,200);
  nota_si(150,200);
  nota_do(300,400);
  nota_do(300,400);
  nota_do(150,200);
  nota_re(150,200);
  nota_si(300,400);
  nota_si(300,400);
  nota_la(150,200);
  nota_sol(150,200);
  nota_la(300,400);
  delay(400);
  nota_mi(150,200);
  nota_sol(150,200);
  nota_la(300,400);
  nota_la(300,400);
  nota_la(150,200);
  nota_do(150,200);
  nota_re(300,400);
  nota_re(300,400);
  nota_re(150,200);
  nota_mi(150,200);
  nota_fa(300,400);
  nota_fa(300,400);
  nota_mi(150,200);
  nota_re(150,200);
  nota_mi(150,200);
  nota_la(450,600);
  nota_la(150,200);
  nota_si(150,200);
  nota_do(300,400);
  nota_do(300,400);
  nota_re(300,400);
  nota_mi(150,200);
  nota_la(450,600);
  nota_la(150,200);
  nota_do(150,200);  
  nota_si(300,400);
  nota_si(300,400);
  nota_do(150,200);
  nota_la(150,200);
  nota_si(900,1200);
  nota_si(300,400);
  nota_si(300,400);
  nota_do(150,200);
  nota_la(150,200);
  nota_si(900,1200);
  nota_si(300,400);
  nota_si(300,400);
  nota_la(150,200);
  nota_sol(150,200);
  nota_la(600,800);
  lcd.clear();
  delay(100);
  Reset_AVR();
}

void shut() {
  if (irrecv.decode(&results)) {
    result=results.value, HEX;
    Serial.println(result);
    if (result==-23971) {
      Reset_AVR();
    }
  }
  irrecv.resume();
}

void nota_do(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("Do    ");
  NewTone(11,262,duration); //DO
  delay(pause);
  }

void nota_doz(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("Do #  ");
  NewTone(11,277,duration); //DO
  delay(pause);
  }

void nota_re(int duration, int pause) {
  shut;
  lcd.setCursor(0, 0);
  lcd.print("Re    ");
  NewTone(11,294,duration); //RE
  delay(pause);
  }

void nota_rez(int duration, int pause) {
  shut;
  lcd.setCursor(0, 0);
  lcd.print("Re #  ");
  NewTone(11,311,duration); //RE
  delay(pause);
  }

void nota_mi(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("Mi    ");
  NewTone(11,330,duration); //MI
  delay(pause);
  }

void nota_fa(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("Fa    ");
  NewTone(11,349,duration); //FA
  delay(pause);
  }

void nota_faz(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("Fa #  ");
  NewTone(11,370,duration); //FA
  delay(pause);
  }


void nota_sol(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("Sol   ");
  NewTone(11,392,duration); //SOL
  delay(pause);
  }

void nota_solz(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("Sol # ");
  NewTone(11,415,duration); //SOL
  delay(pause);
  }

void nota_la(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("La    ");
  NewTone(11,440,duration); //LA
  delay(pause);
  } 

void nota_laz(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("La #  ");
  NewTone(11,466,duration); //LA
  delay(pause);
  }

void nota_si(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("Si    ");
  NewTone(11,494,duration); //SI
  delay(pause);
  }

Schematics

Schematics with Fritzing
canzoni_con_tastiera_fQS3978roa.fzz
Schematics with Fritzing
Canzoni con telecomando qzm8kuxled

Comments

Similar projects you might like

Servo Control with TV Remote Control

Project showcase by eldo85

  • 5,591 views
  • 5 comments
  • 17 respects

Newbie Music Player

Project in progress by Michael Marinis

  • 3,502 views
  • 2 comments
  • 12 respects

Arduino: Switching ON/OFF Appliances Using IR Remote

Project showcase by Naman Chauhan

  • 8,508 views
  • 0 comments
  • 117 respects

Turn LEDs On/Off via Remote Control

Project tutorial by ismystore

  • 6,927 views
  • 0 comments
  • 5 respects

The Magnetic Field and RGB Tester

Project tutorial by Kutluhan Aktar

  • 3,530 views
  • 0 comments
  • 14 respects
Add projectSign up / Login