Introduction: Digitize a Song With Arduino

I wanted to create a project that combined two of my favorite subjects: science and music. I thought of all of the ways that I could combine these two domains, and, I thought that it would be interesting to make an Arduino play Fur Elise while displaying the pitch of the note in Hertz. Now, let's start building!

You will need one Arduino Uno or Mega, a lot of jumper cables, a Piezo buzzer, a breadboard, a 16*2 LCD screen with all wiper pins in place, and a 10k Potentiometer (you may also hear them being referred to as potmeters). It is best to get all of these supplies together before we start the build.

Step 1: Convert the Musical Score Into Digital Notes: Delay Values

There are two steps to digitally transcribing a note from the score into its digital equivalent. First, we will need to write the time the note lasts in milliseconds. I employed a chart found online for this task. Based on whether a note was a half note, quarter note, eighth note, etc, I transcribed the note length into milliseconds. You can see these numbers in my code as the delay(); function and the number within the parentheses will be the delay value in milliseconds we determined in this step.

Step 2: Convert the Musical Score Into Digital Notes: Hertz Values

Before starting this step, let me define some technical terms. The "value" of a note can be interchangeably used with the words "pitch", "value", and "note". Now, you have to read each note of the song from the score. You will have to then translate each note into Hertz using a music to Hertz table, which you can easily find online. One thing to remember is that middle C is listed as C4 on the table, and an octave higher is C5, and so on. Once these notes are all transcribed into Hertz, you will be placing the values into the function tone(x,y,z); where X is the pin number or const int, a way of defining variables that I will explain later. Y will be the Hertz value that you just transcribed, and Z will be the duration of the note in milliseconds rounded to the nearest hundredth. The delay(); values will be the duration of the note. Now, let's design the circuit that can play the music.

Step 3: Circuit Design

Now that we have translated all of the notes into digital values that a computer can understand, it's time to build the circuit. Begin by taking a breadboard and placing the LCD screen with the first pin (GND) in row 14. Place the buzzer anywhere you like, and place a potentiometer next to it. The goal is to line everything up, to minimize cluttering of the wires. Place the Arduino next to the breadboard, and connect the 5v pin to the positive rail of the breadboard, and the ground pin to the negative rail. Now, we are ready to connect jumpers between the Arduino and the components.

Now, let's talk about the pins on the LCD, and how to wire them.

GND stands for ground, this is the negative wire in direct current. Wire GND to the negative rail of the breadboard.

VCC stands for Voltage at the Common Collector, and this is where you connect your 5-volt power source (the positive power rail).

VO stands for Contrast, wire this to the middle pin of the potentiometer. Connect the left pin of the potentiometer to the positive power rail, and the right pin to the ground power rail.

RS stands for Register Select, and this is used by the Arduino to tell the display where to store data. Connect this pin to pin 12 on the Arduino.

RW stands for Read/Write pin, which the Arduino uses to check if the screen is showing what you have programmed it to show. Connect this pin to the negative rail on the breadboard.

E stands for Enable, which tells the LCD which pixels to enable (turn on) or disable (turn off). Connect this pin to Arduino pin 11.

D4, D5, D6, and D7 are Display pins which control the characters and letters being displayed. Connect them to Arduino pins 5, 4, 3, and 2, respectively.

Pin A, sometimes labeled LED, is the LED anode for the backlight. Connect this to the positive power rail with a wire or with a 220-ohm resistor. The resistor is better for longer use as it spares the LCD, but if the device is not going to be used day and night, you don't need the resistor.

Pin K, sometimes also (confusingly) labeled LED, is the LED ground pin. Connect this to the ground power rail.

Step 4: Code Uploading: How-To

Plug your Arduino into your computer's USB. Upload the following code using the Arduino IDE programmer.

#include <liquidcrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);</p><p>void setup() {
// set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Hertz Pitch:!");
  delay(1000);
void loop() {
  
  // play e4
  delay(600);//pause for 0.6 seconds
  tone(10, 329.63, 300);//play e to the buzzer at pin 10, last for .3 secs
  lcd.print("329.63");//display a message on LCD "329.63"</p><p>  delay(350);//delay for .35 seconds
  lcd.clear();//clear LCD and reset for next message
  // play d4# 
  tone(10, 311.13, 300);
  lcd.print("311.13");
  delay(350);
  lcd.clear();
  // play e4
  tone( 10, 329.63, 300);
  lcd.print("329.63");
  delay(350);
  lcd.clear();
  // play d4# 
  tone( 10,311.13, 300);
  lcd.print("311.13");
  delay(350);
  lcd.clear();
  // play e4
  tone(10, 329.63, 300);
  lcd.print("329.63");
  delay(350);
  lcd.clear();
  // play b3
  tone( 10, 246.94, 300);
  lcd.print("246.94");
  delay(400);
  lcd.clear();
  // play d4
  tone(10, 293.66,300);
  lcd.print("293.66");
  delay(400);
  lcd.clear();
  // play c4
  tone(10, 261.63,300);
 lcd.print("261.63");
  delay(400);
  lcd.clear();
  // play a3
  tone(10, 220, 900);
  lcd.print("220.0");
  delay(1000);
 lcd.clear();//line60//helpsave//avrdude.failure.eeprom
  // play d3 
  tone(10,146.83, 300);
  lcd.print("146.63");
  delay(350);
  lcd.clear();
  //play f3
  tone(10, 174.61, 300);
  lcd.print("174.61");
  delay(400);
  lcd.clear();
  //play a3
  tone(10, 220, 300);
  lcd.print("220");
  delay(400);
  lcd.clear();
  // play b3
  tone(10, 246.94, 900);
  lcd.print("246.94");
  delay(1000);
  lcd.clear();</p><p>  // play e3
  tone(10, 164.81, 300);
  lcd.print("164.81");
  delay(400);
  lcd.clear();
  // play g3#
  tone(10, 207.65, 300);
  lcd.print("207.65");
  delay(400);
  lcd.clear();
  // play b3
  tone(10, 246.94, 300);
  lcd.print("246.94");
  delay(400);
  lcd.clear();
  // play c4
  tone(10, 261.63, 900);
  lcd.print("261.63");
  delay(1000);
lcd.clear();
//play e
 tone(10,164.81, 300);
 lcd.print("164.81");
 delay(400); 
 lcd.clear();
  // play e4
  tone(10, 329.63, 300);
  lcd.print("329.63");
  delay(400);
  lcd.clear();
  // play d4#
  tone(10, 311.13, 300);
  lcd.print("311.13");
  delay(400);
  lcd.clear();
  // play e4
  tone(10, 329.63, 300);
    lcd.print("329.63");
  delay(400);
  lcd.clear();
  // play d4#
  tone(10, 311.13, 300);
   lcd.print("311.13");
  delay(400);
   lcd.clear();
  // play e4
  tone(10, 329.63, 300);
  lcd.print("329.63");
  delay(400);
   lcd.clear();
  // play b3
  tone(10, 246.94, 300);
  lcd.print("246.94");
  delay(400);
   lcd.clear();
  // play d4
  tone(10, 293.66, 300);
  lcd.print("293.66");
  delay(400);
   lcd.clear();
  // play c4
  tone(10, 261.63, 300);
  lcd.print("261.63");
  delay(400);
   lcd.clear();
  // play a3
  tone(10, 220, 900);
  lcd.print("220.0");
  delay(1000);
 lcd.clear();
  // play d3
  tone(10, 146.83, 300);
  lcd.print("146.83");
  delay(400);
   lcd.clear();
  // play f3
  tone(10, 174.61, 300);
  //eeprom 20--6 yesno, flash 65--0 noyes
  lcd.print("174.61");
  delay(400);
   lcd.clear();
  // play a3
  tone(10, 220, 300);
  lcd.print("220.0");
  delay(400);
   lcd.clear();
  // play b3
  tone(10, 246.94, 900);
  lcd.print("246.94");
  delay(1000);
   lcd.clear();
 
  // play f3
  tone(10, 174.61, 300);
  lcd.print("174.61");
  delay(400);
   lcd.clear();
  // play c4
  tone(10, 261.63, 300);
  lcd.print("261.63");
  delay(400);
   lcd.clear();
  // play b3
  tone(10, 246.94, 300);
  lcd.print("246.94");
  delay(400);
   lcd.clear();
  // play a3
  tone(10, 220, 900);
  lcd.print("220.0");
  
  delay(1000);
  lcd.clear();
  // play b3
  tone(10,246.94, 300);
  lcd.print("246.94");
  delay(400);
   lcd.clear();
   // play c4
  tone(10, 261.63, 300);
  lcd.print("261.63");
  delay(400);
   lcd.clear();
  // play d4
  tone(10, 293.66, 300);
  lcd.print("293.66");
  delay(400);
   lcd.clear();
  // play e4
  tone(10, 329.63, 900);
  lcd.print("329.63");
  delay(1000);
   lcd.clear();
  // play g3
  tone(10, 196, 300);
  lcd.print("196.0");  
  delay(400);
   lcd.clear();
  // play f4
  tone(10, 349.23, 300);
  lcd.print("349.23");
  delay(400);
   lcd.clear();
  //play e4
  tone(10, 329.23, 300);
  lcd.print("329.23");
  delay(400);
   lcd.clear();
  // play d4
  tone(10, 293.63, 900);
  lcd.print("293.63");
  delay(1000);
   lcd.clear();
  // play e3
  tone(10,164.81, 300);
  lcd.print("164.81");
  delay(400);
   lcd.clear();
  // play e4
  tone(10, 329.63, 300);
  lcd.print("329.63");
  delay(400);
   lcd.clear();
  // play d4
  tone(10, 293.63, 300);
  lcd.print("293.63");
  delay(400);
   lcd.clear();
  // play c4
  
  tone(10, 261.63, 900);
  lcd.print("261.63");
  delay(1000);
   lcd.clear();
  // play d3
  tone(10, 146.83, 300);
  lcd.print("146.83");
  delay(400);
   lcd.clear();
    // play d4
  tone(10, 293.63, 300);
 lcd.print("293.63");
  delay(400);
   lcd.clear();
  // play c4
  tone(10, 261.63, 300);
  lcd.print("261.63");
  delay(400);
   lcd.clear();
  // play b3
  tone(10, 246.94, 900);
  lcd.print("246.94");
  delay(1000);
   lcd.clear();
  // play e4
  tone(10, 329.63, 300);
  lcd.print("329.63");
  delay(400);
   lcd.clear();
  // play d4# 
  tone(10, 311.13, 300);
  lcd.print("311.13");
  delay(350);
   lcd.clear();
  // play e4
  tone( 10, 329.63, 300);
  lcd.print("329.63");
  delay(350);
   lcd.clear();
  // play d4# 
  tone( 10,311.13, 300);
 lcd.print("311.13");
  delay(350);
   lcd.clear();
  // play e4
  tone(10, 329.63, 300);
  lcd.print("329.63");
  delay(350);
   lcd.clear();
  // play b3
  tone( 10, 246.94, 300);
  lcd.print("246.94");
  delay(400);
   lcd.clear();
  // play d4
  tone(10, 293.66,300);
lcd.print("293.66");
  delay(400);
  lcd.clear();
  // play c4
  tone(10, 261.63,300);
  lcd.print("261.63");
  delay(400);
  lcd.clear();
  // play a3
  tone(10, 220, 900);
  lcd.print("220.0");
  delay(1000);
  lcd.clear();
  // play d3
  tone(10,146.83, 300);
  lcd.print("146.83");
  delay(350);
  lcd.clear();
  //play f3
  tone(10, 174.61, 300);
  lcd.print("174.61");
  delay(400);
  lcd.clear();
  //play a3
  tone(10, 220, 300);
  lcd.print("220.0");
  delay(400);
  // play b3
  lcd.clear();
  tone(10, 246.94, 900);
  lcd.print("246.94");
  delay(1000);
  lcd.clear();
  // play e3
  tone(10, 164.81, 300);
  lcd.print("164.81");
  delay(400);
  lcd.clear();
  // play g#3
  tone(10, 207.65, 300);
  lcd.print("207.65");
  delay(400);
  lcd.clear();
  // play b3
  tone(10, 246.94, 300);
lcd.print("246.94");
  delay(400);
  lcd.clear();
  // play c4
  tone(10, 261.63, 900);
  lcd.print("261.63");
  delay(1000);
  delay(300);
  lcd.clear();
 //play e3
 tone(10, 164.81, 300);
 lcd.print("164.81");
 delay(400);
 lcd.clear();
  // play e4
  tone(10, 329.63, 300);
  lcd.print("329.63");
  delay(400);
   lcd.clear();
  // play d4# 
  tone(10, 311.13, 300);
  lcd.print("311.13");
  delay(400);
   lcd.clear();
  // play e4
  tone(10, 329.63, 300);
  lcd.print("329.63");
  delay(400);
    lcd.clear();
  // play d4#
  tone(10, 311.13, 300);
  lcd.print("311.13");
  delay(400);
    lcd.clear();
  // play e4
  tone(10, 329.63, 300);
    lcd.print("329.63");
  delay(400);
     lcd.clear();
  // play b3
  tone(10, 246.94, 300);
  lcd.print("246.94");
  delay(400);
     lcd.clear();
  // play d4
  tone(10, 293.66, 300);
  lcd.print("293.66");
  delay(400);
       lcd.clear();
  // play c4
  tone(10, 261.63, 300);
  lcd.print("261.63");
  delay(400);
       lcd.clear();
  // play a3
  tone(10, 220, 900);
  lcd.print("220.0");
  delay(1000);
    lcd.clear();
  // play d3
  tone(10, 146.83, 300);
  lcd.print("146.83");
  delay(400);
    lcd.clear();
  // play f3
  tone(10, 174.61, 300);
  lcd.print("174.61");
  delay(400);
    lcd.clear();
  // play a3
  tone(10, 220, 300);
  lcd.print("220.0");
  delay(400);
    lcd.clear();
   // play b3
  tone(10, 246.94, 900);
   lcd.print("246.94");
  delay(1000);
  
       lcd.clear();
  // play f3
  tone(10, 174.61, 300);
   lcd.print("174.61");
  delay(400);
       lcd.clear();
  // play c4
  tone(10, 261.63, 300);
 lcd.print("261.63");
  delay(400);
       lcd.clear();
  // play b3
  tone(10, 246.94, 300);
    lcd.print("246.94");
  delay(400);
  
       lcd.clear();
  // play a3
  tone(10, 220, 900);
   lcd.print("220.0");
  delay(1000);
  lcd.clear();
}

Step 5: Code Uploading: What Does All of That Mean?

Let's define some functions in English, so you can understand the code.

tone(x,y,z); = play a tone with a pitch of y Hertz, to a buzzer at pin x, for z milliseconds.

lcd.print("XYZ"); = print a message with the characters XYZ to LCD screen. (e.g. display the Hertz pitch)

delay(x); = pause for x milliseconds.

const int X=Y = set a constant variable X to pin Y, and use either X or Y to assign tasks to the device.

lcd.clear(); = clear the LCD screen and reset for a new display

pinMode(X, OUTPUT); = set pin X for output mode

Once you understand all of these functions, you can easily substitute the variables with the data that you collect when translating a song, and you can then code your own song!

Step 6: Finished!!!

You either have an Arduino that plays Fur Elise and displays the note values in Hertz, or you have made an Arduino that plays the melody of the song that you chose, and displays text that you wished to show. Thank you for visiting this tutorial, and I hope to you this project on the Arduino.

Pro Tips Challenge

Participated in the
Pro Tips Challenge

Pocket-Sized Contest

Participated in the
Pocket-Sized Contest

Epilog Challenge 9

Participated in the
Epilog Challenge 9