Hackster is hosting Hackster Holidays, Ep. 5: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 5 on Friday!
xpaul
Published

Arduino Remote-Controlled Songs

IR receiver and a buzzer.

IntermediateProtip3,911
Arduino Remote-Controlled Songs

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Buzzer
Buzzer
×1
IR receiver (generic)
×1
LED (generic)
LED (generic)
×2
Resistor 220 ohm
Resistor 220 ohm
×2
Through Hole Resistor, 680 kohm
Through Hole Resistor, 680 kohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Alphanumeric LCD, 16 x 2
Alphanumeric LCD, 16 x 2
×1

Story

Read more

Schematics

Circuit

WARNING
USE 3.3 V NOT 5V FOR IR RECEIVER

ATTENZIONE
UTILIZZARE 3.3V E NON 5V PER IL RICEVITORE IR

Code

Code

Arduino
#include "IRremote.h"
#include <LiquidCrystal.h>
#define LED_ON 10
#define LED_OFF 8
int receiver = 13; 
int pointer;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
IRrecv irrecv(receiver);     
decode_results results; 
String waiting[] = {
"1-Pirati Caraibi",
"2-Super Mario",
"3-Harry Potter",
};
//--------------------------------------------------------------------------------    
//PIRATI DEI CARAIBI
const int buzzer = 6;
const int songspeed = 1.5;
#define NOTE_C4  262  
#define NOTE_D4  294
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_G4  392
#define NOTE_A4  440
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_D5  587
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_G5  784
#define NOTE_A5  880
#define NOTE_B5  988

int notes_song_1[] = {

   NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, 0, 
   NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0, 
   NOTE_C5, NOTE_D5, NOTE_B4, NOTE_B4, 0,
   NOTE_A4, NOTE_G4, NOTE_A4, 0,
   
   NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, 0, 
   NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0, 
   NOTE_C5, NOTE_D5, NOTE_B4, NOTE_B4, 0,
   NOTE_A4, NOTE_G4, NOTE_A4, 0,
   
   NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, 0, 
   NOTE_A4, NOTE_C5, NOTE_D5, NOTE_D5, 0, 
   NOTE_D5, NOTE_E5, NOTE_F5, NOTE_F5, 0,
   NOTE_E5, NOTE_D5, NOTE_E5, NOTE_A4, 0,
   
   NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0, 
   NOTE_D5, NOTE_E5, NOTE_A4, 0, 
   NOTE_A4, NOTE_C5, NOTE_B4, NOTE_B4, 0,
   NOTE_C5, NOTE_A4, NOTE_B4, 0,

    NOTE_A4, NOTE_A4, /*

   NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0, 
   NOTE_C5, NOTE_D5, NOTE_B4, NOTE_B4, 0,
   NOTE_A4, NOTE_G4, NOTE_A4, 0,

   NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, 0, 
   NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0, 
   NOTE_C5, NOTE_D5, NOTE_B4, NOTE_B4, 0,
   NOTE_A4, NOTE_G4, NOTE_A4, 0,
   
   NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, 0, 
   NOTE_A4, NOTE_C5, NOTE_D5, NOTE_D5, 0, 
   NOTE_D5, NOTE_E5, NOTE_F5, NOTE_F5, 0,
   NOTE_E5, NOTE_D5, NOTE_E5, NOTE_A4, 0,
   
   NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0, 
   NOTE_D5, NOTE_E5, NOTE_A4, 0, 
   NOTE_A4, NOTE_C5, NOTE_B4, NOTE_B4, 0,
   NOTE_C5, NOTE_A4, NOTE_B4, 0,*/
};

int duration_song_1[] = { 

  125, 125, 250, 125, 125, 
  125, 125, 250, 125, 125,
  125, 125, 250, 125, 125,
  125, 125, 375, 125, 
  
  125, 125, 250, 125, 125, 
  125, 125, 250, 125, 125,
  125, 125, 250, 125, 125,
  125, 125, 375, 125, 
  
  125, 125, 250, 125, 125, 
  125, 125, 250, 125, 125,
  125, 125, 250, 125, 125,
  125, 125, 125, 250, 125,

  125, 125, 250, 125, 125, 
  250, 125, 250, 125, 
  125, 125, 250, 125, 125,
  125, 125, 375, 375,

  250, 125,

  125, 125, 250, 125, 125,
  125, 125, 250, 125, 125,
  125, 125, 375, 125, 
  
  125, 125, 250, 125, 125, 
  125, 125, 250, 125, 125,
  125, 125, 250, 125, 125,
  125, 125, 375, 125, 
  
  125, 125, 250, 125, 125, 
  125, 125, 250, 125, 125,
  125, 125, 250, 125, 125,
  125, 125, 125, 250, 125,

  125, 125, 250, 125, 125, 
  250, 125, 250, 125, 
  125, 125, 250, 125, 125,
  125, 125, 375, 375,
 };
//FINE
//--------------------------------------------------------------------------------  
//--------------------------------------------------------------------------------
//HARRY POTTER
struct MusicStruct {
  int A = 550;
  int As = 582;
  int B = 617;
  int C = 654;
  int Cs = 693;
  int D = 734;
  int Ds = 777;
  int E = 824;
  int F = 873;
  int Fs = 925;
  int G = 980;
  int Gs = 1003;
  int A2 = 1100;
  int A2s = 1165;
  int B2 = 1234;
  int C3 = 1308;
  int C3s = 1385;
  int D3 = 1555;
}Music;

struct LengthStruct {
  float half = 0.5;
  float one = 1.0;
  float one_half = 1.5;
  float two = 2.0;
  float two_half = 2.5;
}Length;

int tempo = 400;
void setTone(int pin, int note, int duration) {
  tone(pin, note, duration);
  delay(duration);
  noTone(pin);
}
//FINE

void setup(){
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("Stato");
  lcd.setCursor(0, 1);
  lcd.print("Spento");
  pinMode(LED_ON, OUTPUT);
  pinMode(LED_OFF, OUTPUT);
  Serial.begin(9600);
  Serial.println("IR Receiver Button Decode"); 
  irrecv.enableIRIn(); // Start the receiver
  digitalWrite(LED_OFF,HIGH);
}


void loop(){
  if (irrecv.decode(&results)) 

  {
    translateIR(); 
    irrecv.resume(); 
  }  
}


void translateIR() {

  switch(results.value)

  {

  case 0xFFA25D:{
    Serial.println("SPEGNI/ACCENDI");
    if(digitalRead(LED_OFF) == HIGH){
    digitalWrite(LED_ON, HIGH);
    digitalWrite(LED_OFF,LOW);
    lcd.setCursor(0,1);
    lcd.print("Acceso");
    delay(1500);
    break;
    }else{
    digitalWrite(LED_ON, LOW); 
    digitalWrite(LED_OFF,HIGH); 
    lcd.setCursor(0,1);
    lcd.print("Spento");
    break;
    }
  }
  case 0xFF629D:Serial.println("VOLUME+");    break;
  case 0xFF22DD:{
  if(pointer == 1){
  pointer == 3;
  HarryPotter();
  break;
  }
  if(pointer == 2){
  pointer == 1;
  PiratiDeiCaraibi();
  break;
  }
  if(pointer == 3){
  pointer == 2;
  SuperMarioTheme();
  break;
  }
  Serial.println("LEFT");   
  break;
  }
  case 0xFF02FD:{
    if(digitalRead(LED_ON)==HIGH){
    for(int i = 0; i<3; i++)
    {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Canzoni:");
    lcd.setCursor(0,1);
    lcd.print(waiting[i]);
    delay(2500);
  }
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Stato");
  lcd.setCursor(0,1);
  lcd.print("Acceso");
  
    }
 Serial.println("PLAY");

  break;}
  case 0xFFC23D:{
  if(pointer == 1){
  pointer == 2;
  SuperMarioTheme();
  break;
  }
  if(pointer == 2){
  pointer == 3;
  HarryPotter();
  break;
  }
  if(pointer == 3){
  pointer == 1;
  PiratiDeiCaraibi();
  break;
  }

  Serial.println("RIGHT");   
  break;
  }
  case 0xFFE01F: Serial.println("DOWN");    break;
  case 0xFFA857: Serial.println("VOL- ");    break;
  case 0xFF906F: Serial.println("UP");    break;
  case 0xFF6897: Serial.println("0");    break;
  case 0xFF9867: Serial.println("EQ");    break;
  case 0xFFB04F: Serial.println("ST/REPT");    break;
  case 0xFF30CF:{
  if(digitalRead(LED_OFF) == LOW){
  PiratiDeiCaraibi();
  break;
  }
  else{
  break;
  }
  }
  case 0xFF18E7:{
  if(digitalRead(LED_OFF) == LOW){
  SuperMarioTheme(); 
  break;
  }
  else{
  break;
  }
  }
  case 0xFF7A85:{
  if(digitalRead(LED_OFF) == LOW){
  HarryPotter();
  break;
  }
  else{
  break;
  }
  }
  case 0xFF10EF: Serial.println("4");    break;
  case 0xFF38C7: Serial.println("5");    break;
  case 0xFF5AA5: Serial.println("6");break;  
  case 0xFF42BD: Serial.println("7");    break;
  case 0xFF4AB5: Serial.println("8");    break;
  case 0xFF52AD: Serial.println("9");break;  

  default: 
    Serial.println(" other button   ");

  }

  delay(500); 


} 


void PiratiDeiCaraibi(){
  pointer = 1;
  lcd.clear();
  Serial.println("Suonando.. Pirati dei Caraibi"); 
  lcd.setCursor(0, 0);
  lcd.print("Musica");
  lcd.setCursor(0, 1);
  lcd.print("Pirati Caraibi");
  for (int i=0;i<70;i++){             
  int wait = duration_song_1[i] * songspeed;
  tone(buzzer,notes_song_1[i],wait);         
  delay(wait);}   

}
void SuperMarioTheme(){
  pointer = 2;
  lcd.clear();
  Serial.println("Suonando.. Super Mario Theme"); 
  lcd.setCursor(0, 0);
  lcd.print("Musica");
  lcd.setCursor(0, 1);
  lcd.print("Super Mario");
tone(buzzer, 660 ,100);  
delay ( 150);  
tone(buzzer, 660 ,100);  
delay ( 300);  
tone(buzzer, 660 ,100);  
delay ( 300);  
tone(buzzer, 510 ,100);  
delay ( 100);  
tone(buzzer, 660 ,100);  
delay ( 300);  
tone(buzzer, 770 ,100);  
delay ( 550);  
tone(buzzer, 380 ,100);  
delay ( 575);  
  
tone(buzzer, 510 ,100);  
delay ( 450);  
tone(buzzer, 380 ,100);  
delay ( 400);  
tone(buzzer, 320 ,100);  
delay ( 500);  
tone(buzzer, 440 ,100);  
delay ( 300);  
tone(buzzer, 480 ,80);  
delay ( 330);  
tone(buzzer, 450 ,100);  
delay ( 150);  
tone(buzzer, 430 ,100);  
delay ( 300);  
tone(buzzer, 380 ,100);  
delay ( 200);  
tone(buzzer, 660 ,80);  
delay ( 200);  
tone(buzzer, 760 ,50);  
delay ( 150);  
tone(buzzer, 860 ,100);  
delay ( 300);  
tone(buzzer, 700 ,80);  
delay ( 150);  
tone(buzzer, 760 ,50);  
delay ( 350);  
tone(buzzer, 660 ,80);  
delay ( 300);  
tone(buzzer, 520 ,80);  
delay ( 150);  
tone(buzzer, 580 ,80);  
delay ( 150);  
tone(buzzer, 480 ,80);  
delay ( 500);  
  
tone(buzzer, 510 ,100);  
delay ( 450);  
tone(buzzer, 380 ,100);  
delay ( 400);  
tone(buzzer, 320 ,100);  
delay ( 500);  
tone(buzzer, 440 ,100);  
delay ( 300);  
tone(buzzer, 480 ,80);  
delay ( 330);  
tone(buzzer, 450 ,100);  
delay ( 150);  
tone(buzzer, 430 ,100);  
delay ( 300);  
tone(buzzer, 380 ,100);  
delay ( 200);  
tone(buzzer, 660 ,80);  
delay ( 200);  
tone(buzzer, 760 ,50);  
delay ( 150);  
tone(buzzer, 860 ,100);  
delay ( 300);  
tone(buzzer, 700 ,80);  
delay ( 150);  
tone(buzzer, 760 ,50);  
delay ( 350);  
tone(buzzer, 660 ,80);  
delay ( 300);  
tone(buzzer, 520 ,80);  
delay ( 150);  
tone(buzzer, 580 ,80);  
delay ( 150);  
tone(buzzer, 480 ,80);  
delay ( 500);  
  
tone(buzzer, 500 ,100);  
delay ( 300);  
  
tone(buzzer, 760 ,100);  
delay ( 100);  
tone(buzzer, 720 ,100);  
delay ( 150);  
tone(buzzer, 680 ,100);  
delay ( 150);  
tone(buzzer, 620 ,150);  
delay ( 300);  
  
tone(buzzer, 650 ,150);  
delay ( 300);  
tone(buzzer, 380 ,100);  
delay ( 150);  
tone(buzzer, 430 ,100);  
delay ( 150);  
  
tone(buzzer, 500 ,100);  
delay ( 300);  
tone(buzzer, 430 ,100);  
delay ( 150);  
tone(buzzer, 500 ,100);  
delay ( 100);  
tone(buzzer, 570 ,100);  
delay ( 220);  
  
tone(buzzer, 500 ,100);  
delay ( 300);  
  
tone(buzzer, 760 ,100);  
delay ( 100);  
tone(buzzer, 720 ,100);  
delay ( 150);  
tone(buzzer, 680 ,100);  
delay ( 150);  
tone(buzzer, 620 ,150);  
delay ( 300);  
  
tone(buzzer, 650 ,200);  
delay ( 300);  
  
tone(buzzer, 1020 ,80);  
delay ( 300);  
tone(buzzer, 1020 ,80);  
delay ( 150);  
tone(buzzer, 1020 ,80);  
delay ( 300);  
  
tone(buzzer, 380 ,100);  
delay ( 300);  
tone(buzzer, 500 ,100);  
delay ( 300);  
  
tone(buzzer, 760 ,100);  
delay ( 100);  
tone(buzzer, 720 ,100);  
delay ( 150);  
tone(buzzer, 680 ,100);  
delay ( 150);  
tone(buzzer, 620 ,150);  
delay ( 300);  
  
tone(buzzer, 650 ,150);  
delay ( 300);  
tone(buzzer, 380 ,100);  
delay ( 150);  
tone(buzzer, 430 ,100);  
delay ( 150);  
  
tone(buzzer, 500 ,100);  
delay ( 300);  
tone(buzzer, 430 ,100);  
delay ( 150);  
tone(buzzer, 500 ,100);  
delay ( 100);  
tone(buzzer, 570 ,100);  
delay ( 420);  
  
tone(buzzer, 585 ,100);  
delay ( 450);  
  
tone(buzzer, 550 ,100);  
delay ( 420);  
  
tone(buzzer, 500 ,100);  
delay ( 360);  
/*
tone(buzzer, 380 ,100);  
delay ( 300);  
tone(buzzer, 500 ,100);  
delay ( 300);  
tone(buzzer, 500 ,100);  
delay ( 150);  
tone(buzzer, 500 ,100);  
delay ( 300);  
  
tone(buzzer, 500 ,100);  
delay ( 300);  
  
tone(buzzer, 760 ,100);  
delay ( 100);  
tone(buzzer, 720 ,100);  
delay ( 150);  
tone(buzzer, 680 ,100);  
delay ( 150);  
tone(buzzer, 620 ,150);  
delay ( 300);  
  
tone(buzzer, 650 ,150);  
delay ( 300);  
tone(buzzer, 380 ,100);  
delay ( 150);  
tone(buzzer, 430 ,100);  
delay ( 150);  
  
tone(buzzer, 500 ,100);  
delay ( 300);  
tone(buzzer, 430 ,100);  
delay ( 150);  
tone(buzzer, 500 ,100);  
delay ( 100);  
tone(buzzer, 570 ,100);  
delay ( 220);  
  
tone(buzzer, 500 ,100);  
delay ( 300);  
  
tone(buzzer, 760 ,100);  
delay ( 100);  
tone(buzzer, 720 ,100);  
delay ( 150);  
tone(buzzer, 680 ,100);  
delay ( 150);  
tone(buzzer, 620 ,150);  
delay ( 300);  
  
tone(buzzer, 650 ,200);  
delay ( 300);  
  
tone(buzzer, 1020 ,80);  
delay ( 300);  
tone(buzzer, 1020 ,80);  
delay ( 150);  
tone(buzzer, 1020 ,80);  
delay ( 300);  
  
tone(buzzer, 380 ,100);  
delay ( 300);  
tone(buzzer, 500 ,100);  
delay ( 300);  
  
tone(buzzer, 760 ,100);  
delay ( 100);  
tone(buzzer, 720 ,100);  
delay ( 150);  
tone(buzzer, 680 ,100);  
delay ( 150);  
tone(buzzer, 620 ,150);  
delay ( 300);  
  
tone(buzzer, 650 ,150);  
delay ( 300);  
tone(buzzer, 380 ,100);  
delay ( 150);  
tone(buzzer, 430 ,100);  
delay ( 150);  
  
tone(buzzer, 500 ,100);  
delay ( 300);  
tone(buzzer, 430 ,100);  
delay ( 150);  
tone(buzzer, 500 ,100);  
delay ( 100);  
tone(buzzer, 570 ,100);  
delay ( 420);  
  
tone(buzzer, 585 ,100);  
delay ( 450);  
  
tone(buzzer, 550 ,100);  
delay ( 420);  
  
tone(buzzer, 500 ,100);  
delay ( 360);  
  
tone(buzzer, 380 ,100);  
delay ( 300);  
tone(buzzer, 500 ,100);  
delay ( 300);  
tone(buzzer, 500 ,100);  
delay ( 150);  
tone(buzzer, 500 ,100);  
delay ( 300);  
  
tone(buzzer, 500 ,60);  
delay ( 150);  
tone(buzzer, 500 ,80);  
delay ( 300);  
tone(buzzer, 500 ,60);  
delay ( 350);  
tone(buzzer, 500 ,80);  
delay ( 150);  
tone(buzzer, 580 ,80);  
delay ( 350);  
tone(buzzer, 660 ,80);  
delay ( 150);  
tone(buzzer, 500 ,80);  
delay ( 300);  
tone(buzzer, 430 ,80);  
delay ( 150);  
tone(buzzer, 380 ,80);  
delay ( 600);  
  
tone(buzzer, 500 ,60);  
delay ( 150);  
tone(buzzer, 500 ,80);  
delay ( 300);  
tone(buzzer, 500 ,60);  
delay ( 350);  
tone(buzzer, 500 ,80);  
delay ( 150);  
tone(buzzer, 580 ,80);  
delay ( 150);  
tone(buzzer, 660 ,80);  
delay ( 550);  
  
tone(buzzer, 870 ,80);  
delay ( 325);  
tone(buzzer, 760 ,80);  
delay ( 600);  
  
tone(buzzer, 500 ,60);  
delay ( 150);  
tone(buzzer, 500 ,80);  
delay ( 300);  
tone(buzzer, 500 ,60);  
delay ( 350);  
tone(buzzer, 500 ,80);  
delay ( 150);  
tone(buzzer, 580 ,80);  
delay ( 350);  
tone(buzzer, 660 ,80);  
delay ( 150);  
tone(buzzer, 500 ,80);  
delay ( 300);  
tone(buzzer, 430 ,80);  
delay ( 150);  
tone(buzzer, 380 ,80);  
delay ( 600);  
  
tone(buzzer, 660 ,100);  
delay ( 150);  
tone(buzzer, 660 ,100);  
delay ( 300);  
tone(buzzer, 660 ,100);  
delay ( 300);  
tone(buzzer, 510 ,100);  
delay ( 100);  
tone(buzzer, 660 ,100);  
delay ( 300);  
tone(buzzer, 770 ,100);  
delay ( 550);  
tone(buzzer, 380 ,100);  
delay ( 575);  
*/
}                   

void HarryPotter(){
  pointer = 3;
  lcd.clear();
  Serial.println("Suonando..Harry Potter Theme"); 
  lcd.setCursor(0, 0);
  lcd.print("Musica");
  lcd.setCursor(0, 1);
  lcd.print("Harry Potter");
  setTone(buzzer, Music.B, tempo * Length.one);
  setTone(buzzer, Music.E, tempo * Length.one_half);
  setTone(buzzer, Music.G, tempo * Length.half);
  setTone(buzzer, Music.F, tempo * Length.one);
  setTone(buzzer, Music.E, tempo * Length.two);
  setTone(buzzer, Music.B2, tempo * Length.one);
  setTone(buzzer, Music.A2, tempo * Length.two_half);
  setTone(buzzer, Music.Fs, tempo * Length.two_half);
  
  setTone(buzzer, Music.E, tempo * Length.one_half);
  setTone(buzzer, Music.G, tempo * Length.half);
  setTone(buzzer, Music.F, tempo * Length.one);
  setTone(buzzer, Music.Ds, tempo * Length.two);
  setTone(buzzer, Music.F, tempo * Length.one);
  setTone(buzzer, Music.B, tempo * Length.two_half);
}

Credits

xpaul

xpaul

1 project • 2 followers

Comments