Components and supplies
1
Arduino UNO
2
Male/Female Jumper Wires
1
Speaker: 0.25W, 8 ohms
Apps and platforms
1
Arduino IDE
Project description
Code
Code
c_cpp
Upload this code to your Arduino board
1/*Arduino speaker song tutorial 2* This program will play the theme song of the Malayalam movie 3* 'Ennu Ninte Moideen'. The song is 'Mukkathe Penne'. 4* The song is played on the speaker connected to pin 3 and GND. 5* 6* Created 26 Oct 2015 7* by Akshay James 8* Video at https://www.youtube.com/watch?v=LgtcUxe8fmA 9*/ 10 11#include"pitches.h" 12 13// notes in the song 'Mukkathe Penne' 14int melody[] = { 15NOTE_D4, NOTE_G4, NOTE_FS4, NOTE_A4, 16NOTE_G4, NOTE_C5, NOTE_AS4, NOTE_A4, 17NOTE_FS4, NOTE_G4, NOTE_A4, NOTE_FS4, NOTE_DS4, NOTE_D4, 18NOTE_C4, NOTE_D4,0, 19 20NOTE_D4, NOTE_G4, NOTE_FS4, NOTE_A4, 21NOTE_G4, NOTE_C5, NOTE_D5, NOTE_C5, NOTE_AS4, NOTE_C5, NOTE_AS4, NOTE_A4, //29 //8 22NOTE_FS4, NOTE_G4, NOTE_A4, NOTE_FS4, NOTE_DS4, NOTE_D4, 23NOTE_C4, NOTE_D4,0, 24 25NOTE_D4, NOTE_FS4, NOTE_G4, NOTE_A4, NOTE_DS5, NOTE_D5, 26NOTE_C5, NOTE_AS4, NOTE_A4, NOTE_C5, 27NOTE_C4, NOTE_D4, NOTE_DS4, NOTE_FS4, NOTE_D5, NOTE_C5, 28NOTE_AS4, NOTE_A4, NOTE_C5, NOTE_AS4, //58 29 30NOTE_D4, NOTE_FS4, NOTE_G4, NOTE_A4, NOTE_DS5, NOTE_D5, 31NOTE_C5, NOTE_D5, NOTE_C5, NOTE_AS4, NOTE_C5, NOTE_AS4, NOTE_A4, NOTE_C5, NOTE_G4, 32NOTE_A4, 0, NOTE_AS4, NOTE_A4, 0, NOTE_G4, 33NOTE_G4, NOTE_A4, NOTE_G4, NOTE_FS4, 0, 34 35NOTE_C4, NOTE_D4, NOTE_G4, NOTE_FS4, NOTE_DS4, 36NOTE_C4, NOTE_D4, 0, 37NOTE_C4, NOTE_D4, NOTE_G4, NOTE_FS4, NOTE_DS4, 38NOTE_C4, NOTE_D4, END 39 40}; 41 42// note durations: 8 = quarter note, 4 = 8th note, etc. 43int noteDurations[] = { //duration of the notes 448,4,8,4, 454,4,4,12, 464,4,4,4,4,4, 474,16,4, 48 498,4,8,4, 504,2,1,1,2,1,1,12, 514,4,4,4,4,4, 524,16,4, 53 544,4,4,4,4,4, 554,4,4,12, 564,4,4,4,4,4, 574,4,4,12, 58 594,4,4,4,4,4, 602,1,1,2,1,1,4,8,4, 612,6,4,2,6,4, 622,1,1,16,4, 63 644,8,4,4,4, 654,16,4, 664,8,4,4,4, 674,20, 68}; 69 70int speed=90; //higher value, slower notes 71void setup() { 72 73Serial.begin(9600); 74for (int thisNote = 0; melody[thisNote]!=-1; thisNote++) { 75 76int noteDuration = speed*noteDurations[thisNote]; 77tone(3, melody[thisNote],noteDuration*.95); 78Serial.println(melody[thisNote]); 79 80delay(noteDuration); 81 82noTone(3); 83} 84} 85 86void loop() { 87// no need to repeat the melody. 88}
Code
c_cpp
Upload this code to your Arduino board
1/*Arduino speaker song tutorial 2* This program will play the theme song of the Malayalam movie 3* 'Ennu Ninte Moideen'. The song is 'Mukkathe Penne'. 4* The song is played on the speaker connected to pin 3 and GND. 5* 6* Created 26 Oct 2015 7* by Akshay James 8* Video at https://www.youtube.com/watch?v=LgtcUxe8fmA 9*/ 10 11#include"pitches.h" 12 13// notes in the song 'Mukkathe Penne' 14int melody[] = { 15NOTE_D4, NOTE_G4, NOTE_FS4, NOTE_A4, 16NOTE_G4, NOTE_C5, NOTE_AS4, NOTE_A4, 17NOTE_FS4, NOTE_G4, NOTE_A4, NOTE_FS4, NOTE_DS4, NOTE_D4, 18NOTE_C4, NOTE_D4,0, 19 20NOTE_D4, NOTE_G4, NOTE_FS4, NOTE_A4, 21NOTE_G4, NOTE_C5, NOTE_D5, NOTE_C5, NOTE_AS4, NOTE_C5, NOTE_AS4, NOTE_A4, //29 //8 22NOTE_FS4, NOTE_G4, NOTE_A4, NOTE_FS4, NOTE_DS4, NOTE_D4, 23NOTE_C4, NOTE_D4,0, 24 25NOTE_D4, NOTE_FS4, NOTE_G4, NOTE_A4, NOTE_DS5, NOTE_D5, 26NOTE_C5, NOTE_AS4, NOTE_A4, NOTE_C5, 27NOTE_C4, NOTE_D4, NOTE_DS4, NOTE_FS4, NOTE_D5, NOTE_C5, 28NOTE_AS4, NOTE_A4, NOTE_C5, NOTE_AS4, //58 29 30NOTE_D4, NOTE_FS4, NOTE_G4, NOTE_A4, NOTE_DS5, NOTE_D5, 31NOTE_C5, NOTE_D5, NOTE_C5, NOTE_AS4, NOTE_C5, NOTE_AS4, NOTE_A4, NOTE_C5, NOTE_G4, 32NOTE_A4, 0, NOTE_AS4, NOTE_A4, 0, NOTE_G4, 33NOTE_G4, NOTE_A4, NOTE_G4, NOTE_FS4, 0, 34 35NOTE_C4, NOTE_D4, NOTE_G4, NOTE_FS4, NOTE_DS4, 36NOTE_C4, NOTE_D4, 0, 37NOTE_C4, NOTE_D4, NOTE_G4, NOTE_FS4, NOTE_DS4, 38NOTE_C4, NOTE_D4, END 39 40}; 41 42// note durations: 8 = quarter note, 4 = 8th note, etc. 43int noteDurations[] = { //duration of the notes 448,4,8,4, 454,4,4,12, 464,4,4,4,4,4, 474,16,4, 48 498,4,8,4, 504,2,1,1,2,1,1,12, 514,4,4,4,4,4, 524,16,4, 53 544,4,4,4,4,4, 554,4,4,12, 564,4,4,4,4,4, 574,4,4,12, 58 594,4,4,4,4,4, 602,1,1,2,1,1,4,8,4, 612,6,4,2,6,4, 622,1,1,16,4, 63 644,8,4,4,4, 654,16,4, 664,8,4,4,4, 674,20, 68}; 69 70int speed=90; //higher value, slower notes 71void setup() { 72 73Serial.begin(9600); 74for (int thisNote = 0; melody[thisNote]!=-1; thisNote++) { 75 76int noteDuration = speed*noteDurations[thisNote]; 77tone(3, melody[thisNote],noteDuration*.95); 78Serial.println(melody[thisNote]); 79 80delay(noteDuration); 81 82noTone(3); 83} 84} 85 86void loop() { 87// no need to repeat the melody. 88}
Downloadable files
Circuit Diagram
Do your connects by using this Circuit Diagram
Circuit Diagram
Comments
Only logged in users can leave comments