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

Picture of 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)

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:

Step 1: Example: the Imperial March

Picture of 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 !

The Imperial March

and a video that I made:

Step 2: Well Done !

Picture of Well Done !

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


samuraijack (author)2014-01-03


NurullahM (author)2015-08-24

i made this. thanks

Very nice...

AbhishekC37 (author)NurullahM2016-01-17

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

Please help...

Thank You

x.h (author)2017-05-09


notak (author)2017-01-08


Aidil Salihin (author)2016-12-28

thank you so much! now i so excited

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

ManuelA70 (author)2016-08-07

Thanks! Work perfect!! Im happy now hahahaa

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.

Jean0x7BE (author)2016-04-29

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

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

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

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.

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

Thanks man, that is awesome!!!

lucianom11 (author)2016-02-21

Thanks dude, pretty good library!!!

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

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

Syntaxian (author)ohoilett2016-01-09

Awesome work! Love this library.

ohoilett (author)Syntaxian2016-01-11

Awesome. Glad someone finds it useful.

chadS1 (author)ohoilett2015-03-01

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

ohoilett (author)chadS12015-03-01

Yeah for sure. Glad it worked out for you.

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

Works excellently. Thank you.

DawnetteB1 (author)2015-12-10

Yes it works on Arduino, just made this!

felpadon (author)2015-11-18

does it work on the arduino UNO?

RodrigoI4 (author)2015-10-17

Thank you man. This is so funny and simple.

WhiteRenard (author)2015-10-12

This is freaking awesome!

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"

ahui6 (author)2015-08-17


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.

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

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

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

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.

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

CPUCHE (author)2014-06-03


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: Until sec 28. Only the first page. This is the link in Youtube: Until sec 16.

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

tankapotamus (author)CPUCHE2014-09-15

I think this is what you need,yuomay want to check

alopes8 (author)2014-02-24


alopes8 (author)2014-02-24


alopes8 (author)2014-02-24


audreyobscura (author)2013-12-05

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

eserra (author)audreyobscura2013-12-07

done ;) thanks

About This Instructable




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