Super Mario theme song w/ piezo buzzer and Arduino!

Today I found a complete post on how to play Super Mario Bros theme song on a piezo buzzer! It’s very simple and fun, and great as a beginner Arduino project.
All fame goes to Dipto Pratyaksa for making the Sketch code and sharing it with us!

I modified the code posted by Dipto and added the PWM-pitches in directly into the Sketch, so you don’t have to mess around with Arduino libraries!

Original post:
http://www.linuxcircle.com/2013/03/31/playing-mario-bros-tune-with-arduino-and-piezo-buzzer/

Hardware requirements

  • An Arduino(I used an Arduino Nano, any other is fine)
  • Piezo buzzer
  • 1 k ohm resistor(any resistor between 333 ohm to 1 k  should be fine in this project)
  • A breadboard
  • Some breadboard cable(s)

Connecting the components

If you have an Arduino Uno(which most people have), connect the components with the help of the image below. If you have an Arduino Nano, look the the image in “Using an Arduino Nano”.

Connect the positive side of the buzzer to digital pin 3, then the negative side to a 1k ohm resistor. Connect the other side of the 1 k ohm resistor to ground(GND) pin on the Arduino. Remember to connect the buzzer the right way, the buzzer has positive and negative pins!

So basically the buzzer, 1 k ohm resistor and Arduino should be connected like this:
Arduino digital pin 3 –> Buzzer –> 1 k ohm resisotor –> Arduino ground(GND) pin.

You can actually do without the 1 k ohm resistor! If you connect without the resistor, the buzzer will be a lot louder, and the sound quality might degrade. But you can also lower the resistance to get a little louder sound, and keep the sound quality. Another idea is using a potentiometer instead of a resistor to act as a volume controller! For this tutorial we’ll just be using a 1 k ohm resistor.

Using an Arduino Uno

Below is an illustration of how to connect the buzzer and resistor to an Arduino Uno.

buzzeruno

Using an Arduino Nano

Below is an illustration of how to connect the buzzer and resistor to an Arduino Nano.

buzzer

Uploading the code

There is a pretty huge amount of code in this Sketch. Just press the “Copy” button on the top right of the code text field for it to automatically highlight the whole code for you.

/*
  Arduino Mario Bros Tunes
  With Piezo Buzzer and PWM

  Connect the positive side of the Buzzer to pin 3,
  then the negative side to a 1k ohm resistor. Connect
  the other side of the 1 k ohm resistor to
  ground(GND) pin on the Arduino.

  by: Dipto Pratyaksa
  last updated: 31/3/13
*/

/*************************************************
 * 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

#define melodyPin 3
//Mario main theme melody
int melody[] = {
  NOTE_E7, NOTE_E7, 0, NOTE_E7,
  0, NOTE_C7, NOTE_E7, 0,
  NOTE_G7, 0, 0,  0,
  NOTE_G6, 0, 0, 0,

  NOTE_C7, 0, 0, NOTE_G6,
  0, 0, NOTE_E6, 0,
  0, NOTE_A6, 0, NOTE_B6,
  0, NOTE_AS6, NOTE_A6, 0,

  NOTE_G6, NOTE_E7, NOTE_G7,
  NOTE_A7, 0, NOTE_F7, NOTE_G7,
  0, NOTE_E7, 0, NOTE_C7,
  NOTE_D7, NOTE_B6, 0, 0,

  NOTE_C7, 0, 0, NOTE_G6,
  0, 0, NOTE_E6, 0,
  0, NOTE_A6, 0, NOTE_B6,
  0, NOTE_AS6, NOTE_A6, 0,

  NOTE_G6, NOTE_E7, NOTE_G7,
  NOTE_A7, 0, NOTE_F7, NOTE_G7,
  0, NOTE_E7, 0, NOTE_C7,
  NOTE_D7, NOTE_B6, 0, 0
};
//Mario main them tempo
int tempo[] = {
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,

  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,

  9, 9, 9,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,

  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,

  9, 9, 9,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
};
//Underworld melody
int underworld_melody[] = {
  NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,
  NOTE_AS3, NOTE_AS4, 0,
  0,
  NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,
  NOTE_AS3, NOTE_AS4, 0,
  0,
  NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,
  NOTE_DS3, NOTE_DS4, 0,
  0,
  NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,
  NOTE_DS3, NOTE_DS4, 0,
  0, NOTE_DS4, NOTE_CS4, NOTE_D4,
  NOTE_CS4, NOTE_DS4,
  NOTE_DS4, NOTE_GS3,
  NOTE_G3, NOTE_CS4,
  NOTE_C4, NOTE_FS4, NOTE_F4, NOTE_E3, NOTE_AS4, NOTE_A4,
  NOTE_GS4, NOTE_DS4, NOTE_B3,
  NOTE_AS3, NOTE_A3, NOTE_GS3,
  0, 0, 0
};
//Underwolrd tempo
int underworld_tempo[] = {
  12, 12, 12, 12,
  12, 12, 6,
  3,
  12, 12, 12, 12,
  12, 12, 6,
  3,
  12, 12, 12, 12,
  12, 12, 6,
  3,
  12, 12, 12, 12,
  12, 12, 6,
  6, 18, 18, 18,
  6, 6,
  6, 6,
  6, 6,
  18, 18, 18, 18, 18, 18,
  10, 10, 10,
  10, 10, 10,
  3, 3, 3
};

void setup(void)
{
  pinMode(3, OUTPUT);//buzzer
  pinMode(13, OUTPUT);//led indicator when singing a note

}
void loop()
{
  //sing the tunes
  sing(1);
  sing(1);
  sing(2);
}
int song = 0;

void sing(int s) {
  // iterate over the notes of the melody:
  song = s;
  if (song == 2) {
    Serial.println(" 'Underworld Theme'");
    int size = sizeof(underworld_melody) / sizeof(int);
    for (int thisNote = 0; thisNote < size; thisNote++) {

      // to calculate the note duration, take one second
      // divided by the note type.
      //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
      int noteDuration = 1000 / underworld_tempo[thisNote];

      buzz(melodyPin, underworld_melody[thisNote], noteDuration);

      // to distinguish the notes, set a minimum time between them.
      // the note's duration + 30% seems to work well:
      int pauseBetweenNotes = noteDuration * 1.30;
      delay(pauseBetweenNotes);

      // stop the tone playing:
      buzz(melodyPin, 0, noteDuration);

    }

  } else {

    Serial.println(" 'Mario Theme'");
    int size = sizeof(melody) / sizeof(int);
    for (int thisNote = 0; thisNote < size; thisNote++) {

      // to calculate the note duration, take one second
      // divided by the note type.
      //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
      int noteDuration = 1000 / tempo[thisNote];

      buzz(melodyPin, melody[thisNote], noteDuration);

      // to distinguish the notes, set a minimum time between them.
      // the note's duration + 30% seems to work well:
      int pauseBetweenNotes = noteDuration * 1.30;
      delay(pauseBetweenNotes);

      // stop the tone playing:
      buzz(melodyPin, 0, noteDuration);

    }
  }
}

void buzz(int targetPin, long frequency, long length) {
  digitalWrite(13, HIGH);
  long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions
  //// 1 second's worth of microseconds, divided by the frequency, then split in half since
  //// there are two phases to each cycle
  long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing
  //// multiply frequency, which is really cycles per second, by the number of seconds to
  //// get the total number of cycles to produce
  for (long i = 0; i < numCycles; i++) { // for the calculated length of time...
    digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphram
    delayMicroseconds(delayValue); // wait for the calculated delay value
    digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram
    delayMicroseconds(delayValue); // wait again or the calculated delay value
  }
  digitalWrite(13, LOW);

}

After uploading the Sketch-code, your Arduino should start playing!

If you have any questions feel free to ask me by using the Contact page or by commenting below.

Prince

A second year computer engineering student at Malmö University in Sweden just having some fun with this blog. Computer Engineering and Mobile IT: Bachelor of Science in engineering

You may also like...

190 Responses

  1. I enjoy what you guys tend to be up too. This sort of
    clever work and exposure! Keep up the excellent works guys I’ve incorporated
    you guys to our blogroll.

  2. Thanks for one’s marvelous posting! I actually enjoyed reading it, you could be a great author.I will remember to bookmark your blog and
    definitely will come back sometime soon. I want to encourage you to ultimately continue your great work,
    have a nice weekend!

  3. Émissions Tv says:

    Spot on with this write-up, I really feel this web site needs much
    more attention. I’ll probably be returning to read more,
    thanks for the info!

  4. I go to see each day some web sites and information sites to read articles, but
    this webpage provides quality based articles.

  5. console playstation 4 pas cher says:

    Thanks in favor of sharing such a fastidious thought, article is pleasant,
    thats why i have read it entirely

  6. tente reception 3x9 says:

    I like the helpful info you provide in your articles. I’ll bookmark your weblog and
    check again here frequently. I’m quite sure I will learn many new
    stuff right here! Good luck for the next!

  7. theme cydia 2014 says:

    I was wondering if you ever thought of changing the structure of your
    site? Its very well written; I love what youve got to say.
    But maybe you could a little more in the way of content so people could connect
    with it better. Youve got an awful lot of text for only having
    1 or two pictures. Maybe you could space it out better?

    • Prince says:

      Thank you for the well-structured feedback! I added another line break before every heading-title in the article. It might not be much of a difference but I don’t want to change it too much so it actually gets more ugly. Can I have your opinion of the updated layout? And if you have any more suggestions for improvements, don’t be a stranger!

  8. replica hermes birkin says:

    I am curious to find out what blog platform you are working with?
    I’m experiencing some minor security issues with my latest site
    and I’d like to find something more secure.
    Do you have any recommendations?

  9. kate spade diaper bag says:

    I’ll immediately grasp your rss feed as I can not to find your e-mail subscription link or newsletter service.
    Do you have any? Kindly let me recognize in order that I may subscribe.
    Thanks.

  10. giuseppe zanotti men says:

    This is a topic which is close to my heart… Best wishes!
    Where are your contact details though?

  11. test kitchen says:

    It’s actually a cool and useful piece of info. I’m satisfied that you
    shared this useful info with us. Please stay us informed like this.
    Thank you for sharing.

  12. Hi to all, it’s in fact a nice for me to visit this site, it consists
    of important Information.

  13. asphalt 8 airborne cheats says:

    Fantastic items from you, man. I have be aware your stuff
    previous to and you are simply too fantastic. I really like what you have obtained here,
    really like what you’re saying and the way in which by which you
    say it. You make it enjoyable and you still take care
    of to keep it sensible. I can’t wait to learn much more from
    you. This is really a wonderful site.

  14. Hungry Shark evolution Gems cheat says:

    I’m impressed, I must say. Seldom do I encounter a blog that’s equally educative and amusing, and without a doubt, you’ve
    hit the nail on the head. The issue is something that too few folks
    are speaking intelligently about. I’m very happy I came across this in my hunt for something regarding this.

  15. What’s up, I check your new stuff on a regular basis.
    Your writing style is witty, keep it up!

  16. Hello, I wish for to subscribe for this blog to
    obtain hottest updates, so where can i do it please help.

  17. kiNi4PFYAjI says:

    572077 225451Its like you read my mind! You appear to know a whole lot about this, like you wrote the book in it or something. I believe which you could do with several pics to drive the message home a bit, but other than that, this really is wonderful weblog. A fantastic read. I

  18. Dell says:

    I do not know whether it’s just me or if perhaps everybody else encountering issues with your blog.
    It seems like some of the written text on your content are running
    off the screen. Can someone else please provide feedback and let me
    know if this is happening to them as well? This might be a
    issue with my web browser because I’ve had this happen previously.
    Cheers

  19. Thanks for the gkod writeup. It actually was a enjoyment account it.
    Glance complicatewd to more delivered agreeable from you!
    However, how could we be in contact?

  20. Your mode of explaining the whole thing in this post is actually good, every one caan simply be aware of it, Thanks
    a lot.

  21. Donovan Reynolds says:

    Try this modified code right here. Same circuit, better sound:

    http://txt.do/ddmv4

  22. Menion says:

    Hi, i have a buzzer 9v, how can connect the battery with this circuit? The sound is very low. Thanks.

  23. Offset says:

    I’ve connected Arduino to a stepper motor driver, and it did play Mario theme using a motor quite well after a little bit of tweaking )) Thanks a lot!

  24. Shou says:

    Nice work 🙂 Just forgot to write Serial.begin(9600)

  25. Sounds good! 🙂

  26. Matthew says:

    It was so earrape without resistor so I had to upload BareMinimum

  27. Indruto says:

    nice i already test and it works well 😀

    Thanks for sharing

  28. Ben says:

    I tried to upload it and all I got was this “sketch_jan06a:14: error: stray ‘\302’ in program”

  29. Jinho Choi says:

    WOW THE BEST!!!

  30. HYUNJUN KIN says:

    It’s a best song ever!!

  31. Timalsina Raju says:

    Thanks a lot. I enjoy listening its sounds and lyrics!!!

  32. Somen Jana says:

    How to play an Indian Music?
    A demo of a RabindraSangeet (Song by Rabindra Nath Tgore — Nobel Laureates in literature, 1913) is shown in the following link:

    https://www.youtube.com/watch?v=yWdUYZahaUU

  33. jackson says:

    Thanks for the example! I can play Mario through a motor and that makes me happy 🙂

  34. m says:

    i have this error
    exit status 1
    ‘NOTE_E7’ was not declared in this scope

  35. 86Shauna says:

    I have noticed you don’t monetize your website, don’t waste your traffic, you
    can earn additional bucks every month because you’ve got hi quality content.
    If you want to know how to make extra money, search for: best adsense alternative Wrastain’s tools

  36. love spells says:

    Hi there,I log on to your blogs named “Super Mario theme song w/ piezo buzzer and Arduino! | PrinceTronics” regularly.Your humoristic style is witty, keep doing what you’re doing! And you can look our website about love spells.

  37. Que você faz para acumular força elétrica? http://queromeudinheiro.com

  38. bob says:

    it’s a very boring expeirients

  39. LastPaul says:

    I see you don’t monetize your site, don’t waste your traffic, you can earn additional cash every month because you’ve got hi quality
    content. If you want to know how to make extra bucks, search for: Mertiso’s tips
    best adsense alternative

  40. krutika says:

    sir u can post report on arduino piano

  41. kenneth says:

    what if i need 2 seconds, or 4 seconds of note tempo??
    what code im ganno use on tempo
    only 1 sec is declared there

    thanks in advance
    tha

  42. dick says:

    your ma gae

  43. MylesBiggie says:

    Hi admin, i’ve been reading your page for some time
    and I really like coming back here. I can see that you probably don’t make
    money on your website. I know one awesome method of earning money, I think you will
    like it. Search google for: dracko’s tricks

  44. vicsar says:

    This is awesome. I like the modifications done. Thanks.

  45. BestMaik says:

    I see you don’t monetize your website, don’t
    waste your traffic, you can earn extra cash every month.
    You can use the best adsense alternative for any type of website (they approve all websites), for more info simply search
    in gooogle: boorfe’s tips monetize your website

  46. This is veryreally interesting, You areYou’re a very skilled blogger. I haveI’ve joined your feedrss feed and look forward to seeking more of your greatwonderfulfantasticmagnificentexcellent post. Also, I haveI’ve shared your siteweb sitewebsite in my social networks!

  47. Seth says:

    Hey i modified this a bit so that when i pressed the button it would change the song but it only works if the button is down while the song ends and it only switches the main theme to the underground theme and not the other way around how do i fix this?

    code:

    /*
    Arduino Mario Bros Tunes
    With Piezo Buzzer and PWM

    Connect the positive side of the Buzzer to pin 3,
    then the negative side to a 1k ohm resistor. Connect
    the other side of the 1 k ohm resistor to
    ground(GND) pin on the Arduino.

    by: Dipto Pratyaksa
    last updated: 31/3/13
    */

    /*************************************************
    * Public Constants
    *************************************************/

    int switchPin = 7;
    int songNum = 1;

    #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

    #define melodyPin 3
    //Mario main theme melody
    int melody[] = {
    NOTE_E7, NOTE_E7, 0, NOTE_E7,
    0, NOTE_C7, NOTE_E7, 0,
    NOTE_G7, 0, 0, 0,
    NOTE_G6, 0, 0, 0,

    NOTE_C7, 0, 0, NOTE_G6,
    0, 0, NOTE_E6, 0,
    0, NOTE_A6, 0, NOTE_B6,
    0, NOTE_AS6, NOTE_A6, 0,

    NOTE_G6, NOTE_E7, NOTE_G7,
    NOTE_A7, 0, NOTE_F7, NOTE_G7,
    0, NOTE_E7, 0, NOTE_C7,
    NOTE_D7, NOTE_B6, 0, 0,

    NOTE_C7, 0, 0, NOTE_G6,
    0, 0, NOTE_E6, 0,
    0, NOTE_A6, 0, NOTE_B6,
    0, NOTE_AS6, NOTE_A6, 0,

    NOTE_G6, NOTE_E7, NOTE_G7,
    NOTE_A7, 0, NOTE_F7, NOTE_G7,
    0, NOTE_E7, 0, NOTE_C7,
    NOTE_D7, NOTE_B6, 0, 0
    };
    //Mario main them tempo
    int tempo[] = {
    12, 12, 12, 12,
    12, 12, 12, 12,
    12, 12, 12, 12,
    12, 12, 12, 12,

    12, 12, 12, 12,
    12, 12, 12, 12,
    12, 12, 12, 12,
    12, 12, 12, 12,

    9, 9, 9,
    12, 12, 12, 12,
    12, 12, 12, 12,
    12, 12, 12, 12,

    12, 12, 12, 12,
    12, 12, 12, 12,
    12, 12, 12, 12,
    12, 12, 12, 12,

    9, 9, 9,
    12, 12, 12, 12,
    12, 12, 12, 12,
    12, 12, 12, 12,
    };
    //Underworld melody
    int underworld_melody[] = {
    NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,
    NOTE_AS3, NOTE_AS4, 0,
    0,
    NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,
    NOTE_AS3, NOTE_AS4, 0,
    0,
    NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,
    NOTE_DS3, NOTE_DS4, 0,
    0,
    NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,
    NOTE_DS3, NOTE_DS4, 0,
    0, NOTE_DS4, NOTE_CS4, NOTE_D4,
    NOTE_CS4, NOTE_DS4,
    NOTE_DS4, NOTE_GS3,
    NOTE_G3, NOTE_CS4,
    NOTE_C4, NOTE_FS4, NOTE_F4, NOTE_E3, NOTE_AS4, NOTE_A4,
    NOTE_GS4, NOTE_DS4, NOTE_B3,
    NOTE_AS3, NOTE_A3, NOTE_GS3,
    0, 0, 0
    };
    //Underwolrd tempo
    int underworld_tempo[] = {
    12, 12, 12, 12,
    12, 12, 6,
    3,
    12, 12, 12, 12,
    12, 12, 6,
    3,
    12, 12, 12, 12,
    12, 12, 6,
    3,
    12, 12, 12, 12,
    12, 12, 6,
    6, 18, 18, 18,
    6, 6,
    6, 6,
    6, 6,
    18, 18, 18, 18, 18, 18,
    10, 10, 10,
    10, 10, 10,
    3, 3, 3
    };

    void setup(void)
    {
    pinMode(3, OUTPUT);//buzzer
    pinMode(13, OUTPUT);//led indicator when singing a note
    pinMode(switchPin, INPUT_PULLUP);

    }
    void loop()
    {
    //sing the tunes
    if (digitalRead(switchPin) == LOW)
    {
    if (songNum = 1)
    {
    songNum = 2;
    }
    else if(songNum = 2)
    {
    songNum = 1;
    }
    }

    sing(songNum);
    }
    int song = 0;

    void sing(int s) {
    // iterate over the notes of the melody:
    song = s;
    if (song == 2) {
    Serial.println(” ‘Underworld Theme'”);
    int size = sizeof(underworld_melody) / sizeof(int);
    for (int thisNote = 0; thisNote < size; thisNote++) {

    // to calculate the note duration, take one second
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000 / underworld_tempo[thisNote];

    buzz(melodyPin, underworld_melody[thisNote], noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);

    // stop the tone playing:
    buzz(melodyPin, 0, noteDuration);

    }

    } else {

    Serial.println(" 'Mario Theme'");
    int size = sizeof(melody) / sizeof(int);
    for (int thisNote = 0; thisNote < size; thisNote++) {

    // to calculate the note duration, take one second
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000 / tempo[thisNote];

    buzz(melodyPin, melody[thisNote], noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);

    // stop the tone playing:
    buzz(melodyPin, 0, noteDuration);

    }
    }
    }

    void buzz(int targetPin, long frequency, long length) {
    digitalWrite(13, HIGH);
    long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions
    //// 1 second's worth of microseconds, divided by the frequency, then split in half since
    //// there are two phases to each cycle
    long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing
    //// multiply frequency, which is really cycles per second, by the number of seconds to
    //// get the total number of cycles to produce
    for (long i = 0; i < numCycles; i++) { // for the calculated length of time…
    digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphram
    delayMicroseconds(delayValue); // wait for the calculated delay value
    digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram
    delayMicroseconds(delayValue); // wait again or the calculated delay value
    }
    digitalWrite(13, LOW);

    }

  48. Mars says:

    Hi. How would I make my own song. Let’s say I have the notes for the song like Happy Birthday, how do I make it play with a rhythm or specific beat instead of a flat boring pace?

  49. Kostas says:

    Hi there, really nice techno-art, tnx for sharing!

    any idea how to modify the below code for use in time sensitive loops?
    (due to “delayMicroseconds” the loop interrupted)

    void buzz(int targetPin, long frequency, long length) {
    digitalWrite(13, HIGH);
    long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions
    //// 1 second’s worth of microseconds, divided by the frequency, then split in half since
    //// there are two phases to each cycle
    long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing
    //// multiply frequency, which is really cycles per second, by the number of seconds to
    //// get the total number of cycles to produce
    for (long i = 0; i < numCycles; i++) { // for the calculated length of time…
    digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphram
    delayMicroseconds(delayValue); // wait for the calculated delay value
    digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram
    delayMicroseconds(delayValue); // wait again or the calculated delay value
    }
    digitalWrite(13, LOW);

  50. hael husaino says:

    what the hell

  51. LIL PUMP says:

    OLA SOI AURONPLEY

  52. Shark Youtube to mp3 Online

  53. peanut plays says:

    sub 2 peanut plays on youtube

  54. cant hear it mate, whats going on here. feeling like shit and this sure doesnt help pal. was at a 5 star hotel and greeted home with you, shithead. send help, please, ill do anything. your wife is hot

  55. shea says:

    Hi, my name is Shea Rutledge!

    I`m a professional writer and I`m going to change your lifes onсe and for all
    Writing has been my passion for a long time and now I cannot imagine my life without it.
    Most of my books were sold throughout Canada, USA, China and even Australia. Also I`m working with services that help people to save their time.
    People ask me “Mr, Shea Rutledge, I need your professional help” and I always accept the request, `cause I know, that only I can solve all their problems!

    Professional Writer – Shea Rutledge – http://www.studioahz.comCorps

  56. Awesome post! Keep up the great work!

  57. Victorvug says:

    Interesting idea luorennetpcopsubs.gq

  58. Elvin Witz says:

    Weight Loss Guaranteed

  59. In addition to the poker operate, they will be a raffle, meals and entertainment. It grew to become even more well-liked online because no reside dealers or tables are required. The card dealing position will rotate amongst players.

  60. Georgeraina says:

    тв в прямом эфире – tv en direct sur internet, Telewizja internetowa

  61. RobertJig says:

    Смотреть ТВ онлайн – Ver Tv Online, TV Online izle

  62. Rickeyjet says:

    идеальный веб сайт томск стоматология

  63. WilliamWen says:

    OVI trickets neccesitate most of the skilled tools used in criminal defense courts. Defending a DWI is initiated by acknowledging none of a persons constitutional rights are trespassed. When law enforcement is in front of you, and they are basically the only witness most of the time, the training and procedural conduct is of the essence. We all make mistakes, and officers are no exception. The Occasion starts with usual accusation that can lead to probable cause. For example, someone gets flashed over for driving too slow at 3 AM. The officer takes reasonable suspicion that you committed a moving violation, speeding. then, when the officer tries to make eye contact or moves in closer to the auto, they may utter you exhibit red eyes, or there is an smell of beer. This elevates the acceptabel suspicion of speeding to providing the officer a fact that you is crusing around while under the influence. 99.9% of law enforcement will say smell of beer, red eyes, or lazy speech. Law enforcement will usually note you were fumbling about trying to get your id and registration out. Now the person driving is likely informed to get out from a auto and do regular field sobriety checks. Those are SFST’s are taught under NHTSA (National road Traffic precautionary Administration) regulations and need to be assumed per situation. when you do go through the tests, the officer may make mistakes which can have the check, or tests thrown out of from evidence. Factors such as physical disabilities and the best field conditions should be integrated into results of your field sobriety test. (i.e. you can not perform a jump and pivot test on crooked sidwalk). You may also take a digital breath tests. There are irregularities in these gadgets as well, after all they are devices that need maintenance and trained on regularly. The arrest is taped at the time the cop turns on their lights. It is through this taped footage we are able to secure an experienced idea if the police giving of the checks, to the accused ability taking the tests. Whether you give an OK to the tests or not, a person will go to lock up. If you have been arrested for Traffic Violations or any criminal charges or know some one who needs a criminal defense Attorney take a look at my site here first offense dui ohio penalty best regards

  64. Excellent site you have here but I was curious if you knew of any user discussion forums
    that cover the same topics talked about here?
    I’d really love to be a part of group where I can get suggestions
    from other experienced people that share the same interest.

    If you have any suggestions, please let me know.
    Bless you!

  65. Aw, this was a really good post. Spending some time and actual effort to create a superb articleÖ but what can I sayÖ I procrastinate a whole lot and never seem to get nearly anything done.

  66. VJ says:

    Hi there, just became alert to your blog through Google, and found
    that it’s truly informative. I’m gonna wtch outt for brussels.
    I’ll appreciate if you continue this in future. A lot of
    pople will be benefited from your writing. Cheers!

  67. JamesOxift says:

    добродетельный веб ресурс купить конфеты

  68. SH says:

    Hey there, You have done a fantastic job. I’ll definitely
    digg it and personally recommend to my friends. I am confident they will
    be benefited from this web site.

  69. Homerluche says:

    сайт omg omg не работает – omg omg onion, omg зеркало

  70. Jamesbab says:

    omg omg tor ссылка – omg omg сайт зеркало, сайт омг омг ссылка

  71. WilliamOxype says:

    сколько стоит квартира в дубае – недвижимость за границей дешевая, дом в америке купить недорого

  72. JerryBew says:

    правильная ссылка на омг – omg darknet market, омг зеркало

  73. GilbertCanda says:

    omg omg тор – официальная ссылка омг, омг омг ссылка на сайт

  74. TimothyPoope says:

    omg onion – сайт omg omg не работает, площадка omg ссылка

  75. GilbertOvelf says:

    my link https://coinwan.us/ – Coinwan bitcoin ethereum exchange, Coinwan – bitcoin exchange

  76. AaronGep says:

    Coinwan exchange cardano – Coinwan – lowest crypto fees, Coinwan exchange bitcoin to ethereum

  77. JamesDus says:

    купить стероиды в москве – гормон роста купить, кленбутерол купить

  78. AynAless says:

    Welcome to the world of adult Dating loveawake.ru

  79. MichaelClAse says:

    рулетка для бомжей от 1 рубля – рулетка кс го от 1, рулетка кс го от 1

  80. AlfredoTwipT says:

    алмазная коронка 45 – алмазная коронка 35, алмазная коронка 450 мм

  81. WilliePewop says:

    омг ссылка – омг, как зайти на омг

  82. constantly i used to read smaller articles which also clear their motive, and that is also
    happening with this paragraph which I am reading now.

  83. KermitMed says:

    создание сайта LoL – шаблоны сайта L2, создание сайта Perfect World

  84. Ellisrex says:

    Отели Котор – Обзор отелей Черногория, Черногория шопинг отзывы

  85. Hi there, I do believe your site may be having browser compatibility issues. Whenever I look at your blog in Safari, it looks fine but when opening in I.E., it’s got some overlapping issues. I merely wanted to provide you with a quick heads up! Besides that, wonderful site!

  86. JasonZex says:

    tor + vpn – избавим откредитов, даркнет маркет

  87. Vincentwaigo says:

    купить ключ SUPERHOT – купить ключ Gothic 3, купить ключи игр

  88. Robertdot says:

    фулфилмент целиком – фулфилмент для wildberries -ozon -москва -услуги, фулфилмент для вайлдберриз москва цена прайс

  89. AndrewBeego says:

    ремдесивир москва – Paxlovid где в наличии, Лагеврио аптеки

  90. TravisAnexy says:

    мотоциклы молдова – электрический трицикл купить, солнечные батареи цены

  91. Thanks for finally writing about > Super Mario theme song w/ piezo buzzer and Arduino!

    – PrinceTronics < Liked it!

  92. This web site really has all of the information and facts I wanted concerning this subject and didnít know who to ask.

  93. I’ve been surfing online more than 3 hours nowadays, yet I by no means discovered any fascinating article like yours. It is lovely value enough for me. In my opinion, if all website owners and bloggers made good content material as you did, the web will be much more useful than ever before.

  94. This info is priceless. Where can I find out more?

  95. Excellent blog here! Also your site loads up fast!
    What web host are you using? Can I get your affiliate link to your host?
    I wish my site loaded up as quickly as yours lol

  96. Edwardwalry says:

    new world carte – Heartgem Runes New World, new world healer build

  97. JasonGam says:

    купить мебель с доставкой – купить мебель с доставкой, заказать кровать

  98. Jamesroupt says:

    кс го читы купить – читы на апекс, кс 1.6 вх скачать

  99. hey there and thank you for your info ? I have certainly picked up something new from right here. I did however expertise some technical points using this site, as I experienced to reload the website lots of times previous to I could get it to load properly. I had been wondering if your hosting is OK? Not that I’m complaining, but slow loading instances times will sometimes affect your placement in google and can damage your quality score if ads and marketing with Adwords. Well I?m adding this RSS to my e-mail and could look out for much more of your respective interesting content. Ensure that you update this again soon..

  100. JosephSom says:

    Hello

    It is a fact of life that you will suddenly die some day and perhaps soon. Therefore, you must find out WHO IS OUR SAVIOR? Before you die and face him.

    Is everyone a sinner ?

    Go to

    https://internetmosque.net/saviour/index.html

    and find out the TRUTH before it is too late

    Piece

  101. Artificial intelligence creates content for the site, no worse than a copywriter, you can also use it to write articles. 100% uniqueness :). Click Here:👉 https://stanford.io/3FXszd0

  102. I was recommended this blog by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about my trouble. You are incredible! Thanks!

  103. I really love your site.. Pleasant colors & theme. Did you build this web site yourself? Please reply back as Iím hoping to create my very own blog and would love to learn where you got this from or exactly what the theme is named. Kudos!

  104. Good post. I learn something totally new and challenging on sites I stumbleupon everyday. It’s always exciting to read through articles from other authors and practice something from their websites.

  105. There’s definately a great deal to find out about this subject. I really like all of the points you made.

  106. This is the right website for anybody who wishes to find out about this topic. You understand so much its almost tough to argue with you (not that I actually would want toÖHaHa). You certainly put a new spin on a subject which has been written about for many years. Wonderful stuff, just wonderful!

  107. This blog was… how do I say it? Relevant!! Finally I’ve found something that helped me. Thanks!

  108. Williambex says:

    Carding and Hacking Tutorials & Tools – Best Logs cloud 10 TB, bank account shop

  109. PeterEndup says:

    Защита от колдовства – Порча на конкурентов, Амулет для торговли

  110. This website was… how do I say it? Relevant!! Finally I have found something which helped me. Appreciate it!

  111. I was more than happy to seek out this web-site.I wanted to thanks in your time for this wonderful read!! I undoubtedly enjoying every little bit of it and I’ve you bookmarked to take a look at new stuff you blog post.

  112. I discovered your blog website on google and check a couple of your early posts. Preserve up the very good operate. I merely additional the Rss to my MSN News Reader. Seeking forward to reading more on your part down the road!…

  113. You’ll find obviously quite a lot of details just like that to take into consideration. That´s a fantastic point to bring up. I offer the thoughts above as general inspiration but clearly you will discover questions like the one you bring up where the most very important thing definitely will be working in honest excellent faith. I don´t know if most useful practices have emerged around things just like that, but I am certain that your work is clearly identified as a fair game.

  114. BlaineBaisp says:

    добродушный ресурс купить конфеты

  115. This is the right website for anybody who hopes to understand this topic. You understand so much its almost tough to argue with you (not that I personally would want toÖHaHa). You certainly put a fresh spin on a subject that’s been discussed for a long time. Great stuff, just great!

  116. count says:

    I do not even know the ѡay І finished up here, һоweveг I thought this post was
    good. I don’t recognise wһo you are һowever certainly you are going to a well-known blߋgger should you aren’t already.
    Cheers!

  117. Good site you have got here.. Itís difficult to find high-quality writing like yours nowadays. I honestly appreciate individuals like you! Take care!!

  118. Charlesquary says:

    двойной памятник цена – памятники могилев гранит, памятники в могилеве с ценами

  119. models says:

    I think thіs is one of the most important infoгmation for mе.
    And i am glaɗ reading your article. Ᏼut want to remark on some general things, The web site style
    is perfect, the articleѕ is reɑlly excellent : D.
    Good jߋb, cheers

  120. rv shades says:

    Hello there! I could have sworn Iíve visited this site before but after browsing through many of the posts I realized itís new to me. Regardless, Iím definitely pleased I stumbled upon it and Iíll be bookmarking it and checking back regularly!

  121. This is a topic which is close to my heart… Many thanks! Exactly where are your contact details though?

  122. Did you write the article yourself or you hired someone
    to do it? I was wondering because I am a site owner too and
    struggle with writing new content all the time. Someone
    told me to use AI to do create articles which I am kinda considering because the
    output is almost written by human. Here is the sample content they sent me
    https://sites.google.com/view/best-ai-content-writing-tools/home

    Let me know if you think I should go ahead and use AI.

  123. RichardDrify says:

    visit this page Bali

  124. MichaelPefed says:

    сайт OMG OMG – сайт OMG OMG, омг ссылка

  125. Johnnyrooke says:

    сайт мега даркнет – mega sb, мега сайт даркнет ссылка

  126. Allenwaync says:

    netex24 – Обменник netex24, обменник netex24

  127. DanielRen says:

    bet365 – bet365, bet365 alternativ link

  128. May I simply just say what a relief to find someone that really understands what they are talking about online. You definitely realize how to bring an issue to light and make it important. More and more people have to look at this and understand this side of the story. I can’t believe you’re not more popular given that you definitely possess the gift.

  129. IsaacAgons says:

    bet365 betsonhand – bet365, bet365 belepes

  130. 2022 says:

    Hi there to all, the contents existing at this web
    site are in fact remarkable for people experience, well, keep up the good work fellows.

    Feel free to visit my website: 2022

  131. Man is the measure of all things.

  132. I don’t know whether it’s just me or if everyone else experiencing issues with your blog.
    It looks like some of the text in your content are
    running off the screen. Can someone else please comment and
    let me know if this is happening to them as well?
    This may be a problem with my internet browser because I’ve had this happen before.
    Appreciate it

    my webpage: tracfone special coupon 2022

  133. There is definately a lot to learn about this issue. I love all of the points you’ve made.

  134. Hello! I could have sworn Iíve been to this web site before but after looking at a few of the posts I realized itís new to me. Anyhow, Iím definitely pleased I found it and Iíll be bookmarking it and checking back regularly!

  135. Ralph C says:

    A Vacation Certificate for You, Your Family, Friends or Business Associates

  136. You made some really good points there. I checked on the internet for more info about the issue and found most individuals will go along with your views on this site.

  137. Billypub says:

    проститутки сургут – проститутки москвы, проститутки ярославль

  138. Victortroli says:

    Мебель – Мебель для кабинета, Заказать мебель

  139. MichaelHoole says:

    купить апартаменты в турции у моря – купить дом в америке, купить квартиру в газипаша турция

  140. I love it when folks get together and share views. Great blog, keep it up!

  141. areawide says:

    Verʏ ցo᧐d article. I certainly appreϲiate this website.
    Keep it up!

  142. Raymonddrasp says:

    гидравлическая насосная станция купить – электрическая гидравлическая станция, гидроцилиндр цена

  143. OliverDaype says:

    строительство домов ключ проекты и цены – проекты домов в ижевске строительство цены, строительство кирпичных домов

  144. Jamesvaw says:

    Отзыв: Самая отстойная компания, производитель мебели DeliveryMebel deliverymebel.ru
    Мебель самого незского качества,перед продажей вам дают гарантию и всякие обещания, но по факту предлогают везти бракованную Мебель к ним,конечно мало кто захочет нанемать грущиков с машиной и платить им туда и обратно за свой счёт, ещё не ясно какая будет транспартировка.И не какого своего эксперта они не пришлют, напрочь отмахиваются.
    Доска Авита их держит за проплату рекламмы https://www.avito.ru/user/9cce47af2babbbe7a5fab9a3140aa47e/profile?src=sharing
    Не связывайтесь с этим жульём!

  145. Excellent blog you have got here.. Itís hard to find quality writing like yours these days. I seriously appreciate people like you! Take care!!

  146. Hi, I do think this is a great site. I stumbledupon it 😉 I am going to come back once again since I saved as a favorite it. Money and freedom is the greatest way to change, may you be rich and continue to guide others.

  147. Anthonybrige says:

    Плуты тщатся вызвать язык вам глубокие чувства — испугать или обрадовать. Так они сбивают раз-два звона равным образом притупляют сверхбдительность потенциальной жертвы.

    Source:

    https://otsovik.com/

    Осторожно, мошенники! мошенничество

  148. Spot on with this write-up, I actually believe this web site needs a great deal more attention. Iíll probably be returning to read more, thanks for the information!

  1. 06/09/2014

    .

    tnx for info.

  2. 01/24/2015

    […] Supermario theme w/ piezo buzzer and android […]

  3. 02/21/2015

    […] Kaynağı: Princetronics Ana tema müziği ve Underworld müziği notaları kodlarda verilmiş. Kodları Arduino‘ya […]

  4. 04/28/2015
  5. 10/15/2015

    […] the piezo, which you can use to make 8 bit music and use as a vibration sensor. So I found a site (http://www.princetronics.com/supermariothemesong/) that would enable the Mario Theme…. to be […]

  6. 11/04/2015
  7. 11/16/2015

    […] code for “sing()” was found using a website that showed how to create the Super Mario Bros. Theme Song. Other than the actual melody that was played, I used the same structure as the code on this […]

Leave a Reply to ให้เช่ารถแบคโฮ Cancel reply

Your email address will not be published. Required fields are marked *