Piezo Christmas Songs

For a digital Christmas, let your Arduino play songs with a piezo buzzer.

Dec 17, 2017

129522 views

77 respects

Components and supplies

1

Arduino UNO

1

Resistor 330 ohm

3

Resistor 10k ohm

3

Pushbutton switch 12mm

1

Buzzer

Project description

Code

Arduino Christmas Songs

arduino

pitches.h

arduino

Arduino Christmas Songs

arduino

Downloadable files

Wiring

Wiring

Wiring

Wiring

Comments

Only logged in users can leave comments

naiinika_12

10 months ago

how to add one more button and song for it

Anonymous user

2 years ago

Hi, if i press the button will it sound again and again? Tnx

joshi

2 years ago

No the code doesn't account for that, but I think you could made it in a loop.

Anonymous user

2 years ago

Awesome project! I used it as the base for my latest instructable, making a Christmas sweater that lights up and sings songs. https://www.instructables.com/id/Singing-Light-Up-Christmas-Sweater/ Thank you very much for sharing! It would have taken me forever to try and program it myself, as I am still learning.

larrybracken

2 years ago

Hi, I used this project as a base for my own project you can find a tutorial here:https://create.arduino.cc/projecthub/larrybracken/make-a-christmas-song-player-with-a-buzzer-and-lcd-display-d118f2?ref=user&ref_id=724297&offset=0 Thank you, Larry B

Anonymous user

2 years ago

I enjoyed making this project, it totally worked for me. Thanks alot

Anonymous user

2 years ago

I have coded it exactly like you with no errors but when I push a button there is no sound coming out but I can see the light with the right melody, do you have any suggestions on how to fix this?

joshi

2 years ago

Sorry for the late reply. Could be your piezo maybe. Is it wired correctly? And have you confirmed it working in another project?

Anonymous user

2 years ago

awesome project!!! seriously thankyou for keeping it simple p.s. a few off notes in 'we wish you a merry christmas' should be; int wish_melody[] = { NOTE_AS3, NOTE_F4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_D4, NOTE_D4, NOTE_D4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_C4, NOTE_C4, NOTE_A4, NOTE_A4, NOTE_AS4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_D4, NOTE_C4, NOTE_C4, NOTE_D4, NOTE_G4, NOTE_E4, NOTE_F4 };

Anonymous user

2 years ago

great project. Instead of the Display, i connected an LED between output 13 and ground and the LED light blinks with the music.

Anonymous user

2 years ago

Getting a fatal error avr\\interrupt,h no file or directory.

RussBuss38

2 years ago

These instructions how to import library file using .zip procedures. Here I'm downloading a .ino

joshi

2 years ago

You probably have to include the library pitches.h first. Forgot to mention that in my post, but I have edited it. Instructions for pitches.h are here: https://www.arduino.cc/en/Tutorial/toneMelody You can also put it directly in your code.

Anonymous user

2 years ago

I am using your code to adapt it to work with a "Dancing Santa Hat". I found it on a discount store but was not working properly. I disassembly it completely to understand how it works and to try to modify it (it was my first idea). I completed the lights and songs testing just missing the ac motor to move the hat and how to attach batteries. I will complete the project and share it here. Thanks from Costa Rica

minukayapa

2 years ago

It is not working Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno" Sweep:9:10: fatal error: pitches.h: No such file or directory #include "pitches.h" ^~~~~~~~~~~ compilation terminated. exit status 1 pitches.h: No such file or directory This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

minukayapa

2 years ago

what?

Tiash22

2 years ago

I get some errors showing - Arduino: 1.8.5 (Windows 7), Board: "Arduino/Genuino Uno" C:\\Users\\Tiash\\Desktop\\sketch_dec30a\\sketch_dec30a.ino: In function 'void sing(int)': sketch_dec30a:58: error: expected ')' before ';' token Serial.println(" 'We wish you a Merry Christmas'"); ^ sketch_dec30a:68: error: 'buzz' was not declared in this scope buzz(melodyPin, wish_melody[thisNote], noteDuration); ^ C:\\Users\\Tiash\\Desktop\\sketch_dec30a\\sketch_dec30a.ino: At global scope: sketch_dec30a:80: error: expected declaration before '}' token } ^ exit status 1 expected ')' before ';' token This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

joshi

2 years ago

I'm not yet very good at programming for Arduino and I can't really find what's wrong with the code. Maybe there should be a space between Christmas' and ". And about buzz not declared. It's declared at the bottom. Maybe you should move that part of the code up before void sing.

coldfire2014

2 years ago

Do you know if this works with an Arduino Uno R3? I noticed that you're using a different Arduino Uno.

Anonymous user

2 years ago

Hey!! This is simple. Either create a header file in Arduino software or second method is quite easy as below: https://forum.arduino.cc/t/how-to-make-the-pitches-h-file-include-pitches-h/287340 1) Open the link -> Copy the code 2) Now delete "pitch.h" line 3) Instead paste the code just in starting of code, you just copied earlier NOTE: you can either create pitch header file or simply just paste the code in declaration section and then start coding. Hope this finds helpful!! Enjoy coding!!

Anonymous user

2 years ago

I'm getting an error message saying; Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: "Arduino/Genuino Uno" C:\\Users\\Admin\\AppData\\Local\\Temp\\arduino_modified_sketch_796818\\sketch_dec30b.ino:9:21: fatal error: pitches.h: No such file or directory #include "pitches.h" ^ compilation terminated. exit status 1 Error compiling for board Arduino/Genuino Uno. This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

joshi

2 years ago

You have to include the pitches.h file, then it should work. You can find it here: https://www.arduino.cc/en/Tutorial/toneMelody (The second set of code on that page).

Anonymous user

2 years ago

Hey man,tried your project and it´s nice.But it keeps repeating merry xmas over and over again.Could you help out? Thxs

Anonymous user

2 years ago

try testing your push button by connecting to a LED to make sure it responds and switches between the high and low states.

Anonymous user

2 years ago

Done that, the leds responds as supposed, but songs never change

Anonymous user

2 years ago

doesnt work

Anonymous user

2 years ago

Above Serial.println(" 'Jingle Bells'"); change Else to Else if should fixed it

Anonymous user

2 years ago

Is there a ".zip" file for the pitches.h library? Just curious because the arduino Libraries page shows how to import using a .zip.

Anonymous user

2 years ago

For the moment I have just copied and pasted the whole library in the sketch and it seems to be working fine.

Anonymous user

2 years ago

I made a project! https://youtu.be/--JuTtx7d5c

waynesparky

2 years ago

great project works fine

Anonymous user

2 years ago

Getting an Error saying 'melody' was not declared in this scope

Anonymous user

2 years ago

nvm fixed when i moved loop to the very bottom

Anonymous user

2 years ago

Can you please explain in detail how does that pitches.h work? trying to use the code but it tell me it doesnt have a file or direction,what should i use from the arduino website to fix this problem?

Anonymous user

2 years ago

I was stumped too, but then I found the solution how to include pitches.h In the code window with Christmas Songs code - iIn the upper right corner of the code window, there is a magnifying glass (Serial monitor). Below that one is an icon (triangle). Click that one and choose New Tab. Paste the pitches.h code in there. (The one below) Then go back to original code window and upload to Arduino. /************************************************* * Public Constants *************************************************/ #define NOTE_B0 31 #define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49 #define NOTE_GS1 52 #define NOTE_A1 55 #define NOTE_AS1 58 #define NOTE_B1 62 #define NOTE_C2 65 #define NOTE_CS2 69 #define NOTE_D2 73 #define NOTE_DS2 78 #define NOTE_E2 82 #define NOTE_F2 87 #define NOTE_FS2 93 #define NOTE_G2 98 #define NOTE_GS2 104 #define NOTE_A2 110 #define NOTE_AS2 117 #define NOTE_B2 123 #define NOTE_C3 131 #define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 220 #define NOTE_AS3 233 #define NOTE_B3 247 #define NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 #define NOTE_G4 392 #define NOTE_GS4 415 #define NOTE_A4 440 #define NOTE_AS4 466 #define NOTE_B4 494 #define NOTE_C5 523 #define NOTE_CS5 554 #define NOTE_D5 587 #define NOTE_DS5 622 #define NOTE_E5 659 #define NOTE_F5 698 #define NOTE_FS5 740 #define NOTE_G5 784 #define NOTE_GS5 831 #define NOTE_A5 880 #define NOTE_AS5 932 #define NOTE_B5 988 #define NOTE_C6 1047 #define NOTE_CS6 1109 #define NOTE_D6 1175 #define NOTE_DS6 1245 #define NOTE_E6 1319 #define NOTE_F6 1397 #define NOTE_FS6 1480 #define NOTE_G6 1568 #define NOTE_GS6 1661 #define NOTE_A6 1760 #define NOTE_AS6 1865 #define NOTE_B6 1976 #define NOTE_C7 2093 #define NOTE_CS7 2217 #define NOTE_D7 2349 #define NOTE_DS7 2489 #define NOTE_E7 2637 #define NOTE_F7 2794 #define NOTE_FS7 2960 #define NOTE_G7 3136 #define NOTE_GS7 3322 #define NOTE_A7 3520 #define NOTE_AS7 3729 #define NOTE_B7 3951 #define NOTE_C8 4186 #define NOTE_CS8 4435 #define NOTE_D8 4699 #define NOTE_DS8 4978

Anonymous user

2 years ago

hola, soy nuevo en arduino y hay cosas que no tengo muy en claro, alguien que pudo hacerlo y me de una mano? probe con todo y todavia no sale sonido, la programacion no me da error

Anonymous user

2 years ago

Good example, works great! Why do you have a resistor in series with the Piezo, is it to reduce noise that would cause weird sounds? Seems to work fine without one.

joshi

2 years ago

I placed the resistor there because it was also there in the original project. Didn't think of trying it without. But it's good to hear it works too without a resistor!

Anonymous user

2 years ago

why does it write exit status 1 redefinition of 'void loop()' ?

joshi

2 years ago

That probably means there was an error in your code, you should check your code for errors. Did you make any changes? Did you include the pitches library?

Anonymous user

2 years ago

i copyed the full code and i included the pitches.h. i didn't do any changes?!

joshi

2 years ago

I'm sorry, I'm not yet very good at programming for Arduino, I'm not sure what goes wrong. The code works for me. Maybe you have the same problem as below in the comments?

coldfire2014

2 years ago

It means that you wrote 'void loop()' twice in your code.

anubis_67

2 years ago

Works Great, I replaced the resistor on the buzzer with an LED to increase the volume and create a light that blinks with the music, a great project for a beginner like myself.

Anonymous user

2 years ago

I have that same mini Christmas tree and i got lights for it and everything.

Anonymous user

3 years ago

Hey!! This is simple. Either create a header file in Arduino software or second method is quite easy as below: https://forum.arduino.cc/t/how-to-make-the-pitches-h-file-include-pitches-h/287340 1) Open the link -> Copy the code 2) Now delete "pitch.h" line 3) Instead paste the code just in starting of code, you just copied earlier NOTE: you can either create pitch header file or simply just paste the code in declaration section and then start coding. Hope this finds helpful!! Enjoy coding!!

Anonymous user

3 years ago

great project. Instead of the Display, i connected an LED between output 13 and ground and the LED light blinks with the music.

Anonymous user

3 years ago

hola, soy nuevo en arduino y hay cosas que no tengo muy en claro, alguien que pudo hacerlo y me de una mano? probe con todo y todavia no sale sonido, la programacion no me da error

hiimpeppapig

3 years ago

Santa Claus is coming to town continues to buzz, even when I press another button

minukayapa

4 years ago

It is not working Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno" Sweep:9:10: fatal error: pitches.h: No such file or directory #include "pitches.h" ^~~~~~~~~~~ compilation terminated. exit status 1 pitches.h: No such file or directory This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

minukayapa

2 years ago

what?

Anonymous user

4 years ago

Can you please explain in detail how does that pitches.h work? trying to use the code but it tell me it doesnt have a file or direction,what should i use from the arduino website to fix this problem?

Anonymous user

2 years ago

I was stumped too, but then I found the solution how to include pitches.h In the code window with Christmas Songs code - iIn the upper right corner of the code window, there is a magnifying glass (Serial monitor). Below that one is an icon (triangle). Click that one and choose New Tab. Paste the pitches.h code in there. (The one below) Then go back to original code window and upload to Arduino. /************************************************* * Public Constants *************************************************/ #define NOTE_B0 31 #define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49 #define NOTE_GS1 52 #define NOTE_A1 55 #define NOTE_AS1 58 #define NOTE_B1 62 #define NOTE_C2 65 #define NOTE_CS2 69 #define NOTE_D2 73 #define NOTE_DS2 78 #define NOTE_E2 82 #define NOTE_F2 87 #define NOTE_FS2 93 #define NOTE_G2 98 #define NOTE_GS2 104 #define NOTE_A2 110 #define NOTE_AS2 117 #define NOTE_B2 123 #define NOTE_C3 131 #define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 220 #define NOTE_AS3 233 #define NOTE_B3 247 #define NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 #define NOTE_G4 392 #define NOTE_GS4 415 #define NOTE_A4 440 #define NOTE_AS4 466 #define NOTE_B4 494 #define NOTE_C5 523 #define NOTE_CS5 554 #define NOTE_D5 587 #define NOTE_DS5 622 #define NOTE_E5 659 #define NOTE_F5 698 #define NOTE_FS5 740 #define NOTE_G5 784 #define NOTE_GS5 831 #define NOTE_A5 880 #define NOTE_AS5 932 #define NOTE_B5 988 #define NOTE_C6 1047 #define NOTE_CS6 1109 #define NOTE_D6 1175 #define NOTE_DS6 1245 #define NOTE_E6 1319 #define NOTE_F6 1397 #define NOTE_FS6 1480 #define NOTE_G6 1568 #define NOTE_GS6 1661 #define NOTE_A6 1760 #define NOTE_AS6 1865 #define NOTE_B6 1976 #define NOTE_C7 2093 #define NOTE_CS7 2217 #define NOTE_D7 2349 #define NOTE_DS7 2489 #define NOTE_E7 2637 #define NOTE_F7 2794 #define NOTE_FS7 2960 #define NOTE_G7 3136 #define NOTE_GS7 3322 #define NOTE_A7 3520 #define NOTE_AS7 3729 #define NOTE_B7 3951 #define NOTE_C8 4186 #define NOTE_CS8 4435 #define NOTE_D8 4699 #define NOTE_DS8 4978

Anonymous user

4 years ago

awesome project!!! seriously thankyou for keeping it simple p.s. a few off notes in 'we wish you a merry christmas' should be; int wish_melody[] = { NOTE_AS3, NOTE_F4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_D4, NOTE_D4, NOTE_D4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_C4, NOTE_C4, NOTE_A4, NOTE_A4, NOTE_AS4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_D4, NOTE_C4, NOTE_C4, NOTE_D4, NOTE_G4, NOTE_E4, NOTE_F4 };

waynesparky

5 years ago

great project works fine

RussBuss38

5 years ago

I made a project! https://youtu.be/--JuTtx7d5c

RussBuss38

5 years ago

Is there a ".zip" file for the pitches.h library? Just curious because the arduino Libraries page shows how to import using a .zip.

RussBuss38

2 years ago

For the moment I have just copied and pasted the whole library in the sketch and it seems to be working fine.

Anonymous user

5 years ago

I enjoyed making this project, it totally worked for me. Thanks alot

larrybracken

5 years ago

Hi, I used this project as a base for my own project you can find a tutorial here:https://create.arduino.cc/projecthub/larrybracken/make-a-christmas-song-player-with-a-buzzer-and-lcd-display-d118f2?ref=user&ref_id=724297&offset=0 Thank you, Larry B

Anonymous user

5 years ago

I am using your code to adapt it to work with a "Dancing Santa Hat". I found it on a discount store but was not working properly. I disassembly it completely to understand how it works and to try to modify it (it was my first idea). I completed the lights and songs testing just missing the ac motor to move the hat and how to attach batteries. I will complete the project and share it here. Thanks from Costa Rica

Anonymous user

5 years ago

Hi, if i press the button will it sound again and again? Tnx

joshi

2 years ago

No the code doesn't account for that, but I think you could made it in a loop.

Anonymous user

6 years ago

I have coded it exactly like you with no errors but when I push a button there is no sound coming out but I can see the light with the right melody, do you have any suggestions on how to fix this?

joshi

2 years ago

Sorry for the late reply. Could be your piezo maybe. Is it wired correctly? And have you confirmed it working in another project?

Anonymous user

6 years ago

Awesome project! I used it as the base for my latest instructable, making a Christmas sweater that lights up and sings songs. https://www.instructables.com/id/Singing-Light-Up-Christmas-Sweater/ Thank you very much for sharing! It would have taken me forever to try and program it myself, as I am still learning.

Gonzo333

6 years ago

Hey man,tried your project and it´s nice.But it keeps repeating merry xmas over and over again.Could you help out? Thxs

Anonymous user

2 years ago

try testing your push button by connecting to a LED to make sure it responds and switches between the high and low states.

hiimpeppapig

2 years ago

doesnt work

Anonymous user

2 years ago

Above Serial.println(" 'Jingle Bells'"); change Else to Else if should fixed it

Anonymous user

2 years ago

Done that, the leds responds as supposed, but songs never change

Anonymous user

6 years ago

Getting an Error saying 'melody' was not declared in this scope

Anonymous user

2 years ago

nvm fixed when i moved loop to the very bottom

The1Xander

7 years ago

I'm getting an error message saying; Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: "Arduino/Genuino Uno" C:\\Users\\Admin\\AppData\\Local\\Temp\\arduino_modified_sketch_796818\\sketch_dec30b.ino:9:21: fatal error: pitches.h: No such file or directory #include "pitches.h" ^ compilation terminated. exit status 1 Error compiling for board Arduino/Genuino Uno. This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

joshi

2 years ago

You have to include the pitches.h file, then it should work. You can find it here: https://www.arduino.cc/en/Tutorial/toneMelody (The second set of code on that page).

Tiash22

7 years ago

I get some errors showing - Arduino: 1.8.5 (Windows 7), Board: "Arduino/Genuino Uno" C:\\Users\\Tiash\\Desktop\\sketch_dec30a\\sketch_dec30a.ino: In function 'void sing(int)': sketch_dec30a:58: error: expected ')' before ';' token Serial.println(" 'We wish you a Merry Christmas'"); ^ sketch_dec30a:68: error: 'buzz' was not declared in this scope buzz(melodyPin, wish_melody[thisNote], noteDuration); ^ C:\\Users\\Tiash\\Desktop\\sketch_dec30a\\sketch_dec30a.ino: At global scope: sketch_dec30a:80: error: expected declaration before '}' token } ^ exit status 1 expected ')' before ';' token This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

joshi

2 years ago

I'm not yet very good at programming for Arduino and I can't really find what's wrong with the code. Maybe there should be a space between Christmas' and ". And about buzz not declared. It's declared at the bottom. Maybe you should move that part of the code up before void sing.

coldfire2014

2 years ago

By the way, I mean 'buzz'

coldfire2014

2 years ago

Ya, it needs to be out of a 'void' so that all 'void' s can access it.

Fuzzi_

7 years ago

why does it write exit status 1 redefinition of 'void loop()' ?

Fuzzi_

2 years ago

i copyed the full code and i included the pitches.h. i didn't do any changes?!

joshi

2 years ago

That probably means there was an error in your code, you should check your code for errors. Did you make any changes? Did you include the pitches library?

joshi

2 years ago

I'm sorry, I'm not yet very good at programming for Arduino, I'm not sure what goes wrong. The code works for me. Maybe you have the same problem as below in the comments?

Anonymous user

7 years ago

Good example, works great! Why do you have a resistor in series with the Piezo, is it to reduce noise that would cause weird sounds? Seems to work fine without one.

joshi

2 years ago

I placed the resistor there because it was also there in the original project. Didn't think of trying it without. But it's good to hear it works too without a resistor!

Anonymous user

7 years ago

Getting a fatal error avr\\interrupt,h no file or directory.

joshi

2 years ago

You probably have to include the library pitches.h first. Forgot to mention that in my post, but I have edited it. Instructions for pitches.h are here: https://www.arduino.cc/en/Tutorial/toneMelody You can also put it directly in your code.

Anonymous user

2 years ago

These instructions how to import library file using .zip procedures. Here I'm downloading a .ino