You are on page 1of 22

University of Messina

Master’s Degree Course in Engineering and Computer Science

Embedded Systems Project:


Preparatory Musical Rhythm

Student: Teacher:
Claudio Vadalà Prof. Francesco Longo

PREPARATORY MUSICAL RHYTHM 1


Contents
Introduction 3
Chapter 1 | Hardware 8
1.1. Elegoo / Arduino Uno 8
1.2. LEDs 10
1.3. Resistors 10
1.3. Speaker Module 11
1.4. Project Setup 11
Chapter 2 | Software 13
2.1. Primary Code 13
2.2. Note Library 20
Conclusions 22

PREPARATORY MUSICAL RHYTHM 2


Introduction
The purpose of this project is to build a device that introduces the children
and who approached the music rhythm for the first time to the
measurement of the music score, interacting together with both touch and
sight, then transferring basic knowledges of rhythm aspects.
This concept have various areas of application, for example in music
schools, but are also used in private environment, such as music-therapy,
self-knowledge or art installation.
To create this device will be used Arduino Uno, a microcontroller board
widely used in this field of application belonging of the Arduino suite,
which will be connected to different buttons and LEDs.
In addition to this, we have a code regarding configuration notes with
specific frequencies and how to manipulate it. So we see from both side,
hardware and software a strong interaction in order to achieve mission of
time signature learning.

In music theory we see that time is notated from left to right. I will quickly
explain the basics of rhythm. Understanding this notation is essential to
learning and studying theoretical music. The recurring pulse called the beat.
It’s the steady rhythm to which you want to tap your foot or dance.
Beats are grouped into bars, or measures as they are also called. In this
study we consider their pulse would be counted on 4/4 which is equivalent
to count such as: 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, … and so on since counting four
beats to a bar is the most common, all rhythmic terminology is based on a
bar containing 4 beats.

PREPARATORY MUSICAL RHYTHM 3


Rhythmically, a note will tell you two things: when to play it, and how long
to hold it. How long a note lasts is called its note value. This case study
will consider only a subset of notes for the songs inserted in the functions:

A quarter note lasts for 1 beat (a quarter of a whole note). The


quarter note looks like a half note with the note head filled in.

An  eighth note  lasts for half of a beat (an  eighth  of a whole
note). The eighth note looks like the quarter note with
a flag attached to the stem.

A sixteenth note lasts for a quarter of a beat (a sixteenths of


a whole note). Rhythms can be subdivided further by adding
more flags to the note or rest.  Sixteenths have two flags. 32nd
notes have 3 flags, and so on. In most music you won’t see note values
much smaller than 16ths.

The time signature tells you how the music is to be counted.


The time signature is written at the beginning of the
staff after the clef and key signature.
The top number of the time signature tells you how many beats to count.
The  bottom number  tells you what kind of note to count. That is,
whether to count the beats as quarter notes or half notes. So the only
numbers you will see as the bottom number (the denominator) will
correspond to a different note values, in our case 4 (quarter) and 8 (otter).

PREPARATORY MUSICAL RHYTHM 4


After a brief introduction to some of the main principles regarding the
rhythm I will move forward explaining how the Preparatory Musical
Rhythm works.

The Breadboard consists in, three LEDs, three buttons and a Buzzer.

The LED are respectively Red, Yellow and Green. They are associated to:
RED: 1/4 note;
YELLOW: 1/8 note;
GREEN: 1/16 note.

The button N° 1 is associated to a Demo Track which will show the alumni
the way how we represent the music in theory in 4/4 with three different
examples respectively in 1/4 notes, 1/8 notes and 1/16 notes.
It starts with four preparatory beats by 1/4, then the first five notes of C
major scale ascending and descending ( C, D, E, F ,G, F, E, D, C), ending
with the remaining rest beats (3) which will end the 4/4 bar. After It starts
again with the same first notes of C major scale ascending and descending
( C, D, E, F ,G, F, E, D, C) this time in 1/8 value notes. ending with the
remaining rest beats (3) which will end the bar. The last part of the Demo
is represented by the first five notes of C major scale ascending and
descending ( C, D, E, F ,G, F, E, D, C) in 1/16 notes value, ending with the
rests beat that will complete the final bar.

PREPARATORY MUSICAL RHYTHM 5


The below image is more explicative under the visual prospective:

Score notation of the first button: “Demo Track”

The button N° 2 is associated to one popular


song from Gershon Kingsley back in 1969
titled: “Popcorn”. The song got famous in 1972
covered from Hot Butter and it was also used in
Pengo game from SEGA in 1982. I choose this
song in particular because it reminds the arcade
gaming atmosphere and also because is has the
particularity with the begin. The song has an
headless start which mean that there are three empty beats before the
melody begins. I retain very useful to show this peculiarity to the begin
listeners who experience music so the alumni can be more conscious about
the variety of rhythmic involving the music itself. Here’s the example:

Score notation of second button: “Gershon Kingsley - Popcorn”

PREPARATORY MUSICAL RHYTHM 6


The third button is associated to another great
example of music for games, I am talking about the
Tetris Main theme. The reason which I choose this
melody is because is also referring to music for
videogame but it has also been written in a different
time signature which is 4/8. This will allow the
Preparatory musical rhythm to play note in 1/16 in
order to give another concrete examples of how is
possible to write music and how a very short note
such as 1/16 can be executed in music. The functionality of 4/8 is to
double the speed of the track metronome in order to have eight “ticks”
instead of four. Here following you will see the score notation example:

Score notation of the third button: “Tetris”

As we can see these examples shows the varieties of the rhythm in different
circumstances. This is a starting point to show under an “Arduino point of
view” how music can be learnt with electronics through coding.

PREPARATORY MUSICAL RHYTHM 7


Chapter 1 | Hardware
Hardware Aspects

In this chapter is described the mainly hardware components used in this


project, they are:
• Elegoo / Arduino Uno: microcontroller;
• LED components;
• Resistors components;
• Speaker module;

1.1. Elegoo / Arduino Uno

Compatibility with Official Arduino IDE

Arduino is an open-source platform used for building electronics projects.


It consists of both a physical programmable circuit board (often referred to
as a microcontroller) and a piece of software, or IDE (Integrated

PREPARATORY MUSICAL RHYTHM 8


Development Environment) that runs on your computer, used to write and
upload computer code to the physical board.

Learn Electronics and Programming with UNO

The UNO boards can be used as the brains behind almost any electronics
project. UNO can interact with buttons, LEDs, motors, speakers, GPS
units, cameras, the internet etc… By connecting the UNO board with a
personal computer via a USB cable and uploading programs to the board,
users can create digital devices and interactive objects that can sense and
control objects in the physical and digital world.

PREPARATORY MUSICAL RHYTHM 9


1.2. LEDs
LEDs have been used in the project to measure the time value of the notes.
The Red LED is associated to 1/4 note, the Yellow LED indicates 1/8
note and the Green LED ends with 1/16 note.

1.3. Resistors
Resistors have been used to limit the amount of current going to certain
components in the circuit, such as LEDs and integrated circuits. For the
LEDs I used 220 Ohm while for the Buzzer I used 100 Ohm.

PREPARATORY MUSICAL RHYTHM 10


1.3. Speaker Module
Speaker or Buzzer uses a material that’s  piezoelectric, it actually changes
shape when you apply electricity to it. By adhering a piezo-electric disc to a
thin metal plate, and then applying electricity, we can bend the metal back
and forth, which in turn creates noise.
The faster you bend the material, the higher the pitch of the noise that’s
produced. This rate is called frequency.

the higher the frequency, the higher


the pitch of the noise we hear.

1.4. Project Setup


The circuit diagram is composed by three buttons. The top right foot is
linked to 5V, the top Left passes from the resistors and then to Ground, the
bottom left foot is linked respectively to Arduino Pins 11,12,13. We also
have three LEDs which the right foot (-) goes straight to Ground and the
left (+) passes through the resistor before going to the Arduino Pin 2,3,4.
Last but not least we find the Buzzer which the top foot is linked to the
Ground and the bottom foot is linked to Arduino Pin 8.

PREPARATORY MUSICAL RHYTHM 11


PREPARATORY MUSICAL RHYTHM 12
Chapter 2 | Software
2.1. Primary Code

I started including the library pitches.h which give us all the frequency reference in terms
of Hertz to be sent to the buzzer for playing the correspondent notes. Then I wrote the
melody of the three song melodies that will characterize the preparatory music concept.

#include "pitches.h" //add note library

//notes in the melody DEMO


int demo[]={2,2,2,2,
NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4,
NOTE_G4, NOTE_F4, NOTE_E4, NOTE_D4,
NOTE_C4, 2,2,2,

NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4,


NOTE_G4, NOTE_F4, NOTE_E4, NOTE_D4,
NOTE_C4,4,4,4,

NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4,


NOTE_G4, NOTE_F4, NOTE_E4, NOTE_D4,
NOTE_C4,8,8,8,};

//notes in the melody POPCORN


int popcorn[]={2,2,2,
NOTE_C6, NOTE_AS5, NOTE_C6, NOTE_G5, NOTE_DS5, NOTE_G5, NOTE_C5,
NOTE_C6, NOTE_AS5, NOTE_C6, NOTE_G5, NOTE_DS5, NOTE_G5, NOTE_C5,
NOTE_C6, NOTE_D6, NOTE_DS6, NOTE_D6, NOTE_DS6, NOTE_C6, NOTE_D6, NOTE_C6,
NOTE_D6, NOTE_AS5, NOTE_C6, NOTE_AS5, NOTE_C6, NOTE_G5, NOTE_C6,
NOTE_C6,};

//notes in the melody TETRIS


int tetris[]={4,4,4,4,

PREPARATORY MUSICAL RHYTHM 13


NOTE_E5, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_C5, NOTE_B4,
NOTE_A4, NOTE_A4, NOTE_C5, NOTE_E5, NOTE_D5, NOTE_C5,
NOTE_B4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_C5,
NOTE_A4, NOTE_A4, NOTE_C5, NOTE_A4,};

Note that every note contains information about the octave pitch (e.x. B4 means B or Si
on the fourth octave) and here following you will find the initialization of the buttons and
leds respectively attached to the Arduino board.

//digital pins respectively 11,12,13 have a button relinked to it.Named as:


int demobuttonPin= 13;
int popbuttonPin= 12;
int tetbuttonPin= 11;
int led=2;
int lstep1=3;
int lstep2=4;

int Rest=0;

//note durations. 2 = half note; 4 = quarter note; 8 = eighth note


int
demonoteDurations[]={2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,4,4,4,4,4,4,4,4,4,4,4,
4,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,};

int
popnoteDurations[]={2,2,2,4,4,4,4,4,4,2,4,4,4,4,4,4,2,4,4,4,4,4,4,4,4,4,4,4
,4,4,4,2,2,};

int tetnoteDurations[]={4,4,4,4,4,8,8,4,8,8,4,8,8,4,8,8,4,8,8,4,4,4,4,2,};

I end up the first part of the code with the score notation of every single note inside the
melody arrangements and following the declaration of Input/output components.

PREPARATORY MUSICAL RHYTHM 14


void setup(){
//make the button's pin input
pinMode(demobuttonPin, INPUT);
pinMode(popbuttonPin, INPUT);
pinMode(tetbuttonPin, INPUT);
pinMode (led, OUTPUT);
pinMode (lstep1, OUTPUT);
pinMode (lstep2, OUTPUT);

The buttons will be taken as Input by pressing it while the LEDs will be Output to get
the message out coming from the music.

void loop(){

//read the input pin

int popbuttonState = digitalRead(popbuttonPin);


int tetbuttonState = digitalRead(tetbuttonPin);
int demobuttonState = digitalRead(demobuttonPin);

Here you find digitalRead function which reads the value from a specified digital pin,
it returns High or Low. In the brackets you have the pin number.

Here following you will find the condition that determines which LED will light up,
based on a division of a unity expressed in ms (e.x. one second = 1000ms). If the value
divided for the note duration is corresponding to the note range associated to the note, then
the LED will reveal the value of the note associated.

PREPARATORY MUSICAL RHYTHM 15


//Script of the three songs composed:

//DEMO MELODY
//if the button is pressed
if (demobuttonState == 1){

//iterate over the notes of the melody


for (int thisNote=0; thisNote <40; thisNote++){

//to calculate the note duration, take one second. Divided by the
note type
int demonoteDuration = 1000 / demonoteDurations [thisNote];

if (demonoteDuration ==500){

digitalWrite(lstep1, HIGH);

tone(8, demo[thisNote],demonoteDuration);

digitalWrite(lstep1, LOW);

}
if (demonoteDuration >200 && demonoteDuration <300){

digitalWrite(lstep2, HIGH);

tone(8, demo[thisNote],demonoteDuration);

digitalWrite(lstep2, LOW);

}
if (demonoteDuration <200){

digitalWrite(led, HIGH);

tone(8, demo[thisNote],demonoteDuration);

digitalWrite(led, LOW);

PREPARATORY MUSICAL RHYTHM 16


}

//to distinguish the notes, set a minimum time between them


//the note's duration +30% seems to work well
int pauseBetweenNotes = demonoteDuration * 1.30;
delay(pauseBetweenNotes);

//stop the tone playing


noTone(8);
}

You can also find another Arduino function called digitalWrite which Is used to
change the LEDs state. If it’s needed to light up than the value will be High, vice versa I
will set up to Low.

//POPCORN MELODY
//if the button is pressed
if (popbuttonState == 1){

//iterate over the notes of the melody


for (int thisNote=0; thisNote <33; thisNote++){

//to calculate the note duration, take 900ms (0,9 seconds). Divided
by the note type
int popnoteDuration = 900 / popnoteDurations [thisNote];

if (popnoteDuration ==225){

digitalWrite(lstep2, HIGH);

tone(8, popcorn[thisNote],popnoteDuration);

PREPARATORY MUSICAL RHYTHM 17


digitalWrite(lstep2, LOW);

}
if (popnoteDuration >225){

digitalWrite(lstep1, HIGH);

tone(8, popcorn[thisNote],popnoteDuration);

digitalWrite(lstep1, LOW);

//to distinguish the notes, set a minimum time between them


//the note's duration +30% seems to work well
int pauseBetweenNotes = popnoteDuration * 1.30;
delay(pauseBetweenNotes);

//stop the tone playing


noTone(8);
}

Here another example of melody, this time I did time-lapse of the variable, bringing up
to 1200 to get possible the 4/8 time signature without stretching too much the speed. I
raised up to 1.2 seconds the main tempo.

//TETRIS MELODY
if (tetbuttonState == 1){

//iterate over the notes of the melody


for (int thisNote=0; thisNote <24; thisNote++){

PREPARATORY MUSICAL RHYTHM 18


//to calculate the note duration, take 1200 ms (1,2 seconds). Divided
by the note type
int tetnoteDuration = 1200 / tetnoteDurations [thisNote];
if (tetnoteDuration <225){

digitalWrite(led, HIGH);

tone(8, tetris[thisNote],tetnoteDuration);

digitalWrite(led, LOW);

}
if (tetnoteDuration >225){

digitalWrite(lstep2, HIGH);

tone(8, tetris[thisNote],tetnoteDuration);

digitalWrite(lstep2, LOW);

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

//stop the tone playing


noTone(8);
}
}
}

The Key function in this project is given by Tone which generates a square wave of the
specified frequency on a pin. So the pin is connected to the Buzzer to play the tone. On the
other hand we have noTone function which will stop the buzzer making sound.

PREPARATORY MUSICAL RHYTHM 19


2.2. Note Library

I selected from the library only three octaves needed to play the melodies:
From C4 (first note of the fourth octave scale) to B6 (last note of the sixth
octave scale).

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

#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

PREPARATORY MUSICAL RHYTHM 20


#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

PREPARATORY MUSICAL RHYTHM 21


Conclusions
The Preparatory Musical Rhythm is was conceived mainly for didactic
purposes, a conscious choice could be to invest more attention in the
development of the prototype. It is possible to think ahead towards an
upgrade of the machine:
• Rhythmic improvements can be made by adding new LEDs
corresponding to note values, new melodies that contain musically
advanced rhythmic elements.
• Another idea is to subdivide the button examples into exercises of
varying difficulty levels, which can then be reproduced by the musician
through his instrument.
• A variation is that of having the same melody but setting three different
speeds, each for each button (distance of 5 BPM for each).
It is also possible to implement the machine from the hardware point of
view, some solutions could be:
• adding 12 LEDs, one for each semitone of the scale, which can indicate
the note in question and other LEDs that can indicate the reference
octave.
• Add references to the beat through four LEDs: the first one in red which
indicates the downbeat time, other three green LEDs which indicate the
weak time (upbeat).
There are truly countless incremental upgrades that can be added to this
basic machine. I hope this is a project that can be used as a reference for
other Arduino developers, for music technology enthusiasts and for the
new generations, who can be guided towards an innovative and artistic
culture.

PREPARATORY MUSICAL RHYTHM 22

You might also like