Introduction: Christmas Melody's on LinkIt One

Its Christmas season and in this tutorial Im going to show you how to play Christmas tunes on the LinkIt One. This instructable uses a piezo speaker to play melodies.

The tunes included are -

  • Ding Dong Merrily on High
  • God Rest Ye Merry Gentlemen
  • O Little Town of Bethlehem
  • While Shepherds Watched
  • In The Bleak Midwinter
  • Hark the Herald
  • O come all Ye Faithful
  • O Come O Come Emmanuel

This would also make a wonderful gift if you are planing to gift a LinkIt one to any one.

Step 1: Requirements

Here is a list of all the electronic components required to get started with the circuit.

LinkIt One

Breadboard

Connecting Wires

Piezo Buzzer or 8 Ohm speaker

Step 2: Circuit

The circuit is very simple and the whole program relies on the program to be uploaded to the LinkIt one board. You could use a Piezo buzzer like the one shown in the picture or use a 8 Ohm speaker. I also tried connecting this to an audio amplifier to get a clear tone and guess what it works there are a lot of circuits over the internet on how to build your own amplifier.

Step 3: Code

Here is the general code to be uploaded to the LinkIt One, the code makes the LinkIt one send a square wave of the appropriate frequency to the piezo, generating the corresponding tone.

The code can be found below and you will require a modified Arduino IDE to work with the LinkIt One board to upload the code.

<p>int speakerPin = 9;<br>
int length = 15; // the number of notes
char notes[] = "ccggaagffeeddc "; // change these lines according to the song
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };// change these lines according to the song</p><p>
int tempo = 300;</p><p>void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}</p><p>void playNote(char note, int duration) {
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };</p><p>  // play the tone corresponding to the note name
  for (int i = 0; i < 8; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);
    }
  }
}</p><p>void setup() {
  pinMode(speakerPin, OUTPUT);
}</p><p>void loop() {
  for (int i = 0; i < length; i++) {
    if (notes[i] == ' ') {
      delay(beats[i] * tempo); // rest
    } else {
      playNote(notes[i], beats[i] * tempo);
    }</p><p>    // pause between notes
    delay(tempo / 2); 
  }
}</p>

Step 4: Tunes

Here are you tunes and the changes you need to make to the code to make it play the melody. The tunes work by replacing the two lines of code with the ones in the previous step.

Ding Dong Merrily on High

int length = 73;char notes[] = "ggagsed deggsgg ggagsed deggsgg DCbCDbCbabCabagabgagsgasgsesgeseddeggsgg "; // a space represents a restint beats[] = { 2,2,1,1,1,1,4,2,2,2,2,2,2,4,2,2,2,2,1,1,1,1,4,2,2,2,2,2,2,4,2,2,3,1,1,1,1,1,3,1,1,1,1,1,3,1,1,1,1,1,3,1,1,1,1,1,3,1,1,1,1,1,3,1,2,2,2,2,2,2,4,2,2 };

God Rest Ye Merry Gentlemen

int length = 71;char notes[] = "cfffgagavCavafggfcfffgagavCavafggffaCDCvagfgavCcfagfccfffgagavCavafggf ";int beats[] = { 2,2,2,2,2,1,1,1,1,2,2,2,1,1,2,2,6,2,2,2,2,2,1,1,1,1,2,2,2,1,1,2,2,6,1,1,3,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,4,4,2,2,2,2,1,1,1,1,2,2,2,1,1,2,2,6,2 };

O Little Town of Bethlehem

int length = 71;char notes[] = "cfffgagavCavafggfcfffgagavCavafggffaCDCvagfgavCcfagfccfffgagavCavafggf ";int beats[] = { 2,2,2,2,2,1,1,1,1,2,2,2,1,1,2,2,6,2,2,2,2,2,1,1,1,1,2,2,2,1,1,2,2,6,1,1,3,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,4,4,2,2,2,2,1,1,1,1,2,2,2,1,1,2,2,6,2 };

While Shephards Watched

int length = 29;char notes[] = "faagfvvagaCCbCaDCvagfeagffef ";int beats[] = { 2,3,1,2,2,2,2,2,2,2,2,2,2,6,2,3,1,2,2,2,2,2,2,2,2,2,2,6,2 };

In The Bleak Midwinter

int length = 51;char notes[] = "aavCagfgagdgavCaggfgagff vavCDDaaCagfecavCagfgagff ";int beats[] = { 2,3,1,2,2,4,4,3,1,2,2,8,3,1,2,2,3,1,4,2,2,3,1,6,2,3,1,2,2,2,2,2,2,2,2,2,2,6,2,2,2,2,2,4,4,2,2,3,1,8,8};

Hark the Herald

int length = 77;char notes[] = "cffefaagCCCvagacffefaagCffeedcCCCfvaagCCCfvaagDDDCvavgavCffgaDDDCvavgavCffgf ";int beats[] = {2,2,3,1,2,2,2,2,2,2,3,1,2,2,4,2,2,3,1,2,2,2,2,2,2,3,1,2,2,4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,4,2,1,1,3,1,2,2,4,3,1,2,2,2,2,4,2,1,1,3,1,2,2,4,8};

O come all Ye Faithful

int length = 64;char notes[] = "ggdgadbabCbaggsesgabsedd DCbCbabgasedggsgagdbbabCbabCbagsgCbagg ";int beats[] = { 2,4,2,2,4,4,2,2,2,2,4,2,2,4,2,2,2,2,2,2,4,3,1,6,2,4,2,2,4,4,2,2,2,2,3,1,2,2,2,2,2,2,4,2,2,2,2,2,2,4,2,2,2,2,2,2,4,2,2,4,3,1,6,8 };

O Come O Come Emmanuel

int length = 63;char notes[] = "egbbbaCbagabgegasedeaaeesgsedgabbbaCbag DD bb baCdagabgegasede ";int beats[] = { 2,2,2,2,2,2,2,2,2,6,2,2,2,2,2,2,2,2,2,6,2,2,2,2,2,4,2,2,6,2,2,2,2,2,2,2,2,2,4,2,2,4,2,2,4,2,2,2,2,2,2,6,2,2,2,2,2,2,2,2,2,8,8 };

Comments

author
DIY Hacks and How Tos (author)2015-12-03

This would be a really fun project to set up in or around a Christmas tree.

About This Instructable

1,069views

20favorites

License:

Bio: Eat*Sleep*Code Repeat
More by Prem67:Build a Proximity Sensor with the Linkit OneLinkit One Play MusicLinkit One Oscilloscope
Add instructable to: