Introduction
The goal of this project was to create an art show, whether that be music or lights etc, on bread board by writing a code. My partner was Sadie Ikeda and we decided to have our code play the friends theme song. We created a code and added notes and frequency. This project was fun because we really had the option to create whatever we wanted.
Code
const int buzzerPin = 9;//this is the pin # that our buzzer is connected to.
const int songLength = 116;// this is how many notes or rests are in our song, so that our board knows how long to go for
char notes[] = " bbagfgag bbagfgag dgacbaggdgaa dgacbagcbagV ccccccccbb abcccccbaggdgabaaVVVEV abcbagVVVEV abcbagVVVEV abcbaaagffgagfcfgab";// These are the notes to let the computer know what frequency to play.
int beats[] = {2,2,1,1,2,2,2,2,2,2,2,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,8,2,2,2,2,2,2,2,2,2,2,2,2,8,2,2,2,2,2,2,2,2,2,2,4,4,2,2,2,2,2,2,2,2,2,2,2,2,1,2,4,4,4,2,4,4,2,2,1,4,2,2,2,4,2,4,4,4,2,1,4,2,2,2,4,2,4,4,4,2,1,4,2,2,1,2,2,2,2,2,8,2,2,2,2,8};// These are the beats for each note or rest in our song
int tempo = 120;// This is the tempo for our song. This controls how fast or slow our notes are going
void setup() {
pinMode(buzzerPin, OUTPUT);}
void loop()
{
int i, duration;
for (i = 0; i < songLength; i++) // step through the song arrays
{
duration = beats[i] * tempo; // length of note/rest in ms
if (notes[i] == ' ') // is this a rest?
{
delay(duration); // then pause for a moment
}
else // otherwise, play the note
{
tone(buzzerPin, frequency(notes[i]), duration);
delay(duration); // wait for tone to finish
}
delay(tempo/10); // brief pause between notes
}
}
int frequency(char note)
{
// This function takes a note character (a-g), and returns the
// corresponding frequency in Hz for the tone() function.
int i;
const int numNotes = 10; // number of notes we're storing
// The following arrays hold the note characters and their
// corresponding frequencies. The last "C" note is uppercase
// to separate it from the first lowercase "c". If you want to
// add more notes, you'll need to use unique characters.
// For the "char" (character) type, we put single characters
// in single quotes.
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', 'D', 'V' };//This is the note names and below are the note frequencies so that our computer knows what to play.
int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523, 587, 1175};
// Now we'll search through the letters in the array, and if
// we find it, we'll return the frequency for that note.
for (i = 0; i < numNotes; i++) // Step through the notes
{
if (names[i] == note) // Is this the one?
{
return(frequencies[i]); // Yes! Return the frequency
}
}
return(0); // We looked through everything and didn't find it,
// but we still need to return a value, so return 0.
}
const int songLength = 116;// this is how many notes or rests are in our song, so that our board knows how long to go for
char notes[] = " bbagfgag bbagfgag dgacbaggdgaa dgacbagcbagV ccccccccbb abcccccbaggdgabaaVVVEV abcbagVVVEV abcbagVVVEV abcbaaagffgagfcfgab";// These are the notes to let the computer know what frequency to play.
int beats[] = {2,2,1,1,2,2,2,2,2,2,2,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,8,2,2,2,2,2,2,2,2,2,2,2,2,8,2,2,2,2,2,2,2,2,2,2,4,4,2,2,2,2,2,2,2,2,2,2,2,2,1,2,4,4,4,2,4,4,2,2,1,4,2,2,2,4,2,4,4,4,2,1,4,2,2,2,4,2,4,4,4,2,1,4,2,2,1,2,2,2,2,2,8,2,2,2,2,8};// These are the beats for each note or rest in our song
int tempo = 120;// This is the tempo for our song. This controls how fast or slow our notes are going
void setup() {
pinMode(buzzerPin, OUTPUT);}
void loop()
{
int i, duration;
for (i = 0; i < songLength; i++) // step through the song arrays
{
duration = beats[i] * tempo; // length of note/rest in ms
if (notes[i] == ' ') // is this a rest?
{
delay(duration); // then pause for a moment
}
else // otherwise, play the note
{
tone(buzzerPin, frequency(notes[i]), duration);
delay(duration); // wait for tone to finish
}
delay(tempo/10); // brief pause between notes
}
}
int frequency(char note)
{
// This function takes a note character (a-g), and returns the
// corresponding frequency in Hz for the tone() function.
int i;
const int numNotes = 10; // number of notes we're storing
// The following arrays hold the note characters and their
// corresponding frequencies. The last "C" note is uppercase
// to separate it from the first lowercase "c". If you want to
// add more notes, you'll need to use unique characters.
// For the "char" (character) type, we put single characters
// in single quotes.
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', 'D', 'V' };//This is the note names and below are the note frequencies so that our computer knows what to play.
int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523, 587, 1175};
// Now we'll search through the letters in the array, and if
// we find it, we'll return the frequency for that note.
for (i = 0; i < numNotes; i++) // Step through the notes
{
if (names[i] == note) // Is this the one?
{
return(frequencies[i]); // Yes! Return the frequency
}
}
return(0); // We looked through everything and didn't find it,
// but we still need to return a value, so return 0.
}
Circuit Diagram
Pre-project assignments:
Before we started the project we learned about electricity. We spent about 1 week on electrical circuits. We learned about the flow of electricity through different objects and resistors. Once we were done with that we started to learn about bread boards and how to transfer energy through the bread board. After we were done with that we started learning about codes using the software Arduino. It had sixteen different circuits to set up. Each time they were focused on a different component. After we had finished all of that we started our project.
Components:
~Circuit- A loop of conductive material from one terminal of power source to the other
~Current- flow of charge or electricity through a circuit
Equation: v=ir
Unit= Amps
~Voltage- potential energy difference across a component in a circuit
Equation: v=ir
Unit= Volts
~Resistance- obstacle to the current that slows it down
Equation: Ohms
~Series- The total resistance of resistors in series is the sum of the resistors.
~Parallel- You can add the resistors in a series to get the total resistance.
~Ohms Law- V=IR voltage equals current times resistance
~Bread boards- A board used for making electrical circuit. We used this to create our circuit and then hooked it up to the computer to create our song.
~Coding- the process of assigning a code to something for the purposes of classification or identification
~Current- flow of charge or electricity through a circuit
Equation: v=ir
Unit= Amps
~Voltage- potential energy difference across a component in a circuit
Equation: v=ir
Unit= Volts
~Resistance- obstacle to the current that slows it down
Equation: Ohms
~Series- The total resistance of resistors in series is the sum of the resistors.
~Parallel- You can add the resistors in a series to get the total resistance.
~Ohms Law- V=IR voltage equals current times resistance
~Bread boards- A board used for making electrical circuit. We used this to create our circuit and then hooked it up to the computer to create our song.
~Coding- the process of assigning a code to something for the purposes of classification or identification
Reflection
Overall this project went really well! Personally I think I could have improved upon leadership. Being in a two person group is hard from a leadership roll, but I think I could have tried harder to come up with more ideas. As a group I think we could improve upon work ethic. Not only being in a two person group , but picking our own groups made it a little more of a challenge to stay focused.
This project was very successful though. Personally I believe I did really well with empathy and listening to my partners ideas. As a group I feel we had really great attitudes. We both found this project interesting so we were very excited about doing it. We had a creative idea and we enjoyed achieving it.
This project was very successful though. Personally I believe I did really well with empathy and listening to my partners ideas. As a group I feel we had really great attitudes. We both found this project interesting so we were very excited about doing it. We had a creative idea and we enjoyed achieving it.