We are Number One but it's Arduino - Arduino Project

Song made with an Arduino

The song made with an Arduino is a simple Arduino based project which plays a song using a piezo which vibrates at different frequencies to make different notes/sounds. I chose to do the song We are number one because it is a meme and I quite like the first few notes of the song. It is a simple project which I designed in the span of about 15 to 30 minutes.


All you will need for this project is:

  • An Arduino UNO
  • A Piezo
  • Wires
  • And the open-source Arduino Software (You can download it for free at https://www.arduino.cc/en/Main/Software)

You first wire up your components as shown in the diagram below.



The only thing that you will be wiring in this project is the piezo. The piezo will be connected to the ground inlet through the ground pin and the digital inlet 8 through the other pin.

Here are some pictures of how I wired up my arduino.




When your board is wired up you can start coding. Here is the simplest version of the code.


const int fn = 400;
const int hn = 200;
const int qn = 100;
const int f5 = 698;
const int c6 = 1047;
const int b5 = 988;
const int gh5 = 831;
const int ch6 = 1109;
const int dh6 = 1245;

int song[] = {
  f5,fn + hn,
  c6,hn,
  b5,qn,
  c6,qn,
  b5,qn,
  c6,qn,
  b5,hn,
  c6,hn,
  gh5,fn,
  f5,fn + hn,
  f5,hn,
  gh5,hn,
  c6,hn,
  ch6,fn,
  gh5,fn,
  ch6,fn,
  dh6,fn,
  c6,hn,
  ch6,hn,
  c6,hn,
  ch6,hn,
  c6,fn
  };

void setup() {
  Serial.begin(9600);
}

void loop() {

for (int i = 0; i < (sizeof(song)/sizeof(int)); i = i + 2){
  tone(8, song[i]);
  delay(song[i + 1]);
}

noTone(8);
delay(1000);

}

My dad suggested writing the code this way but there is a simpler way in which you write out the notes individually and with the tone(number of the pin, frequency of the tone); delay(how long the tone should play);

Komentáre