Project tutorial
Anchors Aweigh

Anchors Aweigh

Play Anchors Away to commemorate Veteran's Day 2018. Go Navy!

  • 851 views
  • 0 comments
  • 6 respects

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
Any Arduino with a pin 13 should work; if there is no pin 13, you should be able to just change the pin in the code.
×1
12002 04
Breadboard (generic)
Only needed if male-to-female wires are not available.
×1
Adafruit industries ada1536 image
Buzzer
An 8 ohm speaker should also work and may sound better.
×1
11026 02
Jumper wires (generic)
Male-to-male or male-to-female wires are needed; if male-to-female are used, the breadboard is not needed.
×2

Apps and online services

About this project

This project will play Anchors Aweigh on pin 13. It is based on the Jingle Bells sketch at gist.github.com/elubow/7844436. It was designed for Veteran's Day 2018. It is very simple to build.

To build the circuit, follow one of these sets of steps:

If male-to-female wires are available, insert one male end into the Arduino's GND pin and plug the buzzer or speaker's negative pin into the female end. Repeat this with a new wire, the buzzer's positive pin, and Arduino pin 13. Install the included sketch. Tip: If male-to-male and female-to-female wires are available, simply plug an end of a male-to-male wire into an end of a female-to-female wire. This can be used as a male-to-female wire.

If only male-to-male wires are available, the buzzer should be plugged into a breadboard. Place one wire in the Arduino's GND pin. Place the other end in a hole in the breadboard that is connected to the negative pin of the buzzer. Repeat this with a new wire, the buzzer's positive pin, and Arduino pin 13. Install the included sketch.

No licensing information was found for the original sketch. This version (or at least the modifications, if the original is under any license) is Public Domain.

Code

Anchors AweighArduino
/*
 * Based on the sketch found at https://gist.github.com/elubow/7844436.
 * The original sketch plays "Jingle Bells" repeatedly on pin 5.
 * This version plays "Anchors Aweigh" once on pin 13.
 * No licensing information was found for the original sketch. This version
 * (or at least the modifications, if the original is under any license) is
 * Public Domain.
 * 
 * Notes:
 *  Changed song to "Anchors Aweigh"
 *  Added line to prevent repeated playing
 *  Changed beats[] from int to float
 *  Added notes :
 *    D above high C* : D
 *    E above high C* : E
 *    F Sharp         : F
 --------------
      * Note: This is high C, not "high seas." Get it? Navy?
 */
int speakerPin = 13;
int length = 51;
char notes[] = "cegaeaCDgCaCagabCFadCbgfdcegaeaCDgCaCagabcEgFgDgfgC";
float beats[] = { 2, 1, 1,   1.5, 0.5, 2,  2, 1, 1,   4,  2, 1, 1,   1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  2, 1, 1,    1.5, 0.5, 2,    2, 1, 1,   4,  2, 1, 1,   1, 1, 1, 1, .75, .25, .5, .125, .75, .25, .5, .5,  4};

int tempo = 300;
void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}
void playNote(char note, int duration) {
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', 'D', 'E', 'F' };
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 901, 849, 1390 };

  // play the tone corresponding to the note name
  for (int i = 0; i < 11; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);
    }
  }
}
void setup() {
  pinMode(speakerPin, OUTPUT);
}
void loop() {
  for (int i = 0; i < length; i++) {
    if (notes[i] == ' ') {
      delay(beats[i] * tempo); // rest
    } else {
      playNote(notes[i], beats[i] * tempo);
    }

    // pause between notes
    delay(tempo / 2);
  }
  while (true) {}
}

Schematics

Circuit Diagram
Anchors aweigh circuit zu2iavkof5
Schematic
Anchors aweigh schem lu9d5hchwa

Comments

Similar projects you might like

Complete Digital Clock Including Alarm and Motion Sensor

Project tutorial by LAGSILVA

  • 12,684 views
  • 11 comments
  • 50 respects

Security System And Access Control With Arduino And RFID

Project tutorial by Sarath P

  • 7,251 views
  • 0 comments
  • 18 respects

Ultrasonic Sensor with Alarm, LCD and Temperature

Project tutorial by MichDragstar

  • 5,726 views
  • 7 comments
  • 20 respects

More than an Hour Timer

Project tutorial by Ian Cumming

  • 3,221 views
  • 1 comment
  • 5 respects

Morse Code Communication Using Arduino

Project tutorial by Jalal_Mansoori

  • 2,701 views
  • 7 comments
  • 19 respects

Buzzer Alarm System With Help Of Arduino

by Team ONYX

  • 37,919 views
  • 5 comments
  • 21 respects
Add projectSign up / Login