teri meri songs tone using arduino with circuit diagram and code

Teri meri Arduino code.



Arduino code,
 copy and pest




// Teri Meri Meri Teri Prem Kahani by "Future Technology RC"
int BuzzerPin = 9; //buzzer is connected to Pin 9 of the Board.
int LEDPin = 10;
int length = 100; // the number of notes
char notes[] = "DAGAFGAFGAGFEDEDC DEFEFEGAGFEDD DAGAFGAFGAGFEDEDC DEFEFEGAGFEDD DAGAFGAFGAGFEDEDC DEFEFEGAGFEDD "; // a space represents a rest
int beats[] = { 2,1,2,1,2,1,2,1,2,2,1,1,2,2,1,1,1,1,2,1,2,1,1,2,2,2,1,2,2,2,1,1,2,2,1,2,2,2,1,2,2,2,2,1,2,2,1,2,1,1,2,1,2,1,2,2,1,2,2,2,1,2,1,1,2,1,2,1,2,1,2,2,1,1,2,2,1,1,1,2,1,2,1,1,2,2,2,1,2,2,2,1,2,2,2,1,2,2,2,1, };//Duration of each note
int tempo = 300; //Change song speed here

void playTone(int tone, int duration) {  //creating a square wave for the given duration
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(BuzzerPin, HIGH); 
    digitalWrite(LEDPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(BuzzerPin, LOW);
    digitalWrite(LEDPin, LOW);
    delayMicroseconds(tone);
  }
}

void playNote(char note, int duration) { //Assigning high time for the notes
  char names[] = { 'C', 'D', 'E', 'F', 'G', 'A', 'B', 'C' };
  int tones[] = { 956, 851, 758, 716, 638, 568, 1014, 478 };

  // play the tone corresponding to the note name
  for (int i = 0; i < 8; i++)
  {
    if (names[i] == note)
    {
      playTone(tones[i], duration);
    }
  }
}

void setup()
{
  pinMode(BuzzerPin, OUTPUT); // Setting pin 9 as an OutPut Pin
   pinMode(LEDPin, OUTPUT);
}

void loop() {  //Main function
  for (int i = 0; i < length; i++) {  //For the length of the tune array
    if (notes[i] == ' ') {  //take space as rest
      delay(beats[i] * tempo); // rest
    } else {
      playNote(notes[i], beats[i] * tempo); //play the corresponding note for the corresponding beat
    }

    // pause between notes
    delay(tempo / 2);
  }
}


Comments

Popular posts from this blog

How to make talking Voltmeter at home

how to make taking distance measurement device using Arduino and ultrasonic sensor

How to make voltmeter using Arduino