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

223,949

97

31

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 !

7 People Made This Project!

Recommendations

  • Pi Day Speed Challenge

    Pi Day Speed Challenge
  • Trash to Treasure Contest

    Trash to Treasure Contest
  • Microcontroller Contest

    Microcontroller Contest

31 Comments

0
gberl001
gberl001

1 year ago

"Impressive...Most Impressive" - Darth

0
AbhishekC37
AbhishekC37

Reply 5 years ago

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

Please help...

Thank You

0
x.h
x.h

3 years ago

THANKS A LOT

0
notak
notak

4 years ago

THANKS !!!!

0
Aidil Salihin
Aidil Salihin

4 years ago

thank you so much! now i so excited

0
Paladin Fade.
Paladin Fade.

4 years ago

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

0
ManuelA70
ManuelA70

4 years ago

Thanks! Work perfect!! Im happy now hahahaa

0
Vexelius
Vexelius

4 years ago

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.

0
Jean0x7BE
Jean0x7BE

4 years ago

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

0
ArifSae
ArifSae

4 years ago

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.

0
JiříM9
JiříM9

4 years ago

Thanks man, that is awesome!!!

0
lucianom11
lucianom11

5 years ago

Thanks dude, pretty good library!!!

0
DawnetteB1
DawnetteB1

5 years ago

Yes it works on Arduino, just made this!

0
felpadon
felpadon

5 years ago

does it work on the arduino UNO?

0
RodrigoI4
RodrigoI4

5 years ago

Thank you man. This is so funny and simple.

0
WhiteRenard
WhiteRenard

5 years ago

This is freaking awesome!

0
MauiJerry
MauiJerry

5 years ago

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"