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

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:
<p>does it work on the arduino UNO?</p>
<p>Thank you man. This is so funny and simple.</p>
<p>This is freaking awesome!</p>
<p>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.</p><p>This is good coding practice - &quot;Avoid Magic Numbers&quot;</p>
<p><iframe allowfullscreen="" frameborder="0" height="281" src="//www.youtube.com/embed/3X76LXWxORQ" width="500"></iframe></p><p>i made this. thanks </p>
<p>Thanks a million. Now I can incorporate this tune with the paper craft Darth Vader bust which I will be assembling.</p>
<p>I made it! It was a very fun and entertaining project. Thanks for sharing it!</p>
<p>This was a very entertaining compilation and I can only imagine how long it took to figure out all of the frequencies. Stay Imperial! ;)</p>
<p>This was really helpful for what I need to do. I actually put together a MusicPlayer library based on this. Here is the link</p><p><a href="https://drive.google.com/open?id=0BxuS3a9LkLcBRjJJdFcweWtXbzg&authuser=0" rel="nofollow">https://drive.google.com/open?id=0BxuS3a9LkLcBRjJJ...</a></p><p>It's pretty simple. If you have any feedback that would be great.</p>
<p>My daughter got a kick out of this. Thank you so much for putting it together.</p>
<p>Yeah for sure. Glad it worked out for you.</p>
<p>I have plans to come to the dark side after running the sketch. Good job, and may the force be with you.</p>
<p>Great job. Simple and nice. I just tryied it and it worked easy and at the first attempt ;-)</p>
<p>Hi!!!</p><p>I want to do something like that. I don't know if you can help me.</p><p>I have the melody and the sheet music, but I need to know the notes for arduino... just like you did.</p><p>this are the links: </p><p><a href="https://www.youtube.com/watch?v=vJMvCEaOpyw" rel="nofollow">https://www.youtube.com/watch?v=vJMvCEaOpyw </a> Until sec 28.</p><p><a href="http://ebookbrowsee.net/gdoc.php?id=399890027&url=e9564b4165df199ecfc478f7f9e96857" rel="nofollow">http://ebookbrowsee.net/gdoc.php?id=399890027&amp;url=...</a> Only the first page. This is the link in Youtube: <a href="https://www.youtube.com/watch?v=vq7HOgjPZXU" rel="nofollow">https://www.youtube.com/watch?v=vq7HOgjPZXU </a> Until sec 16. </p><p>Thanks for your help. I'll be waiting for your reply :)</p>
<p>I think this is what you need http://arduino.cc/en/Reference/Tone,yuomay want to check http://arduino.cc/en/Reference/HomePage</p>
Hey that video is set to private, mind making it public?
done ;) thanks

About This Instructable


59 favorites


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