Arduino Piano

by adhillon in Circuits > Arduino

134 Views, 3 Favorites, 0 Comments

Arduino Piano

IMG_1568.png

This is a piano built with an Arduino. The Arduino is used to control the sounds that come out depending on which button is pressed. The circuit and code are very simple and easy to understand.

Supplies

Arduino x1

Buzzer x1

Push Buttons x6

Jumper Cables (As many as required)

Code for the Arduino (Last Step)

Getting the Materials

Gather Materials

I will attach links for the products below:

BREADBOARD: https://shorturl.at/0Umn2

JUMPER WIRES: https://shorturl.at/Lxf1d

MINI BUZZER: https://shorturl.at/FPPpR

PUSH BUTTONS: https://shorturl.at/qp4Mo

ARDUINO: https://shorturl.at/mmxwN


Getting the Push Buttons Wired Up

IMG_1568.png

The push buttons need to be wired to the D4-D9 Pins of your Arduino. The other end needs to be connected to the negative rail of the breadboard. This picture should help


Plugging the Buzzer and GND In.

image.jpg
image.jpg

Plug the Arduino's GND into your breadboards negative rail.

Plug the Buzzer's Negative into the negative breadboard rail and the positive into the D11 PIN on the Arduino

Getting the Arduino App

By this point your circuit should look just like mine, and it still won't work because we are missing the last step, The Code! The code will work on the Arduino app which you can download down here:

https://www.arduino.cc/en/software

The Code

This is the code for the Arduino, if you run into any issues you can download the direct file onto your computer.

File is at the bottom of this step

//Arveer Piano Arduino

#define  T_C 262
#define T_D 294
#define T_E 330
#define T_F 349
#define T_G  392
#define T_A 440
#define T_B 493


const int C = 10;
const int  D = 9;
const int E = 8;
const int F = 7;
const int G = 6;
const int  A = 5;
const int B = 4;


const int Buzz = 11;
const int LED = 13;


void  setup()
{
  pinMode(LED, OUTPUT);
  pinMode(C, INPUT);
  digitalWrite(C,HIGH);
  
  pinMode(D, INPUT);
  digitalWrite(D,HIGH);
  
  pinMode(E, INPUT);
  digitalWrite(E,HIGH);
  
  pinMode(F, INPUT);
  digitalWrite(F,HIGH);
  
  pinMode(G, INPUT);
  digitalWrite(G,HIGH);
  
  pinMode(A, INPUT);
  digitalWrite(A,HIGH);
  
  pinMode(B, INPUT);
  digitalWrite(B,HIGH);


   digitalWrite(LED,LOW);
}


void loop()
{
  while(digitalRead(C)  == LOW)
  {
    tone(Buzz,T_C);
    digitalWrite(LED,HIGH);
  }


  while(digitalRead(D) == LOW)
  {
    tone(Buzz,T_D);
    digitalWrite(LED,HIGH);
  }


  while(digitalRead(E) == LOW)
  {
    tone(Buzz,T_E);
    digitalWrite(LED,HIGH);
  }


  while(digitalRead(F) == LOW)
  {
    tone(Buzz,T_F);
    digitalWrite(LED,HIGH);
  }


  while(digitalRead(G) == LOW)
  {
    tone(Buzz,T_G);
    digitalWrite(LED,HIGH);
  }


  while(digitalRead(A) == LOW)
  {
    tone(Buzz,T_A);
    digitalWrite(LED,HIGH);
  }


  while(digitalRead(B) == LOW)
  {
    tone(Buzz,T_B);
    digitalWrite(LED,HIGH);
  }


  noTone(Buzz);
  digitalWrite(LED,LOW);


}


Have Fun!

Engineering Final Project - Arveer

Have some fun playing your new Arduino Piano. Try to play some of your favourite songs!

The code also includes an LED which you can add to the digital 13 pin without needing anymore code as it is already included.