Introduction: How to Easily Play Music With Buzzer on Arduino (The Imperial March - STAR WARS)

Hi,I recently designed a sort of "library" in order to make easier to play exact notes on arduino with the buzzer.
I included the frequencies of the notes (pleasant to be heard) with #defines .
I then defined the value of the BPM ( you can modify it obviously) and according to that I defined the note values
( the most commonly used ones).
With this defines you can easyly play a note with the command "tone" like this:
tone(pin, note, duration)
eg:
tone(8,LA3,Q);
delay(1+Q);

the delay is important because thanks to that the note doesn't overlap possibly with the successive ones.
(the "1+" is one extra millisecond that i usually put to separate notes but you can avoid it if you prefer the notes to be continuous.

Here is the code:
ARDU NOTES
(http://tny.cz/d1a629c1)

Step 1: Example: the Imperial March

With a lot of effort I did it!
I wrote the code for the first part of the imperial march... so cool !

HERE IS THE CODE:
The Imperial March

and a video that I made:

Step 2: Well Done !

Now is your turn , make your arduino "whistle" all kinds of songs!
Hope you enjoyed this instructable !

Comments

author
samuraijack (author)2014-01-03

AWESOME

author
NurullahM (author)2015-08-24

i made this. thanks

author

Very nice...

author
AbhishekC37 (author)NurullahM2016-01-17

hey Nurullah, how did u connect buzzer with lcd & what was the code?

Please help...

Thank You

author
x.h (author)2017-05-09

THANKS A LOT

author
notak (author)2017-01-08

THANKS !!!!

author
Aidil Salihin (author)2016-12-28

thank you so much! now i so excited

author
Paladin Fade. (author)2016-10-04

its 2016 almost 2017 now. the current version of the arduino ide is not compatible with the code. what version of the ide are you using

author
ManuelA70 (author)2016-08-07

Thanks! Work perfect!! Im happy now hahahaa

author
Vexelius (author)2016-07-29

Thank you very much for this tutorial! It helped me to build my own tone system (which is fully compatible with millis), using yours as reference.

author
Jean0x7BE (author)2016-04-29

Excellent! Thanks for the nice job, it gave me an excellent Friday night! ;)

author
ArifSae made it! (author)2016-03-14

Thanks, i used it as one of sound in my project.

https://www.instructables.com/id/Jum-Jum-the-Jumping-Board/

IMG_20160314_134037.jpg
author
ArifSae (author)2016-03-10

Thanks. I am trying this. Just a humble suggestions, if a name of buzzer pin is used instead of 8 at all places, it would be easier to change buzzer pin. (using find and replace to do so). Thanks for sharing.

author
JiříM9 (author)2016-03-10

Thanks man, that is awesome!!!

author
lucianom11 (author)2016-02-21

Thanks dude, pretty good library!!!

author
ohoilett made it! (author)2015-01-07

This was really helpful for what I need to do. I actually put together a MusicPlayer library based on this. Here is the link

https://drive.google.com/open?id=0BxuS3a9LkLcBRjJJ...

It's pretty simple. If you have any feedback that would be great.

MusicPlayer.JPG
author
Syntaxian (author)ohoilett2016-01-09

Awesome work! Love this library.

author
ohoilett (author)Syntaxian2016-01-11

Awesome. Glad someone finds it useful.

author
chadS1 (author)ohoilett2015-03-01

My daughter got a kick out of this. Thank you so much for putting it together.

author
ohoilett (author)chadS12015-03-01

Yeah for sure. Glad it worked out for you.

author
Syntaxian made it! (author)2016-01-09

Works excellently. Thank you.

20160109_223839[1].jpg
author
DawnetteB1 (author)2015-12-10

Yes it works on Arduino, just made this!

author
felpadon (author)2015-11-18

does it work on the arduino UNO?

author
RodrigoI4 (author)2015-10-17

Thank you man. This is so funny and simple.

author
WhiteRenard (author)2015-10-12

This is freaking awesome!

author
MauiJerry (author)2015-10-06

Nice. However, if your code used a variable (or constant) for the buzzer pins, it would be a LOT easier to reuse in slightly different setups. For example the Sparkfun Protosnap comes with buzzer prewired on Pin2.

This is good coding practice - "Avoid Magic Numbers"

author
ahui6 (author)2015-08-17

U R A FREAKING GENUUUUUUUUUUISSSSSSSS

author
Dklawz (author)2015-08-08

Thanks a million. Now I can incorporate this tune with the paper craft Darth Vader bust which I will be assembling.

author
Fission_Chips made it! (author)2015-07-13

I made it! It was a very fun and entertaining project. Thanks for sharing it!

ImperialMarch.PNG
author
Murcielago38 (author)2015-05-03

This was a very entertaining compilation and I can only imagine how long it took to figure out all of the frequencies. Stay Imperial! ;)

author
rimolive made it! (author)2014-11-29

I have plans to come to the dark side after running the sketch. Good job, and may the force be with you.

IMG_20141129_231129201.jpg
author
roberto.petresco.1 (author)2014-10-02

Great job. Simple and nice. I just tryied it and it worked easy and at the first attempt ;-)

author
CPUCHE (author)2014-06-03

Hi!!!

I want to do something like that. I don't know if you can help me.

I have the melody and the sheet music, but I need to know the notes for arduino... just like you did.

this are the links:

https://www.youtube.com/watch?v=vJMvCEaOpyw Until sec 28.

http://ebookbrowsee.net/gdoc.php?id=399890027&url=... Only the first page. This is the link in Youtube: https://www.youtube.com/watch?v=vq7HOgjPZXU Until sec 16.

Thanks for your help. I'll be waiting for your reply :)

author
tankapotamus (author)CPUCHE2014-09-15

I think this is what you need http://arduino.cc/en/Reference/Tone,yuomay want to check http://arduino.cc/en/Reference/HomePage

author
alopes8 (author)2014-02-24

AMAZING DUDE!

author
alopes8 (author)2014-02-24

AMAZING DUDE!

author
alopes8 (author)2014-02-24

AMAZING DUDE!

author
audreyobscura (author)2013-12-05

Hey that video is set to private, mind making it public?

author
eserra (author)audreyobscura2013-12-07

done ;) thanks

About This Instructable

165,597views

88favorites

License:

More by eserra:How to easily play music with buzzer on arduino  (The imperial March - STAR WARS)
Add instructable to: