loading

If you are planing to gift a Linkit One for your friends or family birth day, you can set up this project and make the Linkit one play the Happy Birth day tune for him or her. This is a really cool gift and I actually presented this project to my friend and he loved it and also this instructable is really very simple to design. If you are looking for Christmas tunes I made an instructable on that earlier.

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.

int speakerPin = 9;

int length = 28; // the number of notes

char notes[] = "GGAGcB GGAGdc GGxecBA yyecdc";

int beats[] = { 2, 2, 8, 8, 8, 16, 1, 2, 2, 8, 8,8, 16, 1, 2,2,8,8,8,8,16, 1,2,2,8,8,8,16 };

int tempo = 150;

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);

}

}

void playNote(char note, int duration) {

char names[] = {'C', 'D', 'E', 'F', 'G', 'A', 'B',

'c', 'd', 'e', 'f', 'g', 'a', 'b',

'x', 'y' };

int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014,

956, 834, 765, 593, 468, 346, 224,

655 , 715 };

int SPEE = 5;

// play the tone corresponding to the note name

for (int i = 0; i < 17; i++) {

if (names[i] == note) { int newduration = duration/SPEE; playTone(tones[i], newduration);

}

}

}

void setup() {

pinMode(speakerPin, OUTPUT);

}

void loop() {

for (int i = 0; i < length; i++) {

if (notes[i] == ' ') {

delay(beats[i] * tempo); // rest

} else {

playNote(notes[i], beats[i] * tempo);

}

// pause between notes

delay(tempo);

}

}

Step 4: Packing It Up

You can also set up a light sensor and edit the code to play the tune when it detects light, so you can wrap it up in a box and right when the person opens it up it starts playing the tune. If you make the circuit make sure to use the "I Made it" Button and let me know how you designed your gift.

About This Instructable

230views

1favorite

License:

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