Thomas Fowler
Published

National Anthem Tank

I created a tank that plays the US National Anthem upon pressing a button (eagle eye). It is meant to be a fun way of being patriotic.

BeginnerFull instructions provided1 hour2,186
National Anthem Tank

Things used in this project

Hardware components

Arduino LilyPad USB
Arduino LilyPad USB
This is where the code for the tune is stored, and must connect with the buzzer and button to be able to play.
×1
LilyPad Buzzer
SparkFun LilyPad Buzzer
This is where the actual sound of the tune is emitted, upon pressing the button.
×1
LilyPad Button Board
SparkFun LilyPad Button Board
When pressed, this allows for the buzzer to make sound.
×1
Sewable Conductive Thread
Sewable Conductive Thread
Conductive thread connects each of the components to each other in the circuit.
×1

Software apps and online services

Arduino IDE
Arduino IDE
I referenced the "Play a Tune" tutorial in Arduino to learn how sound is emitted from the buzzer. I then coded the tune myself in Arduino, working with different note frequencies and lengths.

Story

Read more

Schematics

National Anthem Circuit Diagram

This is a diagram representing the embedded circuit in the tank. When a user presses the button, the music will begin to play from the buzzer. The entire tune must complete before it can be restarted, and it cannot be stopped midway.

Code

National Anthem

Arduino
I declared the frequencies for every note and coded the melody to the National Anthem. I made it so the user must press a button for the tune to begin playing. The entire tune must play through before the user can start from the beginning again.
int buzzer = A4;

int buttonTune = A9;


int NOTE_B0 = 31;
int NOTE_C1 = 33;
int NOTE_CS1 = 35;
int NOTE_D1 = 37;
int NOTE_DS1 = 39;
int NOTE_E1 = 41;
int NOTE_F1 = 44;
int NOTE_FS1 = 46;
int NOTE_G1 = 49;
int NOTE_GS1 = 52;
int NOTE_A1 = 55;
int NOTE_AS1 = 58;
int NOTE_B1 = 62;
int NOTE_C2 = 65;
int NOTE_CS2 = 69;
int NOTE_D2 = 73;
int NOTE_E2 = 82;
int NOTE_F2 = 87;
int NOTE_FS2 = 93;
int NOTE_G2 = 98;
int NOTE_GS2 = 104;
int NOTE_A2 = 110;
int NOTE_AS2 = 117;
int NOTE_B2 = 123;
int NOTE_C3 = 131;
int NOTE_CS3 = 139;
int NOTE_D3 = 147;
int NOTE_DS3 = 156;
int NOTE_E3 = 165;
int NOTE_F3 = 175;
int NOTE_FS3 = 185;
int NOTE_G3 = 196;
int NOTE_GS3 = 208;
int NOTE_A3 = 220;
int NOTE_AS3 = 233;
int NOTE_B3 = 247;
int NOTE_C4 = 262;
int NOTE_CS4 = 277;
int NOTE_D4 = 294;
int NOTE_DS4 = 311;
int NOTE_E4 = 330;
int NOTE_F4 = 349;
int NOTE_FS4 = 370;
int NOTE_G4 = 392;
int NOTE_GS4 = 415;
int NOTE_A4 = 440;
int NOTE_AS4 = 466;
int NOTE_B4 = 494;
int NOTE_C5 = 523;
int NOTE_CS5 = 554;
int NOTE_D5 = 587;
int NOTE_DS5 = 622;
int NOTE_E5 = 659;
int NOTE_F5 = 698;
int NOTE_FS5 = 740;
int NOTE_G5 = 784;
int NOTE_GS5 = 831;
int NOTE_A5 = 880;
int NOTE_AS5 = 932;
int NOTE_B5 = 988;
int NOTE_C6 = 1047;
int NOTE_CS6 = 1109;
int NOTE_D6 = 1175;
int NOTE_DS6 = 1245;
int NOTE_E6 = 1319;
int NOTE_F6 = 1397;
int NOTE_FS6 = 1480;
int NOTE_G6 = 1568;
int NOTE_GS6 = 1661;
int NOTE_A6 = 1760;
int NOTE_AS6 = 1865;
int NOTE_B6 = 1976;
int NOTE_C7 = 2093;
int NOTE_CS7 = 2217;
int NOTE_D7 = 2349;
int NOTE_DS7 = 2489;
int NOTE_E7 = 2637;
int NOTE_F7 = 2794;
int NOTE_FS7 = 2960;
int NOTE_G7 = 3136;
int NOTE_GS7 = 3322;
int NOTE_A7 = 3520;
int NOTE_AS7 = 3729;
int NOTE_B7 = 3951;
int NOTE_C8 = 4186;
int NOTE_CS8 = 4435;
int NOTE_D8 = 4699;
int NOTE_DS8 = 4978;


int tempo = 500;

void setup(){

  pinMode(buzzer, OUTPUT);
  pinMode(buttonTune, INPUT_PULLUP);

}

void loop()
{

  if(digitalRead(buttonTune) == LOW){

     tone(buzzer,NOTE_G5);
  delay(tempo);

  tone(buzzer,NOTE_E5);
  delay(tempo/3);

  tone(buzzer,NOTE_C5);
  delay(tempo);

  tone(buzzer,NOTE_E5);
  delay(tempo);

  tone(buzzer,NOTE_G5);
  delay(tempo);

  tone(buzzer,NOTE_C6);
  delay(tempo*2);

  tone(buzzer,NOTE_E6);
  delay(tempo);

  tone(buzzer,NOTE_D6);
  delay(tempo/3);

  tone(buzzer,NOTE_C6);
  delay(tempo);

    tone(buzzer,NOTE_E5);
  delay(tempo);

    tone(buzzer,NOTE_FS5);
  delay(tempo);

    tone(buzzer,NOTE_G5);
  delay(tempo*2);

    tone(buzzer,NOTE_G5);
  delay(tempo/3);

  tone(buzzer,NOTE_E6);
  delay(tempo*1.5);

   tone(buzzer,NOTE_D6);
  delay(tempo/3);

    tone(buzzer,NOTE_C6);
  delay(tempo);

    tone(buzzer,NOTE_B5);
  delay(tempo);

      tone(buzzer,NOTE_A5);
  delay(tempo);

   tone(buzzer,NOTE_B5);
  delay(tempo);

      tone(buzzer,NOTE_C6);
  delay(tempo);

        tone(buzzer,NOTE_C6);
  delay(tempo);

    tone(buzzer,NOTE_G5);
  delay(tempo);

     tone(buzzer,NOTE_E5);
  delay(tempo);

    tone(buzzer,NOTE_C5);
  delay(tempo);

    tone(buzzer,NOTE_E6);
  delay(tempo);

    tone(buzzer,NOTE_E6);
  delay(tempo/3);

    tone(buzzer,NOTE_E6);
  delay(tempo);

    tone(buzzer,NOTE_F6);
  delay(tempo/3);

    tone(buzzer,NOTE_G6);
  delay(tempo);

      tone(buzzer,NOTE_G6);
  delay(tempo);

      tone(buzzer,NOTE_F6);
  delay(tempo/2);

    tone(buzzer,NOTE_E6);
  delay(tempo/2);

     tone(buzzer,NOTE_D6);
  delay(tempo*2);

      tone(buzzer,NOTE_E6);
  delay(tempo/3);

        tone(buzzer,NOTE_F6);
  delay(tempo);

        tone(buzzer,NOTE_F6);
  delay(tempo);

         tone(buzzer,NOTE_F6);
  delay(tempo);

        tone(buzzer,NOTE_E6);
  delay(tempo);

       tone(buzzer,NOTE_D6);
  delay(tempo);

         tone(buzzer,NOTE_C6);
  delay(tempo);

         tone(buzzer,NOTE_B5);
  delay(tempo);

           tone(buzzer,NOTE_A5);
  delay(tempo);

           tone(buzzer,NOTE_B5);
  delay(tempo);

           tone(buzzer,NOTE_C6);
  delay(tempo);

           tone(buzzer,NOTE_C6);
  delay(tempo);

           tone(buzzer,NOTE_G5);
  delay(tempo);

          tone(buzzer,NOTE_E5);
  delay(tempo);

            tone(buzzer,NOTE_C5);
  delay(tempo);

             tone(buzzer,NOTE_G5);
  delay(tempo);

             tone(buzzer,NOTE_C6);
  delay(tempo);

               tone(buzzer,NOTE_C6);
  delay(tempo);

               tone(buzzer,NOTE_C6);
  delay(tempo/2);

               tone(buzzer,NOTE_B5);
  delay(tempo/2);

               tone(buzzer,NOTE_A5);
  delay(tempo);
  
               tone(buzzer,NOTE_A5);
  delay(tempo);
  
               tone(buzzer,NOTE_A5);
  delay(tempo);
                 tone(buzzer,NOTE_D6);
  delay(tempo);

                 tone(buzzer,NOTE_F6);
  delay(tempo/2);
                    tone(buzzer,NOTE_E6);
  delay(tempo/2);

                   tone(buzzer,NOTE_D6);
  delay(tempo/2);

                   tone(buzzer,NOTE_C6);
  delay(tempo/2);
  
                   tone(buzzer,NOTE_C6);
  delay(tempo);
  
                   tone(buzzer,NOTE_B5);
  delay(tempo*4);

                     tone(buzzer,NOTE_G5);
  delay(tempo);

                       tone(buzzer,NOTE_G5);
  delay(tempo);
  
                       tone(buzzer,NOTE_C6);
  delay(tempo*2);

                         tone(buzzer,NOTE_D6);
  delay(tempo/2);
  
                           tone(buzzer,NOTE_E6);
  delay(tempo/2);
  
                             tone(buzzer,NOTE_F6);
  delay(tempo/2);
  
                               tone(buzzer,NOTE_G6);
  delay(tempo*6);

                                 tone(buzzer,NOTE_C6);
  delay(tempo*1.5);

                                   tone(buzzer,NOTE_D6);
  delay(tempo*1.5);

                                   tone(buzzer,NOTE_E6);
  delay(tempo*2);

                                   tone(buzzer,NOTE_F6);
  delay(tempo);

                                     tone(buzzer,NOTE_D6);
  delay(tempo*2.5);

                                     tone(buzzer,NOTE_C6);
  delay(tempo*6);
    
    
  }

  else {
     noTone(buzzer);
 
  }

}

Credits

Thomas Fowler

Thomas Fowler

1 project • 0 followers

Comments